// 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.data.core.v3;

import "envoy/config/core/v3/address.proto";
import "envoy/config/core/v3/base.proto";

import "google/protobuf/timestamp.proto";

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

option java_package = "io.envoyproxy.envoy.data.core.v3";
option java_outer_classname = "HealthCheckEventProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/data/core/v3;corev3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: Health check logging events]
// :ref:`Health check logging <arch_overview_health_check_logging>`.

enum HealthCheckFailureType {
  ACTIVE = 0;
  PASSIVE = 1;
  NETWORK = 2;
  NETWORK_TIMEOUT = 3;
}

enum HealthCheckerType {
  HTTP = 0;
  TCP = 1;
  GRPC = 2;
  REDIS = 3;
  THRIFT = 4;
}

// [#next-free-field: 13]
message HealthCheckEvent {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.data.core.v2alpha.HealthCheckEvent";

  HealthCheckerType health_checker_type = 1 [(validate.rules).enum = {defined_only: true}];

  config.core.v3.Address host = 2;

  string cluster_name = 3 [(validate.rules).string = {min_len: 1}];

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

    // Host ejection.
    HealthCheckEjectUnhealthy eject_unhealthy_event = 4;

    // Host addition.
    HealthCheckAddHealthy add_healthy_event = 5;

    // A health check was successful. Note: a host will be considered healthy either if it is
    // the first ever health check, or if the healthy threshold is reached. This kind of event
    // indicate that a health check was successful, but does not indicates that the host is
    // considered healthy. A host is considered healthy if HealthCheckAddHealthy kind of event is sent.
    HealthCheckSuccessful successful_health_check_event = 12;

    // Host failure.
    HealthCheckFailure health_check_failure_event = 7;

    // Healthy host became degraded.
    DegradedHealthyHost degraded_healthy_host = 8;

    // A degraded host returned to being healthy.
    NoLongerDegradedHost no_longer_degraded_host = 9;
  }

  // Timestamp for event.
  google.protobuf.Timestamp timestamp = 6;

  // Host metadata
  config.core.v3.Metadata metadata = 10;

  // Host locality
  config.core.v3.Locality locality = 11;
}

message HealthCheckEjectUnhealthy {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.data.core.v2alpha.HealthCheckEjectUnhealthy";

  // The type of failure that caused this ejection.
  HealthCheckFailureType failure_type = 1 [(validate.rules).enum = {defined_only: true}];
}

message HealthCheckAddHealthy {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.data.core.v2alpha.HealthCheckAddHealthy";

  // Whether this addition is the result of the first ever health check on a host, in which case
  // the configured :ref:`healthy threshold <envoy_v3_api_field_config.core.v3.HealthCheck.healthy_threshold>`
  // is bypassed and the host is immediately added.
  bool first_check = 1;
}

message HealthCheckSuccessful {
}

message HealthCheckFailure {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.data.core.v2alpha.HealthCheckFailure";

  // The type of failure that caused this event.
  HealthCheckFailureType failure_type = 1 [(validate.rules).enum = {defined_only: true}];

  // Whether this event is the result of the first ever health check on a host.
  bool first_check = 2;
}

message DegradedHealthyHost {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.data.core.v2alpha.DegradedHealthyHost";
}

message NoLongerDegradedHost {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.data.core.v2alpha.NoLongerDegradedHost";
}
