// Copyright 2020 The gRPC 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.

// Local copy of Envoy xDS proto file, used for testing only.

syntax = "proto3";

package envoy.extensions.filters.http.fault.v3;

import "src/proto/grpc/testing/xds/v3/fault_common.proto";
import "src/proto/grpc/testing/xds/v3/route.proto";
import "src/proto/grpc/testing/xds/v3/percent.proto";

import "google/protobuf/wrappers.proto";

// [#protodoc-title: Fault Injection]
// Fault Injection :ref:`configuration overview <config_http_filters_fault_injection>`.
// [#extension: envoy.filters.http.fault]

// [#next-free-field: 6]
message FaultAbort {
  // Fault aborts 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 HeaderAbort {
  }

  reserved 1;

  oneof error_type {
    // HTTP status code to use to abort the HTTP request.
    uint32 http_status = 2;

    // gRPC status code to use to abort the gRPC request.
    uint32 grpc_status = 5;

    // Fault aborts are controlled via an HTTP header (if applicable).
    HeaderAbort header_abort = 4;
  }

  // The percentage of requests/operations/connections that will be aborted with the error code
  // provided.
  type.v3.FractionalPercent percentage = 3;
}

// [#next-free-field: 15]
message HTTPFault {
  // If specified, the filter will inject delays based on the values in the
  // object.
  common.fault.v3.FaultDelay delay = 1;

  // If specified, the filter will abort requests based on the values in
  // the object. At least *abort* or *delay* must be specified.
  FaultAbort abort = 2;

  // Specifies a set of headers that the filter should match on. The fault
  // injection filter can be applied selectively to requests that match a set of
  // headers specified in the fault filter config. The chances of actual fault
  // injection further depend on the value of the :ref:`percentage
  // <envoy_api_field_extensions.filters.http.fault.v3.FaultAbort.percentage>` field.
  // The filter will check the request's headers against all the specified
  // headers in the filter config. A match will happen if all the headers in the
  // config are present in the request with the same values (or based on
  // presence if the *value* field is not in the config).
  repeated config.route.v3.HeaderMatcher headers = 4;

  // The maximum number of faults that can be active at a single time via the configured fault
  // filter. Note that because this setting can be overridden at the route level, it's possible
  // for the number of active faults to be greater than this value (if injected via a different
  // route). If not specified, defaults to unlimited. This setting can be overridden via
  // `runtime <config_http_filters_fault_injection_runtime>` and any faults that are not injected
  // due to overflow will be indicated via the `faults_overflow
  // <config_http_filters_fault_injection_stats>` stat.
  //
  // .. attention::
  //   Like other :ref:`circuit breakers <arch_overview_circuit_break>` in Envoy, this is a fuzzy
  //   limit. It's possible for the number of active faults to rise slightly above the configured
  //   amount due to the implementation details.
  google.protobuf.UInt32Value max_active_faults = 6;
}
