// 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.common.fault.v3;

import "envoy/type/v3/percent.proto";

import "google/protobuf/duration.proto";

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

option java_package = "io.envoyproxy.envoy.extensions.filters.common.fault.v3";
option java_outer_classname = "FaultProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/common/fault/v3;faultv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: Common fault injection types]

// Delay specification is used to inject latency into the
// HTTP/Mongo operation.
// [#next-free-field: 6]
message FaultDelay {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.config.filter.fault.v2.FaultDelay";

  enum FaultDelayType {
    // Unused and deprecated.
    FIXED = 0;
  }

  // Fault delays are controlled via an HTTP header (if applicable). See the
  // :ref:`HTTP fault filter <config_http_filters_fault_injection_http_header>` documentation for
  // more information.
  message HeaderDelay {
    option (udpa.annotations.versioning).previous_message_type =
        "envoy.config.filter.fault.v2.FaultDelay.HeaderDelay";
  }

  reserved 2, 1;

  reserved "type";

  oneof fault_delay_secifier {
    option (validate.required) = true;

    // Add a fixed delay before forwarding the operation upstream. See
    // https://developers.google.com/protocol-buffers/docs/proto3#json for
    // the JSON/YAML Duration mapping. For HTTP/Mongo, the specified
    // delay will be injected before a new request/operation.
    // This is required if type is FIXED.
    google.protobuf.Duration fixed_delay = 3 [(validate.rules).duration = {gt {}}];

    // Fault delays are controlled via an HTTP header (if applicable).
    HeaderDelay header_delay = 5;
  }

  // The percentage of operations/connections/requests on which the delay will be injected.
  type.v3.FractionalPercent percentage = 4;
}

// Describes a rate limit to be applied.
message FaultRateLimit {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.config.filter.fault.v2.FaultRateLimit";

  // Describes a fixed/constant rate limit.
  message FixedLimit {
    option (udpa.annotations.versioning).previous_message_type =
        "envoy.config.filter.fault.v2.FaultRateLimit.FixedLimit";

    // The limit supplied in KiB/s.
    uint64 limit_kbps = 1 [(validate.rules).uint64 = {gte: 1}];
  }

  // Rate limits are controlled via an HTTP header (if applicable). See the
  // :ref:`HTTP fault filter <config_http_filters_fault_injection_http_header>` documentation for
  // more information.
  message HeaderLimit {
    option (udpa.annotations.versioning).previous_message_type =
        "envoy.config.filter.fault.v2.FaultRateLimit.HeaderLimit";
  }

  oneof limit_type {
    option (validate.required) = true;

    // A fixed rate limit.
    FixedLimit fixed_limit = 1;

    // Rate limits are controlled via an HTTP header (if applicable).
    HeaderLimit header_limit = 3;
  }

  // The percentage of operations/connections/requests on which the rate limit will be injected.
  type.v3.FractionalPercent percentage = 2;
}
