// Copyright 2025 Envoy Project Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package envoy.extensions.filters.network.zookeeper_proxy.v3;

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.filters.network.zookeeper_proxy.v3";
option java_outer_classname = "ZookeeperProxyProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/zookeeper_proxy/v3;zookeeper_proxyv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: ZooKeeper proxy]
// ZooKeeper Proxy :ref:`configuration overview <config_network_filters_zookeeper_proxy>`.
// [#extension: envoy.filters.network.zookeeper_proxy]

// [#next-free-field: 10]
message ZooKeeperProxy {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.config.filter.network.zookeeper_proxy.v1alpha1.ZooKeeperProxy";

  // The human readable prefix to use when emitting :ref:`statistics
  // <config_network_filters_zookeeper_proxy_stats>`.
  string stat_prefix = 1 [(validate.rules).string = {min_len: 1}];

  // [#not-implemented-hide:] The optional path to use for writing ZooKeeper access logs.
  // If the access log field is empty, access logs will not be written.
  string access_log = 2;

  // Messages — requests, responses and events — that are bigger than this value will
  // be ignored. If it is not set, the default value is 1Mb.
  //
  // The value here should match the jute.maxbuffer property in your cluster configuration:
  //
  // https://zookeeper.apache.org/doc/r3.4.10/zookeeperAdmin.html#Unsafe+Options
  //
  // if that is set. If it isn't, ZooKeeper's default is also 1Mb.
  google.protobuf.UInt32Value max_packet_bytes = 3;

  // Whether to emit latency threshold metrics. If not set, it defaults to false.
  // If false, setting ``default_latency_threshold`` and ``latency_threshold_overrides`` will not have effect.
  bool enable_latency_threshold_metrics = 4;

  // The default latency threshold to decide the fast/slow responses and emit metrics (used for error budget calculation).
  //
  // https://sre.google/workbook/implementing-slos/
  //
  // If it is not set, the default value is 100 milliseconds.
  google.protobuf.Duration default_latency_threshold = 5
      [(validate.rules).duration = {gte {nanos: 1000000}}];

  // List of latency threshold overrides for opcodes.
  // If the threshold override of one opcode is not set, it will fallback to the default latency
  // threshold.
  // Specifying latency threshold overrides multiple times for one opcode is not allowed.
  repeated LatencyThresholdOverride latency_threshold_overrides = 6;

  // Whether to emit per opcode request bytes metrics. If not set, it defaults to false.
  bool enable_per_opcode_request_bytes_metrics = 7;

  // Whether to emit per opcode response bytes metrics. If not set, it defaults to false.
  bool enable_per_opcode_response_bytes_metrics = 8;

  // Whether to emit per opcode decoder error metrics. If not set, it defaults to false.
  bool enable_per_opcode_decoder_error_metrics = 9;
}

message LatencyThresholdOverride {
  enum Opcode {
    Connect = 0;
    Create = 1;
    Delete = 2;
    Exists = 3;
    GetData = 4;
    SetData = 5;
    GetAcl = 6;
    SetAcl = 7;
    GetChildren = 8;
    Sync = 9;
    Ping = 10;
    GetChildren2 = 11;
    Check = 12;
    Multi = 13;
    Create2 = 14;
    Reconfig = 15;
    CheckWatches = 16;
    RemoveWatches = 17;
    CreateContainer = 18;
    CreateTtl = 19;
    Close = 20;
    SetAuth = 21;
    SetWatches = 22;
    GetEphemerals = 23;
    GetAllChildrenNumber = 24;
    SetWatches2 = 25;
    AddWatch = 26;
  }

  // The ZooKeeper opcodes. Can be found as part of the ZooKeeper source code:
  //
  // https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/main/java/org/apache/zookeeper/ZooDefs.java
  //
  Opcode opcode = 1 [(validate.rules).enum = {defined_only: true}];

  // The latency threshold override of certain opcode.
  google.protobuf.Duration threshold = 2 [(validate.rules).duration = {
    required: true
    gte {nanos: 1000000}
  }];
}
