github.com/thanos-io/thanos@v0.32.5/pkg/rules/rulespb/rpc.proto (about)

     1  // Copyright (c) The Thanos Authors.
     2  // Licensed under the Apache License 2.0.
     3  
     4  syntax = "proto3";
     5  package thanos;
     6  
     7  import "store/storepb/types.proto";
     8  import "store/labelpb/types.proto";
     9  import "gogoproto/gogo.proto";
    10  import "google/protobuf/timestamp.proto";
    11  
    12  option go_package = "rulespb";
    13  
    14  option (gogoproto.sizer_all) = true;
    15  option (gogoproto.marshaler_all) = true;
    16  option (gogoproto.unmarshaler_all) = true;
    17  option (gogoproto.goproto_getters_all) = false;
    18  
    19  // Do not generate XXX fields to reduce memory footprint and opening a door
    20  // for zero-copy casts to/from prometheus data types.
    21  option (gogoproto.goproto_unkeyed_all) = false;
    22  option (gogoproto.goproto_unrecognized_all) = false;
    23  option (gogoproto.goproto_sizecache_all) = false;
    24  
    25  /// Rules represents API that is responsible for gathering rules and their statuses.
    26  service Rules {
    27      /// Rules has info for all rules.
    28      /// Returned rules are expected to include external labels.
    29      rpc Rules(RulesRequest) returns (stream RulesResponse);
    30  }
    31  
    32  message RulesRequest {
    33      enum Type {
    34          ALL = 0;
    35          /// This will make sure strings.ToLower(.String()) will match 'alert' and 'record' values for
    36          /// Prometheus HTTP API.
    37          /// NOTE: The implementation has to return empty rule groups as well.
    38          ALERT  = 1;
    39          RECORD = 2;
    40      }
    41      Type type = 1;
    42      PartialResponseStrategy partial_response_strategy = 2;
    43      repeated string matcher_string = 3;
    44  }
    45  
    46  message RulesResponse {
    47      oneof result {
    48          /// group for rule groups. It is up to server implementation to decide how many of those to put here within single frame.
    49          RuleGroup group = 1;
    50  
    51          /// warning is considered an information piece in place of series for warning purposes.
    52          /// It is used to warn rule API users about suspicious cases or partial response (if enabled).
    53          string warning = 2;
    54      }
    55  }
    56  
    57  
    58  /// RuleGroups is set of rule groups.
    59  /// This and below APIs are meant to be used for unmarshaling and marshsaling rules from/to Prometheus API.
    60  /// That's why json tag has to be customized and matching https://github.com/prometheus/prometheus/blob/c530b4b456cc5f9ec249f771dff187eb7715dc9b/web/api/v1/api.go#L955
    61  /// NOTE: See rules_custom_test.go for compatibility tests.
    62  ///
    63  /// For rule parsing from YAML configuration other struct is used: https://github.com/prometheus/prometheus/blob/20b1f596f6fb16107ef0c244d240b0ad6da36829/pkg/rulefmt/rulefmt.go#L105
    64  message RuleGroups {
    65      repeated RuleGroup groups = 1 [(gogoproto.jsontag) = "groups" ];
    66  }
    67  
    68  /// RuleGroup has info for rules which are part of a group.
    69  message RuleGroup {
    70      string name                               = 1 [(gogoproto.jsontag) = "name" ];
    71      string file                               = 2 [(gogoproto.jsontag) = "file" ];
    72      repeated Rule rules                       = 3 [(gogoproto.jsontag) = "rules" ];
    73      double interval                           = 4 [(gogoproto.jsontag) = "interval" ];
    74      double evaluation_duration_seconds        = 5 [(gogoproto.jsontag) = "evaluationTime" ]; // TODO: Is it really second?
    75      google.protobuf.Timestamp last_evaluation = 6 [(gogoproto.jsontag) = "lastEvaluation", (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];
    76      int64 limit                               = 9 [(gogoproto.jsontag) = "limit" ];
    77  
    78      // Thanos specific.
    79      PartialResponseStrategy PartialResponseStrategy = 8 [(gogoproto.jsontag) = "partialResponseStrategy" ];
    80  }
    81  
    82  message Rule {
    83      oneof result {
    84          RecordingRule recording = 1;
    85          Alert alert= 2;
    86      }
    87  }
    88  
    89  /// AlertState represents state of the alert. Has to match 1:1 Prometheus AlertState:
    90  //
    91  // StateInactive is the state of an alert that is neither firing nor pending.
    92  //StateInactive AlertState = iota
    93  // StatePending is the state of an alert that has been active for less than
    94  // the configured threshold duration.
    95  //StatePending
    96  // StateFiring is the state of an alert that has been active for longer than
    97  // the configured threshold duration.
    98  //StateFiring
    99  enum AlertState {
   100      INACTIVE            = 0;
   101      PENDING             = 1;
   102      FIRING              = 2;
   103  }
   104  
   105  message AlertInstance {
   106      ZLabelSet labels                     = 1 [(gogoproto.jsontag) = "labels", (gogoproto.nullable) = false ];
   107      ZLabelSet annotations                = 2 [(gogoproto.jsontag) = "annotations", (gogoproto.nullable) = false ];
   108      AlertState state                     = 3 [(gogoproto.jsontag) = "state" ];
   109      google.protobuf.Timestamp active_at  = 4 [(gogoproto.jsontag) = "activeAt,omitempty", (gogoproto.stdtime) = true];
   110      string value                         = 5 [(gogoproto.jsontag) = "value" ];
   111  
   112      // Thanos specific. Used mainly for alert API purposes.
   113      PartialResponseStrategy PartialResponseStrategy = 6 [(gogoproto.jsontag) = "partialResponseStrategy" ];
   114  }
   115  
   116  message Alert {
   117      /// state returns the maximum state of alert instances for this rule.
   118      AlertState state                          = 1 [(gogoproto.jsontag) = "state" ];
   119      string name                               = 2 [(gogoproto.jsontag) = "name" ];
   120      string query                              = 3 [(gogoproto.jsontag) = "query" ];
   121      double duration_seconds                   = 4 [(gogoproto.jsontag) = "duration" ];
   122      ZLabelSet labels                          = 5 [(gogoproto.jsontag) = "labels", (gogoproto.nullable) = false ];
   123      ZLabelSet annotations                     = 6 [(gogoproto.jsontag) = "annotations", (gogoproto.nullable) = false ];
   124      repeated AlertInstance alerts             = 7 [(gogoproto.jsontag) = "alerts" ];
   125      string health                             = 8 [(gogoproto.jsontag) = "health" ];
   126      string last_error                         = 9 [(gogoproto.jsontag) = "lastError,omitempty" ];
   127      double evaluation_duration_seconds        = 10 [(gogoproto.jsontag) = "evaluationTime" ];
   128      google.protobuf.Timestamp last_evaluation = 11 [(gogoproto.jsontag) = "lastEvaluation", (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];
   129  }
   130  
   131  message RecordingRule {
   132      string name                               = 1 [(gogoproto.jsontag) = "name" ];
   133      string query                              = 2 [(gogoproto.jsontag) = "query" ];
   134      ZLabelSet labels                          = 3 [(gogoproto.jsontag) = "labels", (gogoproto.nullable) = false ];
   135      string health                             = 4 [(gogoproto.jsontag) = "health" ];
   136      string last_error                         = 5 [(gogoproto.jsontag) = "lastError,omitempty" ];
   137      double evaluation_duration_seconds        = 6 [(gogoproto.jsontag) = "evaluationTime" ];
   138      google.protobuf.Timestamp last_evaluation = 7 [(gogoproto.jsontag) = "lastEvaluation", (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];
   139  }