syntax = "proto3";

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

import "envoy/config/core/v3/extension.proto";

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

option java_package = "io.envoyproxy.envoy.extensions.filters.http.stateful_session.v3";
option java_outer_classname = "StatefulSessionProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/stateful_session/v3;stateful_sessionv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: Stateful session filter]
// Stateful session :ref:`configuration overview <config_http_filters_stateful_session>`.
// [#extension: envoy.filters.http.stateful_session]

message StatefulSession {
  // Specifies the implementation of session state. This session state is used to store and retrieve the address of the
  // upstream host assigned to the session.
  //
  // [#extension-category: envoy.http.stateful_session]
  config.core.v3.TypedExtensionConfig session_state = 1;

  // Determines whether the HTTP request must be strictly routed to the requested destination. When set to ``true``,
  // if the requested destination is not found in the set of available endpoints, Envoy will return a status code
  // determined by ``status_on_strict_destination_not_found``. If the destination exists but is unhealthy, Envoy will
  // always return ``503`` regardless of ``status_on_strict_destination_not_found``. The default value is ``false``,
  // which allows Envoy to fall back to its load balancing mechanism and route the request according to the load
  // balancing algorithm.
  bool strict = 2;

  // Optional stat prefix. If specified, the filter will emit statistics in the
  // ``http.<stat_prefix>.stateful_session.<stat_prefix>.`` namespace. If not specified, no statistics will be emitted.
  //
  // .. note::
  //
  //   Per-route configuration overrides do not support statistics and will not emit stats even if this field is set
  //   in the per-route config.
  string stat_prefix = 3;

  // The HTTP status code to return when ``strict`` mode is enabled and the requested destination
  // is not found in the set of available endpoints. This does not apply when the destination exists
  // but is unhealthy. This field has no effect when ``strict`` is set to ``false`` and will be
  // ignored. Defaults to ``503`` (Service Unavailable) if not specified or set to ``0``.
  uint32 status_on_strict_destination_not_found = 4;
}

message StatefulSessionPerRoute {
  oneof override {
    option (validate.required) = true;

    // Disable the stateful session filter for this particular vhost or route. If disabled is
    // specified in multiple per-filter-configs, the most specific one will be used.
    bool disabled = 1 [(validate.rules).bool = {const: true}];

    // Per-route stateful session configuration that can be served by RDS or static route table.
    StatefulSession stateful_session = 2;
  }
}
