Skip to content

Commit

Permalink
change metricsHub var
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Mange <[email protected]>
  • Loading branch information
thibaultmg committed Dec 2, 2024
1 parent 57e2104 commit f84c657
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
cerr "errors"
"fmt"
"net/url"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -52,6 +53,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 +268,19 @@ func (r *MultiClusterObservabilityReconciler) Reconcile(ctx context.Context, req
}
disableMCOACMAORender := !apierrors.IsNotFound(err)

obsAPIURL := &url.URL{}
if !disableMCOACMAORender {
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 @@ -5,7 +5,6 @@
package rendering

import (
"context"
"fmt"

prometheusv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
Expand Down Expand Up @@ -34,11 +33,12 @@ const (
nameUserWorkloadTracesCollection = "userWorkloadTracesCollection"
nameUserWorkloadInstrumentation = "userWorkloadInstrumentation"
nameUserWorkloadMetricsCollection = "userWorkloadMetricsCollection"
nameSignalsHubEndpoint = "signalsHubEndpoint"
nameMetricsHubHostname = "metricsHubHostname"
)

type MCOARendererOptions struct {
DisableCMAORender bool
DisableCMAORender bool
MetricsHubHostname string
}

func (r *MCORenderer) newMCOARenderer() {
Expand Down Expand Up @@ -341,12 +341,11 @@ func (r *MCORenderer) renderAddonDeploymentConfig(
}
}

if (cs.Platform != nil && cs.Platform.Metrics.Collection.Enabled) || (cs.UserWorkloads != nil && cs.UserWorkloads.Metrics.Collection.Enabled) {
obsAPIURL, err := mcoconfig.GetObsAPIExternalURL(context.TODO(), r.kubeClient, namespace)
if err != nil {
return nil, fmt.Errorf("failed to get the Observatorium API URL: %w", err)
if r.rendererOptions != nil {
metricsHubHostname := r.rendererOptions.MCOAOptions.MetricsHubHostname
if metricsHubHostname != "" {
appendCustomVar(aodc, nameMetricsHubHostname, metricsHubHostname)
}
appendCustomVar(aodc, nameSignalsHubEndpoint, obsAPIURL.Host)
}

u.Object, err = runtime.DefaultUnstructuredConverter.ToUnstructured(aodc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ func TestRenderAddonDeploymentConfig(t *testing.T) {
},
},
},
AdvancedConfig: &mcov1beta2.AdvancedConfig{
CustomObservabilityHubURL: "https://observability-hub",
},
},
}

Expand All @@ -181,7 +178,11 @@ func TestRenderAddonDeploymentConfig(t *testing.T) {
WithObjects(mco).
Build()

renderer := &MCORenderer{cr: mco, kubeClient: fakeClient}
renderer := &MCORenderer{cr: mco, kubeClient: fakeClient, rendererOptions: &RendererOptions{
MCOAOptions: MCOARendererOptions{
MetricsHubHostname: "observability-hub",
},
}}

uobj, err := renderer.renderAddonDeploymentConfig(aodc, "test", map[string]string{"key": "value"})
assert.NoError(t, err)
Expand All @@ -203,7 +204,7 @@ func TestRenderAddonDeploymentConfig(t *testing.T) {
assert.Contains(t, got.Spec.CustomizedVariables, addonv1alpha1.CustomizedVariable{Name: nameUserWorkloadInstrumentation, Value: instrV1alpha1})
assert.Contains(t, got.Spec.CustomizedVariables, addonv1alpha1.CustomizedVariable{Name: namePlatformMetricsCollection, Value: promV1alpha1})
assert.Contains(t, got.Spec.CustomizedVariables, addonv1alpha1.CustomizedVariable{Name: nameUserWorkloadMetricsCollection, Value: promV1alpha1})
assert.Contains(t, got.Spec.CustomizedVariables, addonv1alpha1.CustomizedVariable{Name: nameSignalsHubEndpoint, Value: "observability-hub"})
assert.Contains(t, got.Spec.CustomizedVariables, addonv1alpha1.CustomizedVariable{Name: nameMetricsHubHostname, Value: "observability-hub"})
}

func TestMCORenderer_RenderClusterManagementAddOn(t *testing.T) {
Expand Down

0 comments on commit f84c657

Please sign in to comment.