Elasticsearch: Put new log details filters behavior behind a feature flag (#70703)

* Elasticsearch: create elasticFiltersToggle feature flag

* Elasticsearch: add new filter behavior behind a feature flag

* Rename feature flag
This commit is contained in:
Matias Chomicki 2023-06-27 10:38:20 +02:00 committed by GitHub
parent a9b9b96c61
commit c1ce24c90f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 64 additions and 18 deletions

View File

@ -117,6 +117,7 @@ Experimental features might be changed or removed without prior notice.
| `pluginsDynamicAngularDetectionPatterns` | Enables fetching Angular detection patterns for plugins from GCOM and fallback to hardcoded ones |
| `alertingLokiRangeToInstant` | Rewrites eligible loki range queries to instant queries |
| `flameGraphV2` | New version of flame graph with new features |
| `elasticToggleableFilters` | Enable support to toggle filters off from the query through the Logs Details component |
## Development feature toggles

View File

@ -104,4 +104,5 @@ export interface FeatureToggles {
pluginsDynamicAngularDetectionPatterns?: boolean;
alertingLokiRangeToInstant?: boolean;
flameGraphV2?: boolean;
elasticToggleableFilters?: boolean;
}

View File

@ -586,5 +586,12 @@ var (
Stage: FeatureStageExperimental,
Owner: grafanaObservabilityTracesAndProfilingSquad,
},
{
Name: "elasticToggleableFilters",
Description: "Enable support to toggle filters off from the query through the Logs Details component",
Stage: FeatureStageExperimental,
FrontendOnly: true,
Owner: grafanaObservabilityLogsSquad,
},
}
)

View File

@ -85,3 +85,4 @@ recordedQueriesMulti,experimental,@grafana/observability-metrics,false,false,fal
pluginsDynamicAngularDetectionPatterns,experimental,@grafana/plugins-platform-backend,false,false,false,false
alertingLokiRangeToInstant,experimental,@grafana/alerting-squad,false,false,false,false
flameGraphV2,experimental,@grafana/observability-traces-and-profiling,false,false,false,true
elasticToggleableFilters,experimental,@grafana/observability-logs,false,false,false,true

1 Name Stage Owner requiresDevMode RequiresLicense RequiresRestart FrontendOnly
85 pluginsDynamicAngularDetectionPatterns experimental @grafana/plugins-platform-backend false false false false
86 alertingLokiRangeToInstant experimental @grafana/alerting-squad false false false false
87 flameGraphV2 experimental @grafana/observability-traces-and-profiling false false false true
88 elasticToggleableFilters experimental @grafana/observability-logs false false false true

View File

@ -350,4 +350,8 @@ const (
// FlagFlameGraphV2
// New version of flame graph with new features
FlagFlameGraphV2 = "flameGraphV2"
// FlagElasticToggleableFilters
// Enable support to toggle filters off from the query through the Logs Details component
FlagElasticToggleableFilters = "elasticToggleableFilters"
)

View File

@ -1185,6 +1185,7 @@ describe('modifyQuery', () => {
let ds: ElasticDatasource;
beforeEach(() => {
ds = getTestContext().ds;
config.featureToggles.elasticToggleableFilters = true;
});
describe('with empty query', () => {
let query: ElasticsearchQuery;
@ -1243,6 +1244,26 @@ describe('modifyQuery', () => {
expect(ds.modifyQuery(query, { type: 'unknown', options: { key: 'foo', value: 'bar' } }).query).toBe(query.query);
});
});
describe('legacy behavior', () => {
beforeEach(() => {
config.featureToggles.elasticToggleableFilters = false;
});
it('should not modify other filters in the query', () => {
expect(
ds.modifyQuery(
{ query: 'test:"value"', refId: 'A' },
{ type: 'ADD_FILTER', options: { key: 'test', value: 'value' } }
).query
).toBe('test:"value"');
expect(
ds.modifyQuery(
{ query: 'test:"value"', refId: 'A' },
{ type: 'ADD_FILTER_OUT', options: { key: 'test', value: 'value' } }
).query
).toBe('test:"value" AND -test:"value"');
});
});
});
describe('addAdhocFilters', () => {

View File

@ -897,27 +897,38 @@ export class ElasticDatasource
}
let expression = query.query ?? '';
switch (action.type) {
case 'ADD_FILTER': {
// This gives the user the ability to toggle a filter on and off.
expression = queryHasFilter(expression, action.options.key, action.options.value)
? removeFilterFromQuery(expression, action.options.key, action.options.value)
: addFilterToQuery(expression, action.options.key, action.options.value);
break;
}
case 'ADD_FILTER_OUT': {
/**
* If there is a filter with the same key and value, remove it.
* This prevents the user from seeing no changes in the query when they apply
* this filter.
*/
if (queryHasFilter(expression, action.options.key, action.options.value)) {
expression = removeFilterFromQuery(expression, action.options.key, action.options.value);
if (config.featureToggles.elasticToggleableFilters) {
switch (action.type) {
case 'ADD_FILTER': {
// This gives the user the ability to toggle a filter on and off.
expression = queryHasFilter(expression, action.options.key, action.options.value)
? removeFilterFromQuery(expression, action.options.key, action.options.value)
: addFilterToQuery(expression, action.options.key, action.options.value);
break;
}
case 'ADD_FILTER_OUT': {
// If the opposite filter is present, remove it before adding the new one.
if (queryHasFilter(expression, action.options.key, action.options.value)) {
expression = removeFilterFromQuery(expression, action.options.key, action.options.value);
}
expression = addFilterToQuery(expression, action.options.key, action.options.value, '-');
break;
}
}
} else {
// Legacy behavior
switch (action.type) {
case 'ADD_FILTER': {
expression = addFilterToQuery(expression, action.options.key, action.options.value);
break;
}
case 'ADD_FILTER_OUT': {
expression = addFilterToQuery(expression, action.options.key, action.options.value, '-');
break;
}
expression = addFilterToQuery(expression, action.options.key, action.options.value, '-');
break;
}
}
return { ...query, query: expression };
}