// 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.http.on_demand.v3;

import "envoy/config/core/v3/config_source.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.http.on_demand.v3";
option java_outer_classname = "OnDemandProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/on_demand/v3;on_demandv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: On Demand Discovery]
// On Demand Discovery :ref:`configuration overview <config_http_filters_on_demand>`.
// [#extension: envoy.filters.http.on_demand]
//
// .. warning::
//
//    Envoy currently only supports On-demand CDS when using Incremental-xDS and not State-of-the-World.
//

// Configuration of on-demand CDS.
message OnDemandCds {
  // A configuration source for the service that will be used for
  // on-demand cluster discovery.
  config.core.v3.ConfigSource source = 1 [(validate.rules).message = {required: true}];

  // xdstp:// resource locator for on-demand cluster collection.
  string resources_locator = 2;

  // The timeout for on demand cluster lookup. If not set, defaults to 5 seconds.
  google.protobuf.Duration timeout = 3;
}

// On Demand Discovery filter config.
message OnDemand {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.config.filter.http.on_demand.v2.OnDemand";

  // An optional configuration for on-demand cluster discovery
  // service. If not specified, the on-demand cluster discovery will
  // be disabled. When it's specified, the filter will pause the
  // request to an unknown cluster and will begin a cluster discovery
  // process. When the discovery is finished (successfully or not), the
  // request will be resumed for further processing.
  OnDemandCds odcds = 1;
}

// Per-route configuration for On Demand Discovery.
message PerRouteConfig {
  // An optional configuration for on-demand cluster discovery
  // service. If not specified, the on-demand cluster discovery will
  // be disabled. When it's specified, the filter will pause the
  // request to an unknown cluster and will begin a cluster discovery
  // process. When the discovery is finished (successfully or not), the
  // request will be resumed for further processing.
  OnDemandCds odcds = 1;
}
