Skip to content

Commit

Permalink
pkg: drop techpreview gate for collection profiles
Browse files Browse the repository at this point in the history
Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
  • Loading branch information
rexagod committed Jul 19, 2023
1 parent 6c0bb4f commit c99feb9
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 75 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
- [#1910](https://github.com/openshift/cluster-monitoring-operator/pull/1910) Add new web console usage metrics
- [#1950](https://github.com/openshift/cluster-monitoring-operator/pull/1950) Disable CORS headers on Thanos querier by default and add a flag to enable them back.
- [#1963](https://github.com/openshift/cluster-monitoring-operator/pull/1963) Add nodeExporter settings for network devices list.
- [#2046](https://github.com/openshift/cluster-monitoring-operator/pull/2046) Drop TechPreview gate for CollectionProfiles.

## 4.13

Expand Down
35 changes: 13 additions & 22 deletions pkg/manifests/config.go
Expand Up @@ -52,7 +52,6 @@ const (
type Config struct {
Images *Images `json:"-"`
RemoteWrite bool `json:"-"`
TechPreview bool `json:"-"`

ClusterMonitoringConfiguration *ClusterMonitoringConfiguration `json:"-"`
UserWorkloadConfiguration *UserWorkloadConfiguration `json:"-"`
Expand Down Expand Up @@ -190,7 +189,7 @@ func (cps CollectionProfiles) String() string {
return sb.String()
}

func NewConfig(content io.Reader, tp bool) (*Config, error) {
func NewConfig(content io.Reader) (*Config, error) {
c := Config{}
cmc := defaultClusterMonitoringConfiguration()
err := k8syaml.NewYAMLOrJSONDecoder(content, 4096).Decode(&cmc)
Expand All @@ -201,25 +200,17 @@ func NewConfig(content io.Reader, tp bool) (*Config, error) {
res := &c
res.applyDefaults()
c.UserWorkloadConfiguration = NewDefaultUserWorkloadMonitoringConfig()
// The operator should only create some manifests if techPreview is enabled
c.TechPreview = tp

if c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile != FullCollectionProfile && !tp {
return nil, errors.Wrap(ErrConfigValidation, "collectionProfiles is a TechPreview feature, to be able to use a profile different from the default (\"full\") please enable TechPreview")
}

// Validate the configured collection profile iff tech preview is enabled, even if the default profile is set.
if tp {
for _, profile := range SupportedCollectionProfiles {
var v float64
if profile == c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile {
v = 1
}
metrics.CollectionProfile.WithLabelValues(string(profile)).Set(v)
}
if !slices.Contains(SupportedCollectionProfiles, c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile) {
return nil, errors.Wrap(ErrConfigValidation, fmt.Sprintf(`%q is not supported, supported collection profiles are: %q`, c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile, SupportedCollectionProfiles.String()))
// Validate the configured collection profile.
for _, profile := range SupportedCollectionProfiles {
var v float64
if profile == c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile {
v = 1
}
metrics.CollectionProfile.WithLabelValues(string(profile)).Set(v)
}
if !slices.Contains(SupportedCollectionProfiles, c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile) {
return nil, errors.Wrap(ErrConfigValidation, fmt.Sprintf(`%q is not supported, supported collection profiles are: %q`, c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile, SupportedCollectionProfiles.String()))
}

return res, nil
Expand Down Expand Up @@ -458,14 +449,14 @@ func calculateBodySizeLimit(podCapacity int) string {
// NewConfigFromString transforms a string containing configuration in the
// openshift-monitoring/cluster-monitoring-configuration format into a data
// structure that facilitates programmatical checks of that configuration. The
// content of the data structure might change if TechPreview is enabled (tp), as
// content of the data structure might change if TechPreview is enabled, as
// some features are only meant for TechPreview.
func NewConfigFromString(content string, tp bool) (*Config, error) {
func NewConfigFromString(content string) (*Config, error) {
if content == "" {
return NewDefaultConfig(), nil
}

return NewConfig(bytes.NewBuffer([]byte(content)), tp)
return NewConfig(bytes.NewBuffer([]byte(content)))
}

func NewDefaultConfig() *Config {
Expand Down
16 changes: 8 additions & 8 deletions pkg/manifests/config_test.go
Expand Up @@ -29,7 +29,7 @@ func TestConfigParsing(t *testing.T) {
if err != nil {
t.Fatal(err)
}
c, err := NewConfig(f, false)
c, err := NewConfig(f)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestNewUserConfigFromStringParsing(t *testing.T) {
}

func TestEmptyConfigIsValid(t *testing.T) {
_, err := NewConfigFromString("", false)
_, err := NewConfigFromString("")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -175,21 +175,21 @@ func TestTelemeterClientConfig(t *testing.T) {
}

func TestPromAdapterDedicatedSMsDefaultsToDisabled(t *testing.T) {
c, err := NewConfigFromString("", false)
c, err := NewConfigFromString("")
if err != nil {
t.Fatal(err)
}
if c.ClusterMonitoringConfiguration.K8sPrometheusAdapter.DedicatedServiceMonitors.Enabled {
t.Error("an empty configuration should have prometheus-adapter dedicated ServiceMonitors dislabled")
}
c, err = NewConfigFromString(`{"k8sPrometheusAdapter":{}}`, false)
c, err = NewConfigFromString(`{"k8sPrometheusAdapter":{}}`)
if err != nil {
t.Fatal(err)
}
if c.ClusterMonitoringConfiguration.K8sPrometheusAdapter.DedicatedServiceMonitors.Enabled {
t.Error("an empty k8sPrometheusAdapter configuration should have prometheus-adapter dedicated ServiceMonitors dislabled")
}
c, err = NewConfigFromString(`{"k8sPrometheusAdapter":{"dedicatedServiceMonitors":{}}}`, false)
c, err = NewConfigFromString(`{"k8sPrometheusAdapter":{"dedicatedServiceMonitors":{}}}`)
if err != nil {
t.Fatal(err)
}
Expand All @@ -205,7 +205,7 @@ func TestHttpProxyConfig(t *testing.T) {
noProxy: https://example.com
`

c, err := NewConfigFromString(conf, false)
c, err := NewConfigFromString(conf)
if err != nil {
t.Errorf("expected no error parsing config - %v", err)
}
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestLoadEnforcedBodySizeLimit(t *testing.T) {
},
} {
t.Run(tt.name, func(t *testing.T) {
c, err := NewConfigFromString(tt.config, false)
c, err := NewConfigFromString(tt.config)
if err != nil {
t.Fatalf("config parsing error")
}
Expand Down Expand Up @@ -381,7 +381,7 @@ func TestCollectionProfile(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
c, err := NewConfigFromString(tc.config, true)
c, err := NewConfigFromString(tc.config)
if err != nil {
if tc.expectedError {
return
Expand Down
16 changes: 6 additions & 10 deletions pkg/manifests/manifests.go
Expand Up @@ -727,7 +727,7 @@ func (f *Factory) KubeStateMetricsClusterRole() (*rbacv1.ClusterRole, error) {
}

func (f *Factory) KubeStateMetricsServiceMonitors() ([]*monv1.ServiceMonitor, error) {
return serviceMonitors(f.config.TechPreview, f.KubeStateMetricsServiceMonitor, f.KubeStateMetricsMinimalServiceMonitor)
return serviceMonitors(f.KubeStateMetricsServiceMonitor, f.KubeStateMetricsMinimalServiceMonitor)
}

func (f *Factory) KubeStateMetricsServiceMonitor() (*monv1.ServiceMonitor, error) {
Expand Down Expand Up @@ -841,7 +841,7 @@ func (f *Factory) OpenShiftStateMetricsRBACProxySecret() (*v1.Secret, error) {
}

func (f *Factory) NodeExporterServiceMonitors() ([]*monv1.ServiceMonitor, error) {
return serviceMonitors(f.config.TechPreview, f.NodeExporterServiceMonitor, f.NodeExporterMinimalServiceMonitor)
return serviceMonitors(f.NodeExporterServiceMonitor, f.NodeExporterMinimalServiceMonitor)
}

func (f *Factory) NodeExporterServiceMonitor() (*monv1.ServiceMonitor, error) {
Expand Down Expand Up @@ -2018,7 +2018,7 @@ func (f *Factory) PrometheusAdapterService() (*v1.Service, error) {
}

func (f *Factory) PrometheusAdapterServiceMonitors() ([]*monv1.ServiceMonitor, error) {
return serviceMonitors(f.config.TechPreview, f.PrometheusAdapterServiceMonitor, f.PrometheusAdapterMinimalServiceMonitor)
return serviceMonitors(f.PrometheusAdapterServiceMonitor, f.PrometheusAdapterMinimalServiceMonitor)
}

func (f *Factory) PrometheusAdapterServiceMonitor() (*monv1.ServiceMonitor, error) {
Expand Down Expand Up @@ -2444,7 +2444,7 @@ func (f *Factory) ControlPlanePrometheusRule() (*monv1.PrometheusRule, error) {
}

func (f *Factory) ControlPlaneKubeletServiceMonitors() ([]*monv1.ServiceMonitor, error) {
return serviceMonitors(f.config.TechPreview, f.ControlPlaneKubeletServiceMonitor, f.ControlPlaneKubeletMinimalServiceMonitor)
return serviceMonitors(f.ControlPlaneKubeletServiceMonitor, f.ControlPlaneKubeletMinimalServiceMonitor)
}

func (f *Factory) ControlPlaneKubeletServiceMonitor() (*monv1.ServiceMonitor, error) {
Expand Down Expand Up @@ -3520,7 +3520,7 @@ func (f *Factory) HashSecret(secret *v1.Secret, data ...string) (*v1.Secret, err
}, nil
}

func serviceMonitors(appendMinimal bool, fullServiceMonitor, minimalServiceMonitor func() (*monv1.ServiceMonitor, error)) ([]*monv1.ServiceMonitor, error) {
func serviceMonitors(fullServiceMonitor, minimalServiceMonitor func() (*monv1.ServiceMonitor, error)) ([]*monv1.ServiceMonitor, error) {
sMonitor, err := fullServiceMonitor()
if err != nil {
return nil, err
Expand All @@ -3529,11 +3529,7 @@ func serviceMonitors(appendMinimal bool, fullServiceMonitor, minimalServiceMonit
if err != nil {
return nil, err
}
sms := []*monv1.ServiceMonitor{sMonitor}
if appendMinimal {
sms = append(sms, sMonitorMinimal)
}
return sms, nil
return []*monv1.ServiceMonitor{sMonitor, sMonitorMinimal}, nil
}

func addRemoteWriteConfigs(clusterID string, rw []monv1.RemoteWriteSpec, rwTargets ...RemoteWriteSpec) []monv1.RemoteWriteSpec {
Expand Down

0 comments on commit c99feb9

Please sign in to comment.