Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Query API discovery #5291

Merged
merged 1 commit into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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