// SPDX-License-Identifier: AGPL-3.0-only
// Provenance-includes-location: https://github.com/cortexproject/cortex/blob/master/pkg/frontend/v2/frontendv2pb/frontend.proto
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: The Cortex Authors.

syntax = "proto3";

package frontendv2pb;

import "github.com/grafana/dskit/httpgrpc/httpgrpc.proto";
import "github.com/grafana/mimir/pkg/querier/querierpb/querier.proto";
import "github.com/grafana/mimir/pkg/querier/stats/stats.proto";
import "gogoproto/gogo.proto";

option go_package = "frontendv2pb";
option (gogoproto.marshaler_all) = true;
option (gogoproto.unmarshaler_all) = true;

// Frontend interface exposed to Queriers. Used by queriers to report back the result of the query.
service FrontendForQuerier {
  rpc QueryResult(QueryResultRequest) returns (QueryResultResponse) {}
  rpc QueryResultStream(stream QueryResultStreamRequest) returns (QueryResultResponse) {}
}

message QueryResultRequest {
  uint64 queryID = 1;
  httpgrpc.HTTPResponse httpResponse = 2;
  stats.Stats stats = 3 [(gogoproto.customtype) = "github.com/grafana/mimir/pkg/querier/stats.SafeStats"];

  // There is no userID field here, because Querier puts userID into the context when
  // calling QueryResult, and that is where Frontend expects to find it.
}

message QueryResultStreamRequest {
  uint64 queryID = 1;

  oneof data {
    // Used for streaming httpgrpc responses:
    QueryResultMetadata metadata = 2;
    QueryResultBody body = 3;

    // Used for streaming non-httpgrpc responses:
    querierpb.Error error = 4;
    querierpb.EvaluateQueryResponse evaluateQueryResponse = 5;
  }
}

message QueryResultMetadata {
  int32 code = 1;
  repeated httpgrpc.Header headers = 2;
  stats.Stats stats = 3 [(gogoproto.customtype) = "github.com/grafana/mimir/pkg/querier/stats.SafeStats"];
}

message QueryResultBody {
  bytes chunk = 1;
}

message QueryResultResponse {}
