-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Bootstrap metastore for wal segments (#13550)
- Loading branch information
1 parent
960c034
commit 0b47498
Showing
197 changed files
with
91,730 additions
and
3,507 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,82 @@ | ||
package metastoreclient | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
|
||
"github.com/grafana/dskit/grpcclient" | ||
"github.com/grafana/dskit/services" | ||
"google.golang.org/grpc" | ||
|
||
metastorepb "github.com/grafana/loki/v3/pkg/ingester-rf1/metastore/metastorepb" | ||
) | ||
|
||
type Config struct { | ||
MetastoreAddress string `yaml:"address"` | ||
GRPCClientConfig grpcclient.Config `yaml:"grpc_client_config" doc:"description=Configures the gRPC client used to communicate with the metastore."` | ||
} | ||
|
||
func (cfg *Config) RegisterFlags(f *flag.FlagSet) { | ||
f.StringVar(&cfg.MetastoreAddress, "metastore.address", "localhost:9095", "") | ||
cfg.GRPCClientConfig.RegisterFlagsWithPrefix("metastore.grpc-client-config", f) | ||
} | ||
|
||
func (cfg *Config) Validate() error { | ||
if cfg.MetastoreAddress == "" { | ||
return fmt.Errorf("metastore.address is required") | ||
} | ||
return cfg.GRPCClientConfig.Validate() | ||
} | ||
|
||
type Client struct { | ||
metastorepb.MetastoreServiceClient | ||
service services.Service | ||
conn *grpc.ClientConn | ||
config Config | ||
} | ||
|
||
func New(config Config) (c *Client, err error) { | ||
c = &Client{config: config} | ||
c.conn, err = dial(c.config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
c.MetastoreServiceClient = metastorepb.NewMetastoreServiceClient(c.conn) | ||
c.service = services.NewIdleService(nil, c.stopping) | ||
return c, nil | ||
} | ||
|
||
func (c *Client) stopping(error) error { return c.conn.Close() } | ||
|
||
func (c *Client) Service() services.Service { return c.service } | ||
|
||
func dial(cfg Config) (*grpc.ClientConn, error) { | ||
if err := cfg.Validate(); err != nil { | ||
return nil, err | ||
} | ||
options, err := cfg.GRPCClientConfig.DialOption(nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// TODO: https://github.com/grpc/grpc-proto/blob/master/grpc/service_config/service_config.proto | ||
options = append(options, grpc.WithDefaultServiceConfig(grpcServiceConfig)) | ||
return grpc.Dial(cfg.MetastoreAddress, options...) | ||
} | ||
|
||
const grpcServiceConfig = `{ | ||
"healthCheckConfig": { | ||
"serviceName": "metastorepb.MetastoreService.RaftLeader" | ||
}, | ||
"loadBalancingPolicy":"round_robin", | ||
"methodConfig": [{ | ||
"name": [{"service": "metastorepb.MetastoreService"}], | ||
"waitForReady": true, | ||
"retryPolicy": { | ||
"MaxAttempts": 4, | ||
"InitialBackoff": ".01s", | ||
"MaxBackoff": ".01s", | ||
"BackoffMultiplier": 1.0, | ||
"RetryableStatusCodes": [ "UNAVAILABLE" ] | ||
} | ||
}] | ||
}` |
This file contains 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,33 @@ | ||
package health | ||
|
||
import ( | ||
"github.com/grafana/dskit/services" | ||
"google.golang.org/grpc/health" | ||
"google.golang.org/grpc/health/grpc_health_v1" | ||
) | ||
|
||
type Service interface { | ||
SetServingStatus(string, grpc_health_v1.HealthCheckResponse_ServingStatus) | ||
} | ||
|
||
type noopService struct{} | ||
|
||
var NoOpService = noopService{} | ||
|
||
func (noopService) SetServingStatus(string, grpc_health_v1.HealthCheckResponse_ServingStatus) {} | ||
|
||
func NewGRPCHealthService() *GRPCHealthService { | ||
s := health.NewServer() | ||
return &GRPCHealthService{ | ||
Server: s, | ||
Service: services.NewIdleService(nil, func(error) error { | ||
s.Shutdown() | ||
return nil | ||
}), | ||
} | ||
} | ||
|
||
type GRPCHealthService struct { | ||
services.Service | ||
*health.Server | ||
} |
Oops, something went wrong.