-
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: Boilerplate for new bloom build planner and worker components. (#…
- Loading branch information
1 parent
88e545f
commit 8978ecf
Showing
10 changed files
with
284 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package builder | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/grafana/dskit/services" | ||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
utillog "github.com/grafana/loki/v3/pkg/util/log" | ||
) | ||
|
||
type Worker struct { | ||
services.Service | ||
|
||
cfg Config | ||
metrics *Metrics | ||
logger log.Logger | ||
} | ||
|
||
func New( | ||
cfg Config, | ||
logger log.Logger, | ||
r prometheus.Registerer, | ||
) (*Worker, error) { | ||
utillog.WarnExperimentalUse("Bloom Builder", logger) | ||
|
||
w := &Worker{ | ||
cfg: cfg, | ||
metrics: NewMetrics(r), | ||
logger: logger, | ||
} | ||
|
||
w.Service = services.NewBasicService(w.starting, w.running, w.stopping) | ||
return w, nil | ||
} | ||
|
||
func (w *Worker) starting(_ context.Context) (err error) { | ||
w.metrics.running.Set(1) | ||
return err | ||
} | ||
|
||
func (w *Worker) stopping(_ error) error { | ||
w.metrics.running.Set(0) | ||
return nil | ||
} | ||
|
||
func (w *Worker) running(_ context.Context) error { | ||
return nil | ||
} |
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,21 @@ | ||
package builder | ||
|
||
import "flag" | ||
|
||
// Config configures the bloom-builder component. | ||
type Config struct { | ||
// TODO: Add config | ||
} | ||
|
||
// RegisterFlagsWithPrefix registers flags for the bloom-planner configuration. | ||
func (cfg *Config) RegisterFlagsWithPrefix(_ string, _ *flag.FlagSet) { | ||
// TODO: Register flags with flagsPrefix | ||
} | ||
|
||
func (cfg *Config) Validate() error { | ||
return nil | ||
} | ||
|
||
type Limits interface { | ||
// TODO: Add limits | ||
} |
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,26 @@ | ||
package builder | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
) | ||
|
||
const ( | ||
metricsNamespace = "loki" | ||
metricsSubsystem = "bloombuilder" | ||
) | ||
|
||
type Metrics struct { | ||
running prometheus.Gauge | ||
} | ||
|
||
func NewMetrics(r prometheus.Registerer) *Metrics { | ||
return &Metrics{ | ||
running: promauto.With(r).NewGauge(prometheus.GaugeOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: metricsSubsystem, | ||
Name: "running", | ||
Help: "Value will be 1 if the bloom builder is currently running on this instance", | ||
}), | ||
} | ||
} |
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,40 @@ | ||
package bloombuild | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
|
||
"github.com/grafana/loki/v3/pkg/bloombuild/builder" | ||
"github.com/grafana/loki/v3/pkg/bloombuild/planner" | ||
) | ||
|
||
// Config configures the bloom-planner component. | ||
type Config struct { | ||
Enabled bool `yaml:"enabled"` | ||
|
||
Planner planner.Config `yaml:"planner"` | ||
Builder builder.Config `yaml:"builder"` | ||
} | ||
|
||
// RegisterFlags registers flags for the bloom building configuration. | ||
func (cfg *Config) RegisterFlags(f *flag.FlagSet) { | ||
f.BoolVar(&cfg.Enabled, "bloom-build.enabled", false, "Flag to enable or disable the usage of the bloom-planner and bloom-builder components.") | ||
cfg.Planner.RegisterFlagsWithPrefix("bloom-build.planner", f) | ||
cfg.Builder.RegisterFlagsWithPrefix("bloom-build.builder", f) | ||
} | ||
|
||
func (cfg *Config) Validate() error { | ||
if !cfg.Enabled { | ||
return nil | ||
} | ||
|
||
if err := cfg.Planner.Validate(); err != nil { | ||
return fmt.Errorf("invalid bloom planner configuration: %w", err) | ||
} | ||
|
||
if err := cfg.Builder.Validate(); err != nil { | ||
return fmt.Errorf("invalid bloom builder configuration: %w", err) | ||
} | ||
|
||
return nil | ||
} |
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,21 @@ | ||
package planner | ||
|
||
import "flag" | ||
|
||
// Config configures the bloom-planner component. | ||
type Config struct { | ||
// TODO: Add config | ||
} | ||
|
||
// RegisterFlagsWithPrefix registers flags for the bloom-planner configuration. | ||
func (cfg *Config) RegisterFlagsWithPrefix(_ string, _ *flag.FlagSet) { | ||
// TODO: Register flags with flagsPrefix | ||
} | ||
|
||
func (cfg *Config) Validate() error { | ||
return nil | ||
} | ||
|
||
type Limits interface { | ||
// TODO: Add limits | ||
} |
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,26 @@ | ||
package planner | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
) | ||
|
||
const ( | ||
metricsNamespace = "loki" | ||
metricsSubsystem = "bloomplanner" | ||
) | ||
|
||
type Metrics struct { | ||
running prometheus.Gauge | ||
} | ||
|
||
func NewMetrics(r prometheus.Registerer) *Metrics { | ||
return &Metrics{ | ||
running: promauto.With(r).NewGauge(prometheus.GaugeOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: metricsSubsystem, | ||
Name: "running", | ||
Help: "Value will be 1 if bloom planner is currently running on this instance", | ||
}), | ||
} | ||
} |
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,50 @@ | ||
package planner | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/grafana/dskit/services" | ||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
utillog "github.com/grafana/loki/v3/pkg/util/log" | ||
) | ||
|
||
type Planner struct { | ||
services.Service | ||
|
||
cfg Config | ||
metrics *Metrics | ||
logger log.Logger | ||
} | ||
|
||
func New( | ||
cfg Config, | ||
logger log.Logger, | ||
r prometheus.Registerer, | ||
) (*Planner, error) { | ||
utillog.WarnExperimentalUse("Bloom Planner", logger) | ||
|
||
p := &Planner{ | ||
cfg: cfg, | ||
metrics: NewMetrics(r), | ||
logger: logger, | ||
} | ||
|
||
p.Service = services.NewBasicService(p.starting, p.running, p.stopping) | ||
return p, nil | ||
} | ||
|
||
func (p *Planner) starting(_ context.Context) (err error) { | ||
p.metrics.running.Set(1) | ||
return err | ||
} | ||
|
||
func (p *Planner) stopping(_ error) error { | ||
p.metrics.running.Set(0) | ||
return nil | ||
} | ||
|
||
func (p *Planner) running(_ context.Context) error { | ||
return nil | ||
} |
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