-
Notifications
You must be signed in to change notification settings - Fork 823
Define store-gateway protobuf and client #2433
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
Merged
pracucci
merged 2 commits into
cortexproject:master
from
pracucci:define-store-gateway-protobuf
Apr 10, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package querier | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/health/grpc_health_v1" | ||
|
||
"github.com/cortexproject/cortex/pkg/ring/client" | ||
"github.com/cortexproject/cortex/pkg/storegateway/storegatewaypb" | ||
"github.com/cortexproject/cortex/pkg/util/grpcclient" | ||
) | ||
|
||
func NewStoreGatewayClientFactory(cfg grpcclient.Config, reg prometheus.Registerer) client.PoolFactory { | ||
requestDuration := promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{ | ||
Namespace: "cortex", | ||
Name: "storegateway_client_request_duration_seconds", | ||
Help: "Time spent executing requests on store-gateway.", | ||
Buckets: prometheus.ExponentialBuckets(0.008, 4, 7), | ||
ConstLabels: prometheus.Labels{"client": "querier"}, | ||
}, []string{"operation", "status_code"}) | ||
|
||
return func(addr string) (client.PoolClient, error) { | ||
return dialStoreGatewayClient(cfg, addr, requestDuration) | ||
} | ||
} | ||
|
||
func dialStoreGatewayClient(cfg grpcclient.Config, addr string, requestDuration *prometheus.HistogramVec) (*storeGatewayClient, error) { | ||
opts := []grpc.DialOption{grpc.WithInsecure()} | ||
opts = append(opts, cfg.DialOption(grpcclient.Instrument(requestDuration))...) | ||
conn, err := grpc.Dial(addr, opts...) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to dial store-gateway %s", addr) | ||
} | ||
|
||
return &storeGatewayClient{ | ||
StoreGatewayClient: storegatewaypb.NewStoreGatewayClient(conn), | ||
HealthClient: grpc_health_v1.NewHealthClient(conn), | ||
conn: conn, | ||
}, nil | ||
} | ||
|
||
type storeGatewayClient struct { | ||
storegatewaypb.StoreGatewayClient | ||
grpc_health_v1.HealthClient | ||
conn *grpc.ClientConn | ||
} | ||
|
||
func (c *storeGatewayClient) Close() error { | ||
return c.conn.Close() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package querier | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"testing" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
dto "github.com/prometheus/client_model/go" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/thanos-io/thanos/pkg/store/storepb" | ||
"github.com/weaveworks/common/user" | ||
"google.golang.org/grpc" | ||
|
||
"github.com/cortexproject/cortex/pkg/storegateway/storegatewaypb" | ||
"github.com/cortexproject/cortex/pkg/util/flagext" | ||
"github.com/cortexproject/cortex/pkg/util/grpcclient" | ||
) | ||
|
||
func TestNewStoreGatewayClientFactory(t *testing.T) { | ||
// Create a GRPC server used to query the mocked service. | ||
grpcServer := grpc.NewServer() | ||
defer grpcServer.GracefulStop() | ||
|
||
srv := &mockStoreGatewayServer{} | ||
storegatewaypb.RegisterStoreGatewayServer(grpcServer, srv) | ||
|
||
listener, err := net.Listen("tcp", "localhost:0") | ||
require.NoError(t, err) | ||
|
||
go func() { | ||
require.NoError(t, grpcServer.Serve(listener)) | ||
}() | ||
|
||
// Create a client factory and query back the mocked service | ||
// with different clients. | ||
cfg := grpcclient.Config{} | ||
flagext.DefaultValues(&cfg) | ||
|
||
reg := prometheus.NewPedanticRegistry() | ||
factory := NewStoreGatewayClientFactory(cfg, reg) | ||
|
||
for i := 0; i < 2; i++ { | ||
client, err := factory(listener.Addr().String()) | ||
require.NoError(t, err) | ||
defer client.Close() //nolint:errcheck | ||
|
||
ctx := user.InjectOrgID(context.Background(), "test") | ||
stream, err := client.(*storeGatewayClient).Series(ctx, &storepb.SeriesRequest{}) | ||
assert.NoError(t, err) | ||
|
||
// Read the entire response from the stream. | ||
for _, err = stream.Recv(); err == nil; { | ||
} | ||
} | ||
|
||
// Assert on the request duration metric, but since it's a duration histogram and | ||
// we can't predict the exact time it took, we need to workaround it. | ||
metrics, err := reg.Gather() | ||
require.NoError(t, err) | ||
|
||
assert.Len(t, metrics, 1) | ||
assert.Equal(t, "cortex_storegateway_client_request_duration_seconds", metrics[0].GetName()) | ||
assert.Equal(t, dto.MetricType_HISTOGRAM, metrics[0].GetType()) | ||
assert.Len(t, metrics[0].GetMetric(), 1) | ||
assert.Equal(t, uint64(2), metrics[0].GetMetric()[0].GetHistogram().GetSampleCount()) | ||
} | ||
|
||
type mockStoreGatewayServer struct{} | ||
|
||
func (m *mockStoreGatewayServer) Series(_ *storepb.SeriesRequest, srv storegatewaypb.StoreGateway_SeriesServer) error { | ||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
syntax = "proto3"; | ||
package gatewaypb; | ||
|
||
import "github.com/thanos-io/thanos/pkg/store/storepb/rpc.proto"; | ||
|
||
option go_package = "storegatewaypb"; | ||
|
||
service StoreGateway { | ||
// Series streams each Series 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 are sorted. | ||
rpc Series(thanos.SeriesRequest) returns (stream thanos.SeriesResponse); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look to be called anywhere? I assume it will be added in a consecutive PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly. I'm still in the process of submitting partial PRs in preparation of the final PR where I will submit the store-gateway and blocks sharding logic, otherwise the final one will be too huge to review.