Skip to content

Commit

Permalink
Configure gRPC clients for ruler->ruler-query-frontend communications
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Nikolic <[email protected]>
  • Loading branch information
duricanikolic committed Mar 8, 2025
1 parent 5eb94ef commit 1923344
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/mimir/mimir.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func (c *Config) CommonConfigInheritance() CommonConfigInheritance {
"querier_store_gateway_client": &c.Querier.StoreGatewayClient.ClusterValidation,
"scheduler_query_frontend_client": &c.QueryScheduler.GRPCClientConfig.ClusterValidation,
"ruler_client": &c.Ruler.ClientTLSConfig.ClusterValidation,
"ruler_query_frontend_client": &c.Ruler.QueryFrontend.GRPCClientConfig.ClusterValidation,
},
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/mimir/mimir_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestCommonConfigCanBeExtended(t *testing.T) {
require.Equal(t, "client-cluster", cfg.MimirConfig.Querier.StoreGatewayClient.ClusterValidation.Label)
require.Equal(t, "client-cluster", cfg.MimirConfig.QueryScheduler.GRPCClientConfig.ClusterValidation.Label)
require.Equal(t, "client-cluster", cfg.MimirConfig.Ruler.ClientTLSConfig.ClusterValidation.Label)
require.Equal(t, "client-cluster", cfg.MimirConfig.Ruler.QueryFrontend.GRPCClientConfig.ClusterValidation.Label)
})

t.Run("yaml inheritance", func(t *testing.T) {
Expand Down Expand Up @@ -75,6 +76,7 @@ common:
require.Equal(t, "client-cluster", cfg.MimirConfig.Querier.StoreGatewayClient.ClusterValidation.Label)
require.Equal(t, "client-cluster", cfg.MimirConfig.QueryScheduler.GRPCClientConfig.ClusterValidation.Label)
require.Equal(t, "client-cluster", cfg.MimirConfig.Ruler.ClientTLSConfig.ClusterValidation.Label)
require.Equal(t, "client-cluster", cfg.MimirConfig.Ruler.QueryFrontend.GRPCClientConfig.ClusterValidation.Label)
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/mimir/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ func (t *Mimir) initRuler() (serv services.Service, err error) {
var queryFunc rules.QueryFunc

if t.Cfg.Ruler.QueryFrontend.Address != "" {
queryFrontendClient, err := ruler.DialQueryFrontend(t.Cfg.Ruler.QueryFrontend)
queryFrontendClient, err := ruler.DialQueryFrontend(t.Cfg.Ruler.QueryFrontend, t.Registerer, util_log.Logger)
if err != nil {
return nil, err
}
Expand Down
14 changes: 11 additions & 3 deletions pkg/ruler/remotequerier.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
otgrpc "github.com/opentracing-contrib/go-grpc"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/prometheus/prompb"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/storage"
Expand All @@ -36,6 +37,7 @@ import (
"google.golang.org/grpc/codes"

"github.com/grafana/mimir/pkg/querier/api"
"github.com/grafana/mimir/pkg/util"
"github.com/grafana/mimir/pkg/util/grpcencoding/s2"
"github.com/grafana/mimir/pkg/util/spanlogger"
"github.com/grafana/mimir/pkg/util/version"
Expand Down Expand Up @@ -95,11 +97,17 @@ func (c *QueryFrontendConfig) Validate() error {
}

// DialQueryFrontend creates and initializes a new httpgrpc.HTTPClient taking a QueryFrontendConfig configuration.
func DialQueryFrontend(cfg QueryFrontendConfig) (httpgrpc.HTTPClient, error) {
opts, err := cfg.GRPCClientConfig.DialOption([]grpc.UnaryClientInterceptor{
func DialQueryFrontend(cfg QueryFrontendConfig, reg prometheus.Registerer, logger log.Logger) (httpgrpc.HTTPClient, error) {
invalidClusterValidation := util.NewRequestInvalidClusterValidationLabelsTotalCounter(reg, "ruler-query-frontend", util.GRPCProtocol)

unary := []grpc.UnaryClientInterceptor{
otgrpc.OpenTracingClientInterceptor(opentracing.GlobalTracer()),
middleware.ClientUserHeaderInterceptor,
}, nil)
}
if cfg.GRPCClientConfig.ClusterValidation.Label != "" {
unary = append(unary, middleware.ClusterUnaryClientInterceptor(cfg.GRPCClientConfig.ClusterValidation.Label, invalidClusterValidation, logger))
}
opts, err := cfg.GRPCClientConfig.DialOption(unary, nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 1923344

Please sign in to comment.