Skip to content

Commit

Permalink
ACM-14962: init MCOA metrics (#1659)
Browse files Browse the repository at this point in the history
* update mco api

Signed-off-by: Thibault Mange <[email protected]>

* add supported and default configs

Signed-off-by: Thibault Mange <[email protected]>

* add customized variables

Signed-off-by: Thibault Mange <[email protected]>

* fix test

Signed-off-by: Thibault Mange <[email protected]>

* add metrics in mcoa enabled

Signed-off-by: Thibault Mange <[email protected]>

* fix crd name

Signed-off-by: Thibault Mange <[email protected]>

* update mcoa role

Signed-off-by: Thibault Mange <[email protected]>

* fix role

Signed-off-by: Thibault Mange <[email protected]>

* fix role typo

Signed-off-by: Thibault Mange <[email protected]>

* add write perms for cfg resources

Signed-off-by: Thibault Mange <[email protected]>

* fix tests

Signed-off-by: Thibault Mange <[email protected]>

* remove default configs

Signed-off-by: Thibault Mange <[email protected]>

* dynamic supported configs

Signed-off-by: Thibault Mange <[email protected]>

* fix

Signed-off-by: Thibault Mange <[email protected]>

* fix

Signed-off-by: Thibault Mange <[email protected]>

* fix

Signed-off-by: Thibault Mange <[email protected]>

* fix supported configs

Signed-off-by: Thibault Mange <[email protected]>

* revert dynamic supportedConfigs

Signed-off-by: Thibault Mange <[email protected]>

* fix

Signed-off-by: Thibault Mange <[email protected]>

* only enabled configs

Signed-off-by: Thibault Mange <[email protected]>

* change metricsHub var

Signed-off-by: Thibault Mange <[email protected]>

* change MetricsHubHostname add logic

Signed-off-by: Thibault Mange <[email protected]>

* fix MetricsHubHostname generation

Signed-off-by: Thibault Mange <[email protected]>

* simplify mcoa test

Signed-off-by: Thibault Mange <[email protected]>

---------

Signed-off-by: Thibault Mange <[email protected]>
  • Loading branch information
thibaultmg authored Jan 14, 2025
1 parent fb915c4 commit 09d061c
Show file tree
Hide file tree
Showing 11 changed files with 553 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ type PlatformLogsCollectionSpec struct {
Enabled bool `json:"enabled,omitempty"`
}

// PlatformMetricsCollectionSpec defines the spec for the addon to collect and forward metrics
// from fleet managed clusters.
type PlatformMetricsCollectionSpec struct {
// Enabled defines a flag to enable/disable the platform metrics collection.
//
// +optional
// +kubebuilder:validation:Optional
Enabled bool `json:"enabled,omitempty"`
}

// PlatformLogsSpec defines the spec for the addon to collect, forward and store logs
// from fleet managed clusters.
type PlatformLogsSpec struct {
Expand All @@ -79,6 +89,17 @@ type PlatformLogsSpec struct {
Collection PlatformLogsCollectionSpec `json:"collection,omitempty"`
}

// PlatformMetricsSpec defines the spec for the addon to collect, forward and store metrics
// from fleet managed clusters.
type PlatformMetricsSpec struct {
// Collection defines the spec for the addon to collect and forward metrics
// from fleet managed clusters.
//
// +optional
// +kubebuilder:validation:Optional
Collection PlatformMetricsCollectionSpec `json:"collection,omitempty"`
}

// PlatformCapabilitiesSpec defines the observability capabilities managed by the addon
// for platform components.
type PlatformCapabilitiesSpec struct {
Expand All @@ -88,6 +109,13 @@ type PlatformCapabilitiesSpec struct {
// +optional
// +kubebuilder:validation:Optional
Logs PlatformLogsSpec `json:"logs,omitempty"`

// Metrics defines the configuration spec for collecting and storing metrics from
// platform components running on fleet managed clusters.
//
// +optional
// +kubebuilder:validation:Optional
Metrics PlatformMetricsSpec `json:"metrics,omitempty"`
}

// ClusterLogForwarderSpec defines the spec for the addon to collect and forward logs
Expand All @@ -110,6 +138,16 @@ type UserWorkloadLogsCollectionSpec struct {
ClusterLogForwarder ClusterLogForwarderSpec `json:"clusterLogForwarder,omitempty"`
}

// UserWorkloadLogsSpec defines the spec for the addon to collect,forward and store logs
// from user workloads hosted on fleet managed clusters.
type UserWorkloadMetricsCollectionSpec struct {
// Enabled defines a flag to enable/disable the platform metrics collection.
//
// +optional
// +kubebuilder:validation:Optional
Enabled bool `json:"enabled,omitempty"`
}

// UserWorkloadLogsSpec defines the spec for the addon to collect,forward and store logs
// from user workloads hosted on fleet managed clusters.
type UserWorkloadLogsSpec struct {
Expand All @@ -121,6 +159,17 @@ type UserWorkloadLogsSpec struct {
Collection UserWorkloadLogsCollectionSpec `json:"collection,omitempty"`
}

// UserWorkloadMetricsSpec defines the spec for the addon to collect, forward and store metrics
// from user workloads hosted on fleet managed clusters.
type UserWorkloadMetricsSpec struct {
// Collection defines the spec for the addon to collect and forward metrics
// from user workloads hosted on fleet managed clusters.
//
// +optional
// +kubebuilder:validation:Optional
Collection UserWorkloadMetricsCollectionSpec `json:"collection,omitempty"`
}

// OpenTelemetryCollectorSpec defines the spec for the addon to collect and forward observability signals
// using the OpenTelemetryCollector custom resource.
type OpenTelemetryCollectorSpec struct {
Expand Down Expand Up @@ -176,6 +225,14 @@ type UserWorkloadCapabilitiesSpec struct {
// +optional
// +kubebuilder:validation:Optional
Logs UserWorkloadLogsSpec `json:"logs,omitempty"`

// Metrics defines the spec for the addon to collect, forward and store metrics
// from user workloads hosted on fleet managed clusters.
//
// +optional
// +kubebuilder:validation:Optional
Metrics UserWorkloadMetricsSpec `json:"metrics,omitempty"`

// Traces defines the spec for the addon to collect, forward and store traces
// from user workloads hosted on fleet managed clusters.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ metadata:
}
]
capabilities: Basic Install
createdAt: "2024-09-23T12:07:01Z"
createdAt: "2024-11-06T16:52:14Z"
operators.operatorframework.io/builder: operator-sdk-v1.34.2
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
name: multicluster-observability-operator.v0.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10036,6 +10036,22 @@ spec:
type: boolean
type: object
type: object
metrics:
description: |-
Metrics defines the configuration spec for collecting and storing metrics from
platform components running on fleet managed clusters.
properties:
collection:
description: |-
Collection defines the spec for the addon to collect and forward metrics
from fleet managed clusters.
properties:
enabled:
description: Enabled defines a flag to enable/disable
the platform metrics collection.
type: boolean
type: object
type: object
type: object
userWorkloads:
description: |-
Expand Down Expand Up @@ -10066,6 +10082,22 @@ spec:
type: object
type: object
type: object
metrics:
description: |-
Metrics defines the spec for the addon to collect, forward and store metrics
from user workloads hosted on fleet managed clusters.
properties:
collection:
description: |-
Collection defines the spec for the addon to collect and forward metrics
from user workloads hosted on fleet managed clusters.
properties:
enabled:
description: Enabled defines a flag to enable/disable
the platform metrics collection.
type: boolean
type: object
type: object
traces:
description: |-
Traces defines the spec for the addon to collect, forward and store traces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10020,6 +10020,22 @@ spec:
type: boolean
type: object
type: object
metrics:
description: |-
Metrics defines the configuration spec for collecting and storing metrics from
platform components running on fleet managed clusters.
properties:
collection:
description: |-
Collection defines the spec for the addon to collect and forward metrics
from fleet managed clusters.
properties:
enabled:
description: Enabled defines a flag to enable/disable
the platform metrics collection.
type: boolean
type: object
type: object
type: object
userWorkloads:
description: |-
Expand Down Expand Up @@ -10050,6 +10066,22 @@ spec:
type: object
type: object
type: object
metrics:
description: |-
Metrics defines the spec for the addon to collect, forward and store metrics
from user workloads hosted on fleet managed clusters.
properties:
collection:
description: |-
Collection defines the spec for the addon to collect and forward metrics
from user workloads hosted on fleet managed clusters.
properties:
enabled:
description: Enabled defines a flag to enable/disable
the platform metrics collection.
type: boolean
type: object
type: object
traces:
description: |-
Traces defines the spec for the addon to collect, forward and store traces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
placementctrl "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/controllers/placementrule"
certctrl "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/certificates"
"github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/config"
mcoconfig "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/config"
"github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/rendering"
smctrl "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/servicemonitor"
"github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/util"
Expand Down Expand Up @@ -266,10 +267,16 @@ func (r *MultiClusterObservabilityReconciler) Reconcile(ctx context.Context, req
}
disableMCOACMAORender := !apierrors.IsNotFound(err)

obsAPIURL, err := mcoconfig.GetObsAPIExternalURL(ctx, r.Client, mcoconfig.GetDefaultNamespace())
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to get the Observatorium API URL: %w", err)
}

// Build render options
rendererOptions := &rendering.RendererOptions{
MCOAOptions: rendering.MCOARendererOptions{
DisableCMAORender: disableMCOACMAORender,
DisableCMAORender: disableMCOACMAORender,
MetricsHubHostname: obsAPIURL.Host,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,16 @@ spec:
# Describes the default Instrumentation type applied to all managed clusters.
- group: opentelemetry.io
resource: instrumentations
# Metrics forwarding configuration types.
- group: monitoring.coreos.com
resource: prometheusagents
- group: monitoring.coreos.com
resource: scrapeconfigs
- group: monitoring.coreos.com
resource: prometheusrules
installStrategy:
type: Placements
placements:
- name: global
namespace: open-cluster-management-global-set
configs:
- group: observability.openshift.io
resource: clusterlogforwarders
name: instance
namespace: open-cluster-management-observability
- group: opentelemetry.io
resource: opentelemetrycollectors
name: instance
namespace: open-cluster-management-observability
- group: opentelemetry.io
resource: instrumentations
name: instance
namespace: open-cluster-management-observability
configs: []
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@
- apiGroups: ["opentelemetry.io"]
resources: ["opentelemetrycollectors", "instrumentations"]
verbs: ["get", "list", "watch"]
# Role for addon to perform prometheus specific actions
- apiGroups: ["monitoring.coreos.com"]
resources: ["prometheusagents", "scrapeconfigs", "prometheusrules"]
verbs: ["get", "list", "watch", "create", "update", "delete"]
2 changes: 2 additions & 0 deletions operators/multiclusterobservability/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,15 @@ const (
ClusterLogForwarderCRDName = "clusterlogforwarders.observability.openshift.io"
OpenTelemetryCollectorCRDName = "opentelemetrycollectors.opentelemetry.io"
InstrumentationCRDName = "instrumentations.opentelemetry.io"
PrometheusAgentCRDName = "prometheusagents.monitoring.coreos.com"
)

var (
mcoaSupportedCRDs = map[string]string{
ClusterLogForwarderCRDName: "v1",
OpenTelemetryCollectorCRDName: "v1beta1",
InstrumentationCRDName: "v1alpha1",
PrometheusAgentCRDName: "v1alpha1",
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ func TestGetMCOASupportedCRDNames(t *testing.T) {
"clusterlogforwarders.observability.openshift.io",
"opentelemetrycollectors.opentelemetry.io",
"instrumentations.opentelemetry.io",
"prometheusagents.monitoring.coreos.com",
}

result := GetMCOASupportedCRDNames()
Expand Down
Loading

0 comments on commit 09d061c

Please sign in to comment.