Skip to content

Commit

Permalink
service/cluster: add common block for clustering arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
rfratto committed Oct 30, 2023
1 parent bb7ce48 commit 9083b26
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 30 deletions.
8 changes: 1 addition & 7 deletions component/loki/source/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ type Arguments struct {
// Client settings to connect to Kubernetes.
Client commonk8s.ClientArguments `river:"client,block,optional"`

Clustering Clustering `river:"clustering,block,optional"`
}

// Clustering holds values that configure clustering-specific behavior.
type Clustering struct {
// TODO(@tpaschalis) Move this block to a shared place for all components using clustering.
Enabled bool `river:"enabled,attr"`
Clustering cluster.ComponentBlock `river:"clustering,block,optional"`
}

// DefaultArguments holds default settings for loki.source.kubernetes.
Expand Down
8 changes: 1 addition & 7 deletions component/loki/source/podlogs/podlogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ type Arguments struct {
Selector config.LabelSelector `river:"selector,block,optional"`
NamespaceSelector config.LabelSelector `river:"namespace_selector,block,optional"`

Clustering Clustering `river:"clustering,block,optional"`
}

// Clustering holds values that configure clustering-specific behavior.
type Clustering struct {
// TODO(@tpaschalis) Move this block to a shared place for all components using clustering.
Enabled bool `river:"enabled,attr"`
Clustering cluster.ComponentBlock `river:"clustering,block,optional"`
}

// DefaultArguments holds default settings for loki.source.kubernetes.
Expand Down
9 changes: 2 additions & 7 deletions component/prometheus/operator/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/grafana/agent/component/common/kubernetes"
flow_relabel "github.com/grafana/agent/component/common/relabel"
"github.com/grafana/agent/component/prometheus/scrape"
"github.com/grafana/agent/service/cluster"
"github.com/prometheus/common/model"
promconfig "github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/storage"
Expand All @@ -26,19 +27,13 @@ type Arguments struct {
// LabelSelector allows filtering discovered monitor resources by labels
LabelSelector *config.LabelSelector `river:"selector,block,optional"`

Clustering Clustering `river:"clustering,block,optional"`
Clustering cluster.ComponentBlock `river:"clustering,block,optional"`

RelabelConfigs []*flow_relabel.Config `river:"rule,block,optional"`

Scrape ScrapeOptions `river:"scrape,block,optional"`
}

// Clustering holds values that configure clustering-specific behavior.
type Clustering struct {
// TODO(@tpaschalis) Move this block to a shared place for all components using clustering.
Enabled bool `river:"enabled,attr"`
}

// ScrapeOptions holds values that configure scraping behavior.
type ScrapeOptions struct {
// DefaultScrapeInterval is the default interval to scrape targets.
Expand Down
8 changes: 1 addition & 7 deletions component/prometheus/scrape/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,7 @@ type Arguments struct {
ExtraMetrics bool `river:"extra_metrics,attr,optional"`
EnableProtobufNegotiation bool `river:"enable_protobuf_negotiation,attr,optional"`

Clustering Clustering `river:"clustering,block,optional"`
}

// Clustering holds values that configure clustering-specific behavior.
type Clustering struct {
// TODO(@tpaschalis) Move this block to a shared place for all components using clustering.
Enabled bool `river:"enabled,attr"`
Clustering cluster.ComponentBlock `river:"clustering,block,optional"`
}

// SetToDefault implements river.Defaulter.
Expand Down
2 changes: 1 addition & 1 deletion component/pyroscope/scrape/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type Arguments struct {

ProfilingConfig ProfilingConfig `river:"profiling_config,block,optional"`

Clustering scrape.Clustering `river:"clustering,block,optional"`
Clustering cluster.ComponentBlock `river:"clustering,block,optional"`
}

type ProfilingConfig struct {
Expand Down
3 changes: 2 additions & 1 deletion converter/internal/prometheusconvert/component/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/grafana/agent/converter/diag"
"github.com/grafana/agent/converter/internal/common"
"github.com/grafana/agent/converter/internal/prometheusconvert/build"
"github.com/grafana/agent/service/cluster"
prom_config "github.com/prometheus/prometheus/config"
prom_discovery "github.com/prometheus/prometheus/discovery"
"github.com/prometheus/prometheus/storage"
Expand Down Expand Up @@ -61,7 +62,7 @@ func toScrapeArguments(scrapeConfig *prom_config.ScrapeConfig, forwardTo []stora
HTTPClientConfig: *common.ToHttpClientConfig(&scrapeConfig.HTTPClientConfig),
ExtraMetrics: false,
EnableProtobufNegotiation: false,
Clustering: scrape.Clustering{Enabled: false},
Clustering: cluster.ComponentBlock{Enabled: false},
}
}

Expand Down
7 changes: 7 additions & 0 deletions service/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,13 @@ type Component interface {
NotifyClusterChange()
}

// ComponentBlock holds common arguments for clustering settings within a
// component. ComponentBlock is intended to be exposed as a block called
// "clustering".
type ComponentBlock struct {
Enabled bool `river:"enabled,attr"`
}

// Cluster is a read-only view of a cluster.
type Cluster interface {
// Lookup determines the set of replicationFactor owners for a given key.
Expand Down

0 comments on commit 9083b26

Please sign in to comment.