mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
a9b9b96c61
commit
c1ce24c90f
@ -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
|
||||
|
||||
|
@ -104,4 +104,5 @@ export interface FeatureToggles {
|
||||
pluginsDynamicAngularDetectionPatterns?: boolean;
|
||||
alertingLokiRangeToInstant?: boolean;
|
||||
flameGraphV2?: boolean;
|
||||
elasticToggleableFilters?: boolean;
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
@ -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
|
||||
|
|
@ -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"
|
||||
)
|
||||
|
@ -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', () => {
|
||||
|
@ -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 };
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user