From 9ceaeed48911e4ba379f372a8e45ebd84d014912 Mon Sep 17 00:00:00 2001 From: Matias Chomicki Date: Wed, 6 Sep 2023 15:32:48 +0200 Subject: [PATCH] toggleLabelsInLogsUI: enable by default (#74342) * GA toggleable labels * Logs integration: update readme with new features * Build a logs data source: update docs with the new interface * Plugin docs: update example function signatures and arguments * Plugin docs: update modifyQuery function names * Formatting * Remove character * Remove `expr` from docs * Plugin docs: improve code * Plugin docs: further code improvements --- .../build-a-logs-data-source-plugin.md | 81 ++++++++++++++++++- docs/sources/explore/logs-integration.md | 6 +- .../feature-toggles/index.md | 2 +- pkg/services/featuremgmt/registry.go | 3 +- pkg/services/featuremgmt/toggles_gen.csv | 2 +- 5 files changed, 85 insertions(+), 9 deletions(-) diff --git a/docs/sources/developers/plugins/create-a-grafana-plugin/develop-a-plugin/build-a-logs-data-source-plugin.md b/docs/sources/developers/plugins/create-a-grafana-plugin/develop-a-plugin/build-a-logs-data-source-plugin.md index 0007d782af8..13b420f4b75 100644 --- a/docs/sources/developers/plugins/create-a-grafana-plugin/develop-a-plugin/build-a-logs-data-source-plugin.md +++ b/docs/sources/developers/plugins/create-a-grafana-plugin/develop-a-plugin/build-a-logs-data-source-plugin.md @@ -273,14 +273,14 @@ export class ExampleDatasource extends DataSourceApi + implements DataSourceWithToggleableQueryFiltersSupport +{ + /** + * Given a query, determine if it has a filter that matches the options. + */ + queryHasFilter(query: ExampleQuery, filter: QueryFilterOptions): boolean { + /** + * Pass the query and the key => value pair to your query-analyzing function. + * We only care about equality/positive filters as only those fields will be + * present in the log lines. + */ + return queryHasPositiveFilter(query.query, filter.key, filter.value); + } + + /** + * Toggle filters on and off from query. + * If the filter is already present, it should be removed. + * If the opposite filter is present, it should be replaced. + */ + toggleQueryFilter(query: ExampleQuery, filter: ToggleFilterAction): LokiQuery { + const queryText = query.query; // The current query. + const { key, value } = filter.options; + // We currently support 2 types of filter: FILTER_FOR (positive) and FILTER_OUT (negative). + switch (filter.type) { + case 'FILTER_FOR': { + // This gives the user the ability to toggle a filter on and off. + queryText = queryHasPositiveFilter(queryText, key, value) + ? removePositiveFilterFromQuery(queryText, key, value) + : addPositiveFilterToQuery(queryText, key, value); + break; + } + case 'FILTER_OUT': { + // If there is a positive filter with the same key and value, remove it. + if (queryHasPositiveFilter(queryText, key, value)) { + queryText = removePositiveLabelFromQuery(queryText, key, value); + } + // Add the inequality filter to the query. + queryText = addNegativeFilterToQuery(queryText, key, value); + break; + } + default: + break; + } + return { ...query, query: queryText }; + } +} +``` diff --git a/docs/sources/explore/logs-integration.md b/docs/sources/explore/logs-integration.md index 3855df7bfc0..65ecfe53add 100644 --- a/docs/sources/explore/logs-integration.md +++ b/docs/sources/explore/logs-integration.md @@ -108,11 +108,13 @@ When your query includes specific words or expressions to search for, Explore wi ### Log details view -In Explore, each log line has an expandable section called **Log details** that can be opened by clicking on the log line. The Log details view provides additional information, including **Fields** and **Links** attached to the log lines, enabling more robust interaction and analysis. +In Explore, each log line has an expandable section called **Log details** that can be opened by clicking on the log line. The Log details view provides additional information and exploration options in the form of **Fields** and **Links** attached to the log lines, enabling a more robust interaction and analysis. #### Fields -Within the Log details view, you have the ability to filter displayed fields in two ways: positive filter (to show specific fields) and negative filter (to exclude certain fields). Additionally, you can select a unique field to visualize instead of the whole log line by clicking on the eye icon. Finally, each field has a stats icon to display ad-hoc statistics in relation to all displayed logs. +Within the Log details view, you have the ability to filter displayed fields in two ways: a positive filter (to focus on an specific field) and a negative filter (to exclude certain fields). These filters will update the corresponding query that produced the log line, adding equality and inequality expressions accordingly. If the data source has support, as it's the case for Loki and Elasticsearch, log details will check if the field is already present in the current query showing and active state (for positive filters only), allowing you to toggle it off the query, or changing the filter expression from positive to negative. + +Additionally, you can select a subset of fields to visualize in the logs list instead of the complete log line by clicking on the eye icon. Finally, each field has a stats icon to display ad-hoc statistics in relation to all displayed logs. #### Links diff --git a/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md b/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md index 7f4892e18a2..166bb548e53 100644 --- a/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md +++ b/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md @@ -44,6 +44,7 @@ Some features are enabled by default. You can disable these feature by setting t | `enableElasticsearchBackendQuerying` | Enable the processing of queries and responses in the Elasticsearch data source through backend | Yes | | `advancedDataSourcePicker` | Enable a new data source picker with contextual information, recently used order and advanced mode | Yes | | `transformationsRedesign` | Enables the transformations redesign | Yes | +| `toggleLabelsInLogsUI` | Enable toggleable filters in log details view | Yes | | `azureMonitorDataplane` | Adds dataplane compliant frame metadata in the Azure Monitor datasource | Yes | ## Preview feature toggles @@ -120,7 +121,6 @@ Experimental features might be changed or removed without prior notice. | `prometheusIncrementalQueryInstrumentation` | Adds RudderStack events to incremental queries | | `logsExploreTableVisualisation` | A table visualisation for logs in Explore | | `awsDatasourcesTempCredentials` | Support temporary security credentials in AWS plugins for Grafana Cloud customers | -| `toggleLabelsInLogsUI` | Enable toggleable filters in log details view | | `mlExpressions` | Enable support for Machine Learning in server-side expressions | | `traceQLStreaming` | Enables response streaming of TraceQL queries of the Tempo data source | | `metricsSummary` | Enables metrics summary queries in the Tempo data source | diff --git a/pkg/services/featuremgmt/registry.go b/pkg/services/featuremgmt/registry.go index 284e56eaab8..6ffe5309870 100644 --- a/pkg/services/featuremgmt/registry.go +++ b/pkg/services/featuremgmt/registry.go @@ -602,8 +602,9 @@ var ( { Name: "toggleLabelsInLogsUI", Description: "Enable toggleable filters in log details view", - Stage: FeatureStageExperimental, + Stage: FeatureStageGeneralAvailability, FrontendOnly: true, + Expression: "true", // enabled by default Owner: grafanaObservabilityLogsSquad, }, { diff --git a/pkg/services/featuremgmt/toggles_gen.csv b/pkg/services/featuremgmt/toggles_gen.csv index 9a45b1ef7ba..ea7ab74fdd4 100644 --- a/pkg/services/featuremgmt/toggles_gen.csv +++ b/pkg/services/featuremgmt/toggles_gen.csv @@ -86,7 +86,7 @@ prometheusIncrementalQueryInstrumentation,experimental,@grafana/observability-me logsExploreTableVisualisation,experimental,@grafana/observability-logs,false,false,false,true awsDatasourcesTempCredentials,experimental,@grafana/aws-datasources,false,false,false,false transformationsRedesign,GA,@grafana/observability-metrics,false,false,false,true -toggleLabelsInLogsUI,experimental,@grafana/observability-logs,false,false,false,true +toggleLabelsInLogsUI,GA,@grafana/observability-logs,false,false,false,true mlExpressions,experimental,@grafana/alerting-squad,false,false,false,false traceQLStreaming,experimental,@grafana/observability-traces-and-profiling,false,false,false,true metricsSummary,experimental,@grafana/observability-traces-and-profiling,false,false,false,true