syntax = "proto3";

package envoy.extensions.access_loggers.grpc.v3;

import "envoy/config/core/v3/base.proto";
import "envoy/config/core/v3/config_source.proto";
import "envoy/config/core/v3/grpc_service.proto";
import "envoy/type/tracing/v3/custom_tag.proto";

import "google/protobuf/duration.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.extensions.access_loggers.grpc.v3";
option java_outer_classname = "AlsProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/access_loggers/grpc/v3;grpcv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: gRPC Access Log Service (ALS)]

// Configuration for the built-in ``envoy.access_loggers.http_grpc``
// :ref:`AccessLog <envoy_v3_api_msg_config.accesslog.v3.AccessLog>`. This configuration will
// populate :ref:`StreamAccessLogsMessage.http_logs
// <envoy_v3_api_field_service.accesslog.v3.StreamAccessLogsMessage.http_logs>`.
// [#extension: envoy.access_loggers.http_grpc]
message HttpGrpcAccessLogConfig {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.config.accesslog.v2.HttpGrpcAccessLogConfig";

  CommonGrpcAccessLogConfig common_config = 1 [(validate.rules).message = {required: true}];

  // Additional request headers to log in :ref:`HTTPRequestProperties.request_headers
  // <envoy_v3_api_field_data.accesslog.v3.HTTPRequestProperties.request_headers>`.
  repeated string additional_request_headers_to_log = 2;

  // Additional response headers to log in :ref:`HTTPResponseProperties.response_headers
  // <envoy_v3_api_field_data.accesslog.v3.HTTPResponseProperties.response_headers>`.
  repeated string additional_response_headers_to_log = 3;

  // Additional response trailers to log in :ref:`HTTPResponseProperties.response_trailers
  // <envoy_v3_api_field_data.accesslog.v3.HTTPResponseProperties.response_trailers>`.
  repeated string additional_response_trailers_to_log = 4;
}

// Configuration for the built-in ``envoy.access_loggers.tcp_grpc`` type. This configuration will
// populate ``StreamAccessLogsMessage.tcp_logs``.
// [#extension: envoy.access_loggers.tcp_grpc]
message TcpGrpcAccessLogConfig {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.config.accesslog.v2.TcpGrpcAccessLogConfig";

  CommonGrpcAccessLogConfig common_config = 1 [(validate.rules).message = {required: true}];
}

// Common configuration for gRPC access logs.
// [#next-free-field: 9]
message CommonGrpcAccessLogConfig {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.config.accesslog.v2.CommonGrpcAccessLogConfig";

  // The friendly name of the access log to be returned in :ref:`StreamAccessLogsMessage.Identifier
  // <envoy_v3_api_msg_service.accesslog.v3.StreamAccessLogsMessage.Identifier>`. This allows the
  // access log server to differentiate between different access logs coming from the same Envoy.
  string log_name = 1 [(validate.rules).string = {min_len: 1}];

  // The gRPC service for the access log service.
  config.core.v3.GrpcService grpc_service = 2 [(validate.rules).message = {required: true}];

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

  // Interval for flushing access logs to the gRPC stream. Logger will flush requests every time
  // this interval is elapsed, or when batch size limit is hit, whichever comes first. Defaults to
  // 1 second.
  google.protobuf.Duration buffer_flush_interval = 3 [(validate.rules).duration = {gt {}}];

  // Soft size limit in bytes for access log entries buffer. Logger will buffer requests until
  // this limit it hit, or every time flush interval is elapsed, whichever comes first. Setting it
  // to zero effectively disables the batching. Defaults to 16384.
  google.protobuf.UInt32Value buffer_size_bytes = 4;

  // Additional filter state objects to log in :ref:`filter_state_objects
  // <envoy_v3_api_field_data.accesslog.v3.AccessLogCommon.filter_state_objects>`.
  // Logger will call ``FilterState::Object::serializeAsProto`` to serialize the filter state object.
  repeated string filter_state_objects_to_log = 5;

  // Sets the retry policy when the establishment of a gRPC stream fails.
  // If the stream succeeds at least once in establishing itself,
  // no retry will be performed no matter what gRPC status is received.
  // Note that only :ref:`num_retries <envoy_v3_api_field_config.core.v3.RetryPolicy.num_retries>`
  // will be used in this configuration. This feature is used only when you are using
  // :ref:`Envoy gRPC client <envoy_v3_api_field_config.core.v3.GrpcService.envoy_grpc>`.
  config.core.v3.RetryPolicy grpc_stream_retry_policy = 7;

  // A list of custom tags with unique tag name to create tags for the logs.
  repeated type.tracing.v3.CustomTag custom_tags = 8;
}
