Skip to content

Commit

Permalink
pkg/prometheus: Export the prometheus.ConfigGenerator type (prometh…
Browse files Browse the repository at this point in the history
…eus-operator#3972)

This makes the `prometheus.ConfigGenerator` type and its `GenerateConfig()`
method exported and available to consumers outside of the `prometheus` package.

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>
  • Loading branch information
Aneurysm9 authored Apr 14, 2021
1 parent 65e18f6 commit a4f5928
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 71 deletions.
6 changes: 3 additions & 3 deletions pkg/prometheus/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type Operator struct {
kubeletSyncEnabled bool
config operator.Config

configGenerator *configGenerator
configGenerator *ConfigGenerator
}

// New creates a new controller.
Expand Down Expand Up @@ -140,7 +140,7 @@ func New(ctx context.Context, conf operator.Config, logger log.Logger, r prometh
kubeletObjectNamespace: kubeletObjectNamespace,
kubeletSyncEnabled: kubeletSyncEnabled,
config: conf,
configGenerator: newConfigGenerator(logger),
configGenerator: NewConfigGenerator(logger),
metrics: operator.NewMetrics("prometheus", r),
nodeAddressLookupErrors: prometheus.NewCounter(prometheus.CounterOpts{
Name: "prometheus_operator_node_address_lookup_errors_total",
Expand Down Expand Up @@ -1501,7 +1501,7 @@ func (c *Operator) createOrUpdateConfigurationSecret(ctx context.Context, p *mon
}

// Update secret based on the most recent configuration.
conf, err := c.configGenerator.generateConfig(
conf, err := c.configGenerator.GenerateConfig(
p,
smons,
pmons,
Expand Down
25 changes: 14 additions & 11 deletions pkg/prometheus/promcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ var (
invalidLabelCharRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)
)

type configGenerator struct {
// ConfigGenerator is used to create Prometheus configurations from operator resources.
type ConfigGenerator struct {
logger log.Logger
}

func newConfigGenerator(logger log.Logger) *configGenerator {
cg := &configGenerator{
// NewConfigGenerator creates a ConfigGenerator instance using the provided Logger.
func NewConfigGenerator(logger log.Logger) *ConfigGenerator {
cg := &ConfigGenerator{
logger: logger,
}
return cg
Expand Down Expand Up @@ -153,7 +155,8 @@ func buildExternalLabels(p *v1.Prometheus) yaml.MapSlice {
return stringMapToMapSlice(m)
}

func (cg *configGenerator) generateConfig(
// GenerateConfig creates a serialized YAML representation of a Prometheus configuration using the provided resources.
func (cg *ConfigGenerator) GenerateConfig(
p *v1.Prometheus,
sMons map[string]*v1.ServiceMonitor,
pMons map[string]*v1.PodMonitor,
Expand Down Expand Up @@ -428,7 +431,7 @@ func initRelabelings() []yaml.MapSlice {
}
}

func (cg *configGenerator) generatePodMonitorConfig(
func (cg *ConfigGenerator) generatePodMonitorConfig(
version semver.Version,
m *v1.PodMonitor,
ep v1.PodMetricsEndpoint,
Expand Down Expand Up @@ -669,7 +672,7 @@ func (cg *configGenerator) generatePodMonitorConfig(
return cfg
}

func (cg *configGenerator) generateProbeConfig(
func (cg *ConfigGenerator) generateProbeConfig(
version semver.Version,
m *v1.Probe,
apiserverConfig *v1.APIServerConfig,
Expand Down Expand Up @@ -892,7 +895,7 @@ func (cg *configGenerator) generateProbeConfig(
return cfg
}

func (cg *configGenerator) generateServiceMonitorConfig(
func (cg *ConfigGenerator) generateServiceMonitorConfig(
version semver.Version,
m *v1.ServiceMonitor,
ep v1.Endpoint,
Expand Down Expand Up @@ -1241,7 +1244,7 @@ func getNamespacesFromNamespaceSelector(nsel *v1.NamespaceSelector, namespace st
return nsel.MatchNames
}

func (cg *configGenerator) generateK8SSDConfig(namespaces []string, apiserverConfig *v1.APIServerConfig, basicAuthSecrets map[string]assets.BasicAuthCredentials, role string) yaml.MapItem {
func (cg *ConfigGenerator) generateK8SSDConfig(namespaces []string, apiserverConfig *v1.APIServerConfig, basicAuthSecrets map[string]assets.BasicAuthCredentials, role string) yaml.MapItem {
k8sSDConfig := yaml.MapSlice{
{
Key: "role",
Expand Down Expand Up @@ -1298,7 +1301,7 @@ func (cg *configGenerator) generateK8SSDConfig(namespaces []string, apiserverCon
}
}

func (cg *configGenerator) generateAlertmanagerConfig(version semver.Version, am v1.AlertmanagerEndpoints, apiserverConfig *v1.APIServerConfig, basicAuthSecrets map[string]assets.BasicAuthCredentials) yaml.MapSlice {
func (cg *ConfigGenerator) generateAlertmanagerConfig(version semver.Version, am v1.AlertmanagerEndpoints, apiserverConfig *v1.APIServerConfig, basicAuthSecrets map[string]assets.BasicAuthCredentials) yaml.MapSlice {
if am.Scheme == "" {
am.Scheme = "http"
}
Expand Down Expand Up @@ -1359,7 +1362,7 @@ func (cg *configGenerator) generateAlertmanagerConfig(version semver.Version, am
return cfg
}

func (cg *configGenerator) generateRemoteReadConfig(version semver.Version, p *v1.Prometheus, basicAuthSecrets map[string]assets.BasicAuthCredentials) yaml.MapItem {
func (cg *ConfigGenerator) generateRemoteReadConfig(version semver.Version, p *v1.Prometheus, basicAuthSecrets map[string]assets.BasicAuthCredentials) yaml.MapItem {

cfgs := []yaml.MapSlice{}

Expand Down Expand Up @@ -1421,7 +1424,7 @@ func (cg *configGenerator) generateRemoteReadConfig(version semver.Version, p *v
}
}

func (cg *configGenerator) generateRemoteWriteConfig(version semver.Version, p *v1.Prometheus, basicAuthSecrets map[string]assets.BasicAuthCredentials) yaml.MapItem {
func (cg *ConfigGenerator) generateRemoteWriteConfig(version semver.Version, p *v1.Prometheus, basicAuthSecrets map[string]assets.BasicAuthCredentials) yaml.MapItem {

cfgs := []yaml.MapSlice{}

Expand Down
Loading

0 comments on commit a4f5928

Please sign in to comment.