Skip to content

Commit

Permalink
Implement Query API discovery
Browse files Browse the repository at this point in the history
A recent commit (thanos-io#5250) added a GRPC API to Thanos Query which allows
executing PromQL over GRPC. This API is currently not discoverable
through endpointsets which makes it hard for other Thanos components
to use it.

This commit extends endpointsets with a GetQueryAPIClients method
which returns Query API clients to all components which support
this API.

Signed-off-by: fpetkovski <[email protected]>
  • Loading branch information
fpetkovski committed Apr 21, 2022
1 parent 4b3f555 commit 20c1e54
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 35 deletions.
1 change: 1 addition & 0 deletions cmd/thanos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ func runQuery(
info.WithRulesInfoFunc(),
info.WithMetricMetadataInfoFunc(),
info.WithTargetsInfoFunc(),
info.WithQueryAPIInfoFunc(),
)

grpcAPI := apiv1.NewGRPCAPI(time.Now, queryableCreator, engineCreator, instantDefaultMaxSourceResolution)
Expand Down
18 changes: 18 additions & 0 deletions pkg/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type InfoServer struct {
getRulesInfo func() *infopb.RulesInfo
getTargetsInfo func() *infopb.TargetsInfo
getMetricMetadataInfo func() *infopb.MetricMetadataInfo
getQueryAPIInfo func() *infopb.QueryAPIInfo
}

// NewInfoServer creates a new server instance for given component
Expand All @@ -42,6 +43,7 @@ func NewInfoServer(
getRulesInfo: func() *infopb.RulesInfo { return nil },
getTargetsInfo: func() *infopb.TargetsInfo { return nil },
getMetricMetadataInfo: func() *infopb.MetricMetadataInfo { return nil },
getQueryAPIInfo: func() *infopb.QueryAPIInfo { return nil },
}

for _, o := range options {
Expand Down Expand Up @@ -144,6 +146,21 @@ func WithMetricMetadataInfoFunc(getMetricMetadataInfo ...func() *infopb.MetricMe
}
}

// WithQueryAPIInfoFunc determines the function that should be executed to obtain
// the query information. If no function is provided, the default empty
// query info is returned. Only the first function from the list is considered.
func WithQueryAPIInfoFunc(queryInfo ...func() *infopb.QueryAPIInfo) ServerOptionFunc {
if len(queryInfo) == 0 {
return func(s *InfoServer) {
s.getQueryAPIInfo = func() *infopb.QueryAPIInfo { return &infopb.QueryAPIInfo{} }
}
}

return func(s *InfoServer) {
s.getQueryAPIInfo = queryInfo[0]
}
}

// RegisterInfoServer registers the info server.
func RegisterInfoServer(infoSrv infopb.InfoServer) func(*grpc.Server) {
return func(s *grpc.Server) {
Expand All @@ -161,5 +178,6 @@ func (srv *InfoServer) Info(ctx context.Context, req *infopb.InfoRequest) (*info
Rules: srv.getRulesInfo(),
Targets: srv.getTargetsInfo(),
MetricMetadata: srv.getMetricMetadataInfo(),
Query: srv.getQueryAPIInfo(),
}, nil
}
234 changes: 205 additions & 29 deletions pkg/info/infopb/rpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions pkg/info/infopb/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,24 @@ message InfoRequest {}
message InfoResponse {
repeated ZLabelSet label_sets = 1 [(gogoproto.nullable) = false];
string ComponentType = 2;

// StoreInfo holds the metadata related to Store API if exposed by the component otherwise it will be null.
StoreInfo store = 3;
StoreInfo store = 3;

// RulesInfo holds the metadata related to Rules API if exposed by the component otherwise it will be null.
RulesInfo rules = 4;

// MetricMetadataInfo holds the metadata related to Metadata API if exposed by the component otherwise it will be null.
MetricMetadataInfo metric_metadata = 5;

// TargetsInfo holds the metadata related to Targets API if exposed by the component otherwise it will be null.
TargetsInfo targets = 6;

// ExemplarsInfo holds the metadata related to Exemplars API if exposed by the component otherwise it will be null.
ExemplarsInfo exemplars = 7;

// QueryAPIInfo holds the metadata related to Query API if exposed by the component, otherwise it will be null.
QueryAPIInfo query = 8;
}

// StoreInfo holds the metadata related to Store API exposed by the component.
Expand All @@ -70,4 +73,8 @@ message TargetsInfo {
message ExemplarsInfo {
int64 min_time = 1;
int64 max_time = 2;
}
}

// QueryInfo holds the metadata related to Query API exposed by the component.
message QueryAPIInfo {
}
Loading

0 comments on commit 20c1e54

Please sign in to comment.