Skip to content

Commit

Permalink
Add thanos/objstore to common configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoBraveCoding committed Nov 16, 2023
1 parent 0c88216 commit 184ea74
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
7 changes: 7 additions & 0 deletions pkg/loki/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/grafana/dskit/flagext"
"github.com/grafana/dskit/netutil"

"github.com/grafana/loki/pkg/storage/bucket"
"github.com/grafana/loki/pkg/storage/chunk/client/alibaba"
"github.com/grafana/loki/pkg/storage/chunk/client/aws"
"github.com/grafana/loki/pkg/storage/chunk/client/azure"
Expand Down Expand Up @@ -58,6 +59,8 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) {
c.Ring.RegisterFlagsWithPrefix("common.storage.", "collectors/", f)
c.Ring.RegisterFlagsWithPrefix("common.storage.", "collectors/", throwaway)

f.BoolVar(&c.Storage.ThanosObjStore, "common.thanos.enable", false, "Enable the thanos.io/objstore to be the backend for object storage")

// instance related flags.
c.InstanceInterfaceNames = netutil.PrivateNetworkInterfacesWithFallback([]string{"eth0", "en0"}, util_log.Logger)
throwaway.StringVar(&c.InstanceAddr, "common.instance-addr", "", "Default advertised address to be used by Loki components.")
Expand All @@ -78,6 +81,8 @@ type Storage struct {
Hedging hedging.Config `yaml:"hedging"`
COS ibmcloud.COSConfig `yaml:"cos"`
CongestionControl congestion.Config `yaml:"congestion_control,omitempty"`
ThanosObjStore bool `yaml:"thanos_objstore"`
ObjStoreConf bucket.Config `yaml:"objstore_config"`
}

func (s *Storage) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
Expand All @@ -91,6 +96,8 @@ func (s *Storage) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
s.Hedging.RegisterFlagsWithPrefix(prefix, f)
s.COS.RegisterFlagsWithPrefix(prefix, f)
s.CongestionControl.RegisterFlagsWithPrefix(prefix, f)

s.ObjStoreConf.RegisterFlagsWithPrefix(prefix+"thanos.", f)
}

type FilesystemConfig struct {
Expand Down
15 changes: 15 additions & 0 deletions pkg/loki/config_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/grafana/loki/pkg/util/cfg"
lokiring "github.com/grafana/loki/pkg/util/ring"

"github.com/grafana/loki/pkg/ruler/rulestore"
"github.com/grafana/loki/pkg/ruler/rulestore/local"
loki_net "github.com/grafana/loki/pkg/util/net"
)
Expand Down Expand Up @@ -564,6 +565,20 @@ func applyStorageConfig(cfg, defaults *ConfigWrapper) error {
}
}

if !reflect.DeepEqual(cfg.Common.Storage.ObjStoreConf, defaults.StorageConfig.ObjStoreConf) {
configsFound++

applyConfig = func(r *ConfigWrapper) {
r.Ruler.StoreConfig.ThanosObjStore = r.Common.Storage.ThanosObjStore
r.Ruler.StoreConfig.ObjStoreConf = rulestore.Config{
Config: r.Common.Storage.ObjStoreConf,
}
r.StorageConfig.ThanosObjStore = r.Common.Storage.ThanosObjStore
r.StorageConfig.ObjStoreConf = r.Common.Storage.ObjStoreConf
r.StorageConfig.Hedging = r.Common.Storage.Hedging
}
}

if configsFound > 1 {
return ErrTooManyStorageConfigs
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/storage/chunk/client/gcp/gcs_thanos_object_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ type GCSThanosObjectClient struct {
client objstore.Bucket
}

func NewGCSThanosObjectClient(ctx context.Context, cfg bucket.Config, component string, logger log.Logger, hedgingCfg hedging.Config) (*GCSThanosObjectClient, error) {
return newGCSThanosObjectClient(ctx, cfg, component, logger)
func NewGCSThanosObjectClient(ctx context.Context, cfg bucket.Config, component string, logger log.Logger, hedgingCfg hedging.Config, reg prometheus.Registerer) (*GCSThanosObjectClient, error) {
//TODO(JoaoBraveCoding) Add Hedging client once we are able to configure HTTP on GCS provider
return newGCSThanosObjectClient(ctx, cfg, component, logger, reg)
}

func newGCSThanosObjectClient(ctx context.Context, cfg bucket.Config, component string, logger log.Logger) (*GCSThanosObjectClient, error) {
bucket, err := bucket.NewClient(ctx, cfg, component, logger, prometheus.DefaultRegisterer)
func newGCSThanosObjectClient(ctx context.Context, cfg bucket.Config, component string, logger log.Logger, reg prometheus.Registerer) (*GCSThanosObjectClient, error) {
bucket, err := bucket.NewClient(ctx, cfg, component, logger, reg)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/storage/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
cfg.Hedging.RegisterFlagsWithPrefix("store.", f)
cfg.CongestionControl.RegisterFlagsWithPrefix("store.", f)

cfg.ObjStoreConf.RegisterFlags(f)
f.BoolVar(&cfg.ThanosObjStore, "thanos.enable", false, "Enable the thanos.io/objstore to be the backend for object storage")
cfg.ObjStoreConf.RegisterFlagsWithPrefix("thanos.", f)

cfg.IndexQueriesCacheConfig.RegisterFlagsWithPrefix("store.index-cache-read.", "", f)
f.DurationVar(&cfg.IndexCacheValidity, "store.index-cache-validity", 5*time.Minute, "Cache validity for active index entries. Should be no higher than -ingester.max-chunk-idle.")
Expand Down Expand Up @@ -719,7 +720,7 @@ func internalNewObjectClient(name string, cfg Config, clientMetrics ClientMetric
// Passing "gcs" as the component name as currently it's not
// possible to get the component called this method
// TODO(JoaoBraveCoding) update compoent when bigger refactor happens
return gcp.NewGCSThanosObjectClient(context.Background(), cfg.ObjStoreConf, "gcs", utilLog.Logger, cfg.Hedging)
return gcp.NewGCSThanosObjectClient(context.Background(), cfg.ObjStoreConf, "gcs", utilLog.Logger, cfg.Hedging, prometheus.WrapRegistererWithPrefix("loki_", prometheus.NewRegistry()))
}
return gcp.NewGCSObjectClient(context.Background(), gcsCfg, cfg.Hedging)

Expand Down

0 comments on commit 184ea74

Please sign in to comment.