Query metrics

Key query metrics, such as aggregation types, query types, latency, and resource usage per query type, are captured along the search path by using the OpenTelemetry (OTel) instrumentation framework. The telemetry data can be consumed using OTel metrics exporters.

Configuring query metric generation

To configure query metric generation, use the following steps.

Step 1: Install the Query Insights plugin

For information about installing the Query Insights plugin, see Installing the Query Insights plugin.

Step 2: Install the OpenTelemetry plugin

For information about installing the OpenTelemetry plugin, see Distributed tracing.

Step 3: Enable query metrics

Enable query metrics by configuring the following opensearch.yml settings:

  1. telemetry.feature.metrics.enabled: true
  2. search.query.metrics.enabled: true

copy

The following is a complete sample configuration that includes a telemetry configuration:

  1. # Enable query metrics feature
  2. search.query.metrics.enabled: true
  3. telemetry.feature.metrics.enabled: true
  4. # OTel-related configuration
  5. opensearch.experimental.feature.telemetry.enabled: true
  6. telemetry.tracer.sampler.probability: 1.0
  7. telemetry.feature.tracer.enabled: true

copy

Alternatively, you can configure query metric generation using the API:

  1. PUT _cluster/settings
  2. {
  3. "persistent" : {
  4. "search.query.metrics.enabled" : true
  5. }
  6. }

copy

Configure the export of metrics and traces using a gRPC exporter. For more information, see Exporters. You can skip this step if you use the default logging exporter:

  1. telemetry.otel.tracer.span.exporter.class: io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter
  2. telemetry.otel.metrics.exporter.class: io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter

copy

Metrics

Query metrics provide the following measurements:

  • The number of queries per query type (for example, the number of match or regex queries)
  • The number of queries per aggregation type (for example, the number of terms aggregation queries)
  • The number of queries per sort order (for example, the number of ascending and descending sort queries)
  • Histograms of latency for each query type, aggregation type, and sort order
  • Histograms of cpu for each query type, aggregation type, and sort order
  • Histograms of memory for each query type, aggregation type, and sort order

Default logging exporter

By default, if no gRPC exporters are configured, then the metrics and traces are exported to log files. The data is saved in the opensearch/logs directory in the following files:

  • opensearch_otel_metrics.log
  • opensearch_otel_traces.log