Skip to content

Commit

Permalink
MON-3487: incorporate MetricsCollectionProfiles
Browse files Browse the repository at this point in the history
Put the collection-profiles feature-set behind a dedicated feature-gate.

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
  • Loading branch information
rexagod committed Apr 9, 2024
1 parent bf04aae commit 965d371
Show file tree
Hide file tree
Showing 146 changed files with 847 additions and 14,690 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -10,7 +10,7 @@ require (
github.com/ghodss/yaml v1.0.0
github.com/go-kit/log v0.2.1
github.com/imdario/mergo v0.3.16
github.com/openshift/api v0.0.0-20240320105957-b09bc66e1760
github.com/openshift/api v0.0.0-20240327143419-1e5b8d673d96
github.com/openshift/client-go v0.0.0-20231218140158-47f6d749b9d9
github.com/openshift/library-go v0.0.0-20240216151214-738f3fa4ccf8
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.71.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -390,8 +390,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/openshift/api v0.0.0-20240320105957-b09bc66e1760 h1:UzSlJWW6VKseRrpUO05xh2AyGyZ+OSbuCJjst5STVdM=
github.com/openshift/api v0.0.0-20240320105957-b09bc66e1760/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
github.com/openshift/api v0.0.0-20240327143419-1e5b8d673d96 h1:H6N843FYq/qnQkAgU8qNxSI6GkKxGkUasDFjMfb0D2s=
github.com/openshift/api v0.0.0-20240327143419-1e5b8d673d96/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
github.com/openshift/client-go v0.0.0-20231218140158-47f6d749b9d9 h1:kjgW3luAkf9NWu+8u+jqNNbexDG+CY82/INw8hGbG14=
github.com/openshift/client-go v0.0.0-20231218140158-47f6d749b9d9/go.mod h1:kKmxYRXTMutfF7XzGppFdbLhNGX1brXkRsZx5ID8c7U=
github.com/openshift/library-go v0.0.0-20240216151214-738f3fa4ccf8 h1:dKtHGYiOwl0DKZEWBW4MFWFS6IYW02AVD1WSuUAVwEo=
Expand Down
9 changes: 0 additions & 9 deletions pkg/client/client.go
Expand Up @@ -595,15 +595,6 @@ func (c *Client) GetConsoleConfig(ctx context.Context, name string) (*configv1.C
return c.oscclient.ConfigV1().Consoles().Get(ctx, name, metav1.GetOptions{})
}

func (c *Client) TechPreviewEnabled(ctx context.Context) (bool, error) {
fg, err := c.oscclient.ConfigV1().FeatureGates().Get(ctx, "cluster", metav1.GetOptions{})
if err != nil {
return false, err
}

return fg.Spec.FeatureSet == configv1.TechPreviewNoUpgrade, nil
}

func (c *Client) GetConfigmap(ctx context.Context, namespace, name string) (*v1.ConfigMap, error) {
return c.kclient.CoreV1().ConfigMaps(namespace).Get(ctx, name, metav1.GetOptions{})
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/manifests/config.go
Expand Up @@ -49,9 +49,9 @@ const (
)

type Config struct {
Images *Images `json:"-"`
RemoteWrite bool `json:"-"`
TechPreview bool `json:"-"`
Images *Images `json:"-"`
RemoteWrite bool `json:"-"`
CollectionProfilesFeatureGateEnabled bool `json:"-"`

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

func NewConfig(content io.Reader, tp bool) (*Config, error) {
c := Config{TechPreview: tp}
func NewConfig(content io.Reader, collectionProfilesFeatureGateEnabled bool) (*Config, error) {
c := Config{CollectionProfilesFeatureGateEnabled: collectionProfilesFeatureGateEnabled}
cmc := defaultClusterMonitoringConfiguration()
err := k8syaml.NewYAMLOrJSONDecoder(content, 4096).Decode(&cmc)
if err != nil {
Expand Down Expand Up @@ -438,12 +438,12 @@ func (c *Config) LoadEnforcedBodySizeLimit(pcr PodCapacityReader, ctx context.Co
}

func (c *Config) Precheck() error {
if c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile != FullCollectionProfile && !c.TechPreview {
return fmt.Errorf("collectionProfiles is a TechPreview feature, to be able to use a profile different from the default (\"full\") please enable TechPreview: %w", ErrConfigValidation)
if c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile != FullCollectionProfile && !c.CollectionProfilesFeatureGateEnabled {
return fmt.Errorf("%w: collectionProfiles is currently a TechPreview feature behind the \"MetricsCollectionProfiles\" feature-gate, to be able to use a profile different from the default (\"full\") please enable it first", ErrConfigValidation)
}

// Validate the configured collection profile iff tech preview is enabled, even if the default profile is set.
if c.TechPreview {
if c.CollectionProfilesFeatureGateEnabled {
for _, profile := range SupportedCollectionProfiles {
var v float64
if profile == c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile {
Expand Down Expand Up @@ -484,12 +484,12 @@ func calculateBodySizeLimit(podCapacity int) string {
// structure that facilitates programmatical checks of that configuration. The
// content of the data structure might change if TechPreview is enabled (tp), as
// some features are only meant for TechPreview.
func NewConfigFromString(content string, tp bool) (*Config, error) {
func NewConfigFromString(content string, collectionProfilesFeatureGateEnabled bool) (*Config, error) {
if content == "" {
return NewDefaultConfig(), nil
}

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

func NewDefaultConfig() *Config {
Expand Down
8 changes: 4 additions & 4 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.config.CollectionProfilesFeatureGateEnabled, f.KubeStateMetricsServiceMonitor, f.KubeStateMetricsMinimalServiceMonitor)
}

func (f *Factory) KubeStateMetricsServiceMonitor() (*monv1.ServiceMonitor, error) {
Expand Down Expand Up @@ -847,7 +847,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.config.CollectionProfilesFeatureGateEnabled, f.NodeExporterServiceMonitor, f.NodeExporterMinimalServiceMonitor)
}

func (f *Factory) NodeExporterServiceMonitor() (*monv1.ServiceMonitor, error) {
Expand Down Expand Up @@ -1964,7 +1964,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.config.CollectionProfilesFeatureGateEnabled, f.PrometheusAdapterServiceMonitor, f.PrometheusAdapterMinimalServiceMonitor)
}

func (f *Factory) PrometheusAdapterServiceMonitor() (*monv1.ServiceMonitor, error) {
Expand Down Expand Up @@ -2627,7 +2627,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.config.CollectionProfilesFeatureGateEnabled, f.ControlPlaneKubeletServiceMonitor, f.ControlPlaneKubeletMinimalServiceMonitor)
}

func (f *Factory) ControlPlaneKubeletServiceMonitor() (*monv1.ServiceMonitor, error) {
Expand Down
8 changes: 7 additions & 1 deletion pkg/metrics/metrics.go
Expand Up @@ -5,6 +5,12 @@ import (
"k8s.io/component-base/metrics/legacyregistry"
)

// The various stability levels used here are analogous to the ones used in the Kubernetes project. They are:
// INTERNAL metrics have no stability guarantees, as such, labels may be arbitrarily added/removed and the metric may be deleted at any time.
// ALPHA metrics have no stability guarantees, as such, labels may be arbitrarily added/removed, while metrics undergo a deprecation cycle before deletion.
// BETA metrics have some stability guarantees, as such, labels may be added but not removed, while metrics undergo a deprecation cycle before deletion.
// STABLE metrics are guaranteed not be mutated.

// ReconcileAttempts is a counter that indicates the number of attempts to reconcile the operator configuration.
var ReconcileAttempts = metrics.NewCounter(&metrics.CounterOpts{
Name: "cluster_monitoring_operator_reconcile_attempts_total",
Expand All @@ -25,7 +31,7 @@ var ReconcileStatus = metrics.NewGauge(&metrics.GaugeOpts{
var CollectionProfile = metrics.NewGaugeVec(&metrics.GaugeOpts{
Name: "cluster_monitoring_operator_collection_profile",
Help: "Information about collection profiles. Set to 1 for the configured collection profile, else 0.",
StabilityLevel: metrics.ALPHA,
StabilityLevel: metrics.BETA,
}, []string{"profile"})

var DeprecatedConfig = metrics.NewGaugeVec(&metrics.GaugeOpts{
Expand Down
14 changes: 6 additions & 8 deletions pkg/operator/operator.go
Expand Up @@ -168,6 +168,7 @@ type Operator struct {
remoteWrite bool
userWorkloadEnabled bool
metricsServerEnabled bool
collectionProfilesEnabled bool

lastKnowInfrastructureConfig *InfrastructureConfig
lastKnowProxyConfig *ProxyConfig
Expand Down Expand Up @@ -244,6 +245,7 @@ func New(
remoteWrite: remoteWrite,
userWorkloadEnabled: false,
metricsServerEnabled: false,
collectionProfilesEnabled: false,
namespace: namespace,
namespaceUserWorkload: namespaceUserWorkload,
client: c,
Expand Down Expand Up @@ -435,6 +437,7 @@ func New(
return nil, err
}
o.metricsServerEnabled = featureGates.Enabled(configv1.FeatureGateMetricsServer)
o.collectionProfilesEnabled = featureGates.Enabled(configv1.FeatureGateMetricsCollectionProfiles)
case <-time.After(1 * time.Minute):
return nil, fmt.Errorf("timed out waiting for FeatureGate detection")
}
Expand Down Expand Up @@ -924,7 +927,7 @@ func (o *Operator) loadUserWorkloadConfig(ctx context.Context) (*manifests.UserW
return uwc, nil
}

func (o *Operator) loadConfig(key string, tp bool) (*manifests.Config, error) {
func (o *Operator) loadConfig(key string) (*manifests.Config, error) {
obj, found, err := o.cmapInf.GetStore().GetByKey(key)
if err != nil {
return nil, fmt.Errorf("an error occurred when retrieving the Cluster Monitoring ConfigMap: %w", err)
Expand All @@ -942,7 +945,7 @@ func (o *Operator) loadConfig(key string, tp bool) (*manifests.Config, error) {
return nil, errors.New("the Cluster Monitoring ConfigMap doesn't contain a 'config.yaml' key")
}

cParsed, err := manifests.NewConfigFromString(configContent, tp)
cParsed, err := manifests.NewConfigFromString(configContent, o.collectionProfilesEnabled)
if err != nil {
return nil, fmt.Errorf("the Cluster Monitoring ConfigMap could not be parsed: %w", err)
}
Expand All @@ -951,12 +954,7 @@ func (o *Operator) loadConfig(key string, tp bool) (*manifests.Config, error) {
}

func (o *Operator) Config(ctx context.Context, key string) (*manifests.Config, error) {
tp, err := o.client.TechPreviewEnabled(ctx)
if err != nil {
return nil, err
}

c, err := o.loadConfig(key, tp)
c, err := o.loadConfig(key)
if err != nil {
return nil, err
}
Expand Down
1 change: 0 additions & 1 deletion vendor/github.com/openshift/api/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

0 comments on commit 965d371

Please sign in to comment.