syntax = "proto3";
package thanos;

import "types.proto";
import "gogoproto/gogo.proto";

option go_package = "storepb";

option (gogoproto.sizer_all) = true;
option (gogoproto.marshaler_all) = true;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.goproto_getters_all) = false;

/// Store reprents API against instance that stores XOR encoded values with label set metadata (e.g Prometheus metrics).
service Store {
  /// Info returns meta information about a store e.g labels that makes that store unique as well as time range that is
  /// available.
  rpc Info(InfoRequest) returns (InfoResponse);

  /// Series streams each Series (Labels and chunk/downsampling chunk) for given label matchers and time range.
  ///
  /// Series should strictly stream full series after series, optionally split by time. This means that a single frame can contain
  /// partition of the single series, but once a new series is started to be streamed it means that no more data will
  /// be sent for previous one.
  /// Series has to be sorted.
  rpc Series(SeriesRequest) returns (stream SeriesResponse);

  /// LabelNames returns all label names that is available.
  /// Currently unimplemented in all Thanos implementations, because Query API does not implement this either.
  rpc LabelNames(LabelNamesRequest) returns (LabelNamesResponse);

  /// LabelValues returns all label values for given label name.
  rpc LabelValues(LabelValuesRequest) returns (LabelValuesResponse);
}

message InfoRequest {
}

enum StoreType {
  UNKNOWN = 0;
  QUERY = 1;
  RULE = 2;
  SIDECAR = 3;
  STORE = 4;
  RECEIVE = 5;
}

message InfoResponse {
  // Deprecated. Use label_sets instead.
  repeated Label labels = 1 [(gogoproto.nullable) = false];
  int64 min_time = 2;
  int64 max_time = 3;
  StoreType storeType  = 4;
  // label_sets is an unsorted list of `LabelSet`s.
  repeated LabelSet label_sets = 5 [(gogoproto.nullable) = false];
}

message LabelSet {
  repeated Label labels = 1 [(gogoproto.nullable) = false];
}

/// PartialResponseStrategy controls partial response handling.
enum PartialResponseStrategy {
  /// WARN strategy tells server to treat any error that will related to single StoreAPI (e.g missing chunk series because of underlying
  /// storeAPI is temporarily not available) as warning which will not fail the whole query (still OK response).
  /// Server should produce those as a warnings field in response.
  WARN = 0;
  /// ABORT strategy tells server to treat any error that will related to single StoreAPI (e.g missing chunk series because of underlying
  /// storeAPI is temporarily not available) as the gRPC error that aborts the query.
  ///
  /// This is especially useful for any rule/alert evaluations on top of StoreAPI which usually does not tolerate partial
  /// errors.
  ABORT = 1;
}

message SeriesRequest {
  int64 min_time                 = 1;
  int64 max_time                 = 2;
  repeated LabelMatcher matchers = 3 [(gogoproto.nullable) = false];

  int64 max_resolution_window = 4;
  repeated Aggr aggregates    = 5;

  // Deprecated. Use partial_response_strategy instead.
  bool partial_response_disabled = 6;

  // TODO(bwplotka): Move Thanos components to use strategy instead. Including QueryAPI.
  PartialResponseStrategy partial_response_strategy = 7;
}

enum Aggr {
  RAW     = 0;
  COUNT   = 1;
  SUM     = 2;
  MIN     = 3;
  MAX     = 4;
  COUNTER = 5;
}

message SeriesResponse {
  oneof result {
      Series series = 1;

      /// warning is considered an information piece in place of series for warning purposes.
      /// It is used to warn query customer about suspicious cases or partial response (if enabled).
      string warning = 2;
  }
}

message LabelNamesRequest {
  bool partial_response_disabled = 1;

  // TODO(bwplotka): Move Thanos components to use strategy instead. Including QueryAPI.
  PartialResponseStrategy partial_response_strategy = 2;
}

message LabelNamesResponse {
  repeated string names = 1;
  repeated string warnings = 2;
}

message LabelValuesRequest {
  string label = 1;

  bool partial_response_disabled = 2;

  // TODO(bwplotka): Move Thanos components to use strategy instead. Including QueryAPI.
  PartialResponseStrategy partial_response_strategy = 3;
}

message LabelValuesResponse {
  repeated string values = 1;
  repeated string warnings = 2;
}
