syntax = "proto3";

package envoy.config.metrics.v3;

import "envoy/config/core/v3/config_source.proto";
import "envoy/config/core/v3/grpc_service.proto";

import "google/protobuf/wrappers.proto";

import "udpa/annotations/status.proto";
import "udpa/annotations/versioning.proto";
import "validate/validate.proto";

option java_package = "io.envoyproxy.envoy.config.metrics.v3";
option java_outer_classname = "MetricsServiceProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/config/metrics/v3;metricsv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: Metrics service]

// HistogramEmitMode is used to configure which metric types should be emitted for histograms.
enum HistogramEmitMode {
  // Emit Histogram and Summary metric types.
  SUMMARY_AND_HISTOGRAM = 0;

  // Emit only Summary metric types.
  SUMMARY = 1;

  // Emit only Histogram metric types.
  HISTOGRAM = 2;
}

// Metrics Service is configured as a built-in ``envoy.stat_sinks.metrics_service`` :ref:`StatsSink
// <envoy_v3_api_msg_config.metrics.v3.StatsSink>`. This opaque configuration will be used to create
// Metrics Service.
//
// Example:
//
// .. code-block:: yaml
//
//     stats_sinks:
//       - name: envoy.stat_sinks.metrics_service
//         typed_config:
//           "@type": type.googleapis.com/envoy.config.metrics.v3.MetricsServiceConfig
//
// [#extension: envoy.stat_sinks.metrics_service]
// [#next-free-field: 7]
message MetricsServiceConfig {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.config.metrics.v2.MetricsServiceConfig";

  // The upstream gRPC cluster that hosts the metrics service.
  core.v3.GrpcService grpc_service = 1 [(validate.rules).message = {required: true}];

  // API version for metric service transport protocol. This describes the metric service gRPC
  // endpoint and version of messages used on the wire.
  core.v3.ApiVersion transport_api_version = 3 [(validate.rules).enum = {defined_only: true}];

  // If true, counters are reported as the delta between flushing intervals. Otherwise, the current
  // counter value is reported. Defaults to false.
  // Eventually (https://github.com/envoyproxy/envoy/issues/10968) if this value is not set, the
  // sink will take updates from the :ref:`MetricsResponse <envoy_v3_api_msg_service.metrics.v3.StreamMetricsResponse>`.
  google.protobuf.BoolValue report_counters_as_deltas = 2;

  // If true, metrics will have their tags emitted as labels on the metrics objects sent to the MetricsService,
  // and the tag extracted name will be used instead of the full name, which may contain values used by the tag
  // extractor or additional tags added during stats creation.
  bool emit_tags_as_labels = 4;

  // Specify which metrics types to emit for histograms. Defaults to SUMMARY_AND_HISTOGRAM.
  HistogramEmitMode histogram_emit_mode = 5 [(validate.rules).enum = {defined_only: true}];

  // The maximum number of metrics to send in a single gRPC message. If not set or set to 0,
  // all metrics will be sent in a single message (current behavior). When set to a positive value,
  // metrics will be batched into multiple messages, with each message containing at most batch_size
  // metric families. This helps avoid hitting gRPC message size limits (typically 4MB) when sending
  // large numbers of metrics.
  uint32 batch_size = 6 [(validate.rules).uint32 = {gte: 0}];
}
