Skip to content
Merged
9 changes: 8 additions & 1 deletion cmd/addon-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import (
addon_operator "github.com/flant/addon-operator/pkg/addon-operator"
"github.com/flant/addon-operator/pkg/app"
"github.com/flant/addon-operator/pkg/kube_config_manager/backend/configmap"
"github.com/flant/addon-operator/pkg/metrics"
"github.com/flant/addon-operator/pkg/utils/stdliblogtolog"
"github.com/flant/kube-client/klogtolog"
shapp "github.com/flant/shell-operator/pkg/app"
"github.com/flant/shell-operator/pkg/debug"
shmetrics "github.com/flant/shell-operator/pkg/metrics"
utils_signal "github.com/flant/shell-operator/pkg/utils/signal"
)

Expand Down Expand Up @@ -71,7 +73,12 @@ func start(logger *log.Logger) func(_ *kingpin.ParseContext) error {

ctx := context.Background()

operator := addon_operator.NewAddonOperator(ctx, addon_operator.WithLogger(logger.Named("addon-operator")))
// Initialize metric names with the configured prefix
shmetrics.InitMetrics(shapp.PrometheusMetricsPrefix)
// Initialize addon-operator specific metrics
metrics.InitMetrics(shapp.PrometheusMetricsPrefix)

operator := addon_operator.NewAddonOperator(ctx, nil, nil, addon_operator.WithLogger(logger.Named("addon-operator")))

operator.StartAPIServer()

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ go 1.24.0
require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/deckhouse/deckhouse/pkg/log v0.1.0
github.com/deckhouse/deckhouse/pkg/metrics-storage v0.2.1
github.com/deckhouse/deckhouse/pkg/metrics-storage v0.3.0
github.com/deckhouse/module-sdk v0.5.0
github.com/dominikbraun/graph v0.23.0
github.com/ettle/strcase v0.2.0
github.com/flant/kube-client v1.5.0
github.com/flant/shell-operator v1.12.0
github.com/flant/shell-operator v1.12.1
github.com/go-chi/chi/v5 v5.2.2
github.com/go-openapi/loads v0.23.1
github.com/go-openapi/spec v0.22.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckhouse/deckhouse/pkg/log v0.1.0 h1:2aPfyiHHSIJlX4x7ysyPOaIb7CLmyY+hUf9uDb8TYd8=
github.com/deckhouse/deckhouse/pkg/log v0.1.0/go.mod h1:pbAxTSDcPmwyl3wwKDcEB3qdxHnRxqTV+J0K+sha8bw=
github.com/deckhouse/deckhouse/pkg/metrics-storage v0.2.1 h1:DhMHRzmaVNXASH+koIy9gK25GU/EaK+zC6sVpacqWRw=
github.com/deckhouse/deckhouse/pkg/metrics-storage v0.2.1/go.mod h1:Rz++SzCLkFW03WGgftnn91TimGU2shiKb5S/YuxcBuE=
github.com/deckhouse/deckhouse/pkg/metrics-storage v0.3.0 h1:xZvbKuexrSQGEw6CB4n3UC7XbOb9QNLbm8UhcGZ2R1I=
github.com/deckhouse/deckhouse/pkg/metrics-storage v0.3.0/go.mod h1:Rz++SzCLkFW03WGgftnn91TimGU2shiKb5S/YuxcBuE=
github.com/deckhouse/module-sdk v0.5.0 h1:b2GJUzMKQLr7oJVJy5lXHvyymNyvNiFXpBie7MwEWwE=
github.com/deckhouse/module-sdk v0.5.0/go.mod h1:+EbBnP8z+poIihgL4l1oxHng5ePqDUK44c39u7sEBss=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
Expand Down Expand Up @@ -155,8 +155,8 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/flant/kube-client v1.5.0 h1:6QZOZy3uk58Bh9YUn4CnhEz13og/cEGXB2uBZ1gWwtM=
github.com/flant/kube-client v1.5.0/go.mod h1:hpJZ0FnDKHW3r5q5SYQgBrTw9k94q4+dcnJ4uOGYBHc=
github.com/flant/shell-operator v1.12.0 h1:VAi6EEqG5aCKgPlE+XaXmpdG5dvGPUkrHSstAREvSiU=
github.com/flant/shell-operator v1.12.0/go.mod h1:MlEVeHh88sL5LCiMmLmtYJZSV7XL/WHIJBKJeNviExE=
github.com/flant/shell-operator v1.12.1 h1:ARrZaPiiQVjPjXombUt//doaHFCBlzGATgsUpQHT85o=
github.com/flant/shell-operator v1.12.1/go.mod h1:RFXNvfK/v18J5u4RMqfFSDFhwJvMNPv5OR3BpioyxI0=
github.com/flopp/go-findfont v0.1.0 h1:lPn0BymDUtJo+ZkV01VS3661HL6F4qFlkhcJN55u6mU=
github.com/flopp/go-findfont v0.1.0/go.mod h1:wKKxRDjD024Rh7VMwoU90i6ikQRCr+JTHB5n4Ejkqvw=
github.com/fluxcd/flagger v1.36.1 h1:X2PumtNwZz9YSGaOtZLFm2zAKLgHhFkbNv8beg7ifyc=
Expand Down
5 changes: 3 additions & 2 deletions pkg/addon-operator/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/flant/addon-operator/pkg/app"
"github.com/flant/addon-operator/pkg/kube_config_manager"
"github.com/flant/addon-operator/pkg/kube_config_manager/backend"
"github.com/flant/addon-operator/pkg/metrics"
"github.com/flant/addon-operator/pkg/module_manager"
taskservice "github.com/flant/addon-operator/pkg/task/service"
shapp "github.com/flant/shell-operator/pkg/app"
Expand Down Expand Up @@ -75,8 +76,8 @@ func (op *AddonOperator) Assemble(debugServer *debug.Server) error {
}

// Start background updaters for metrics
StartLiveTicksUpdater(op.engine.MetricStorage)
StartTasksQueueLengthUpdater(op.engine.MetricStorage, op.engine.TaskQueues)
metrics.StartLiveTicksUpdater(op.engine.MetricStorage)
metrics.StartTasksQueueLengthUpdater(op.engine.MetricStorage, op.engine.TaskQueues)

// Register debug HTTP endpoints to inspect internal state
op.engine.RegisterDebugQueueRoutes(debugServer)
Expand Down
5 changes: 3 additions & 2 deletions pkg/addon-operator/handler_module_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/flant/addon-operator/pkg/addon-operator/converge"
"github.com/flant/addon-operator/pkg/kube_config_manager/config"
"github.com/flant/addon-operator/pkg/metrics"
dynamic_extender "github.com/flant/addon-operator/pkg/module_manager/scheduler/extenders/dynamically_enabled"
"github.com/flant/addon-operator/pkg/task"
"github.com/flant/addon-operator/pkg/utils"
Expand Down Expand Up @@ -196,13 +197,13 @@ func (op *AddonOperator) StartModuleManagerEventHandler() {
additionalDescription := fmt.Sprintf("%d absent module resources", len(HelmReleaseStatusEvent.Absent))
// helm reslease in unexpected state event
if HelmReleaseStatusEvent.UnexpectedStatus {
op.engine.MetricStorage.CounterAdd("{PREFIX}modules_helm_release_redeployed_total", 1.0, map[string]string{"module": HelmReleaseStatusEvent.ModuleName})
op.engine.MetricStorage.CounterAdd(metrics.ModulesHelmReleaseRedeployedTotal, 1.0, map[string]string{"module": HelmReleaseStatusEvent.ModuleName})
eventDescription = "HelmReleaseUnexpectedStatus"
additionalDescription = "unexpected helm release status"
} else {
// some resources are missing and metrics are provided
for _, manifest := range HelmReleaseStatusEvent.Absent {
op.engine.MetricStorage.CounterAdd("{PREFIX}modules_absent_resources_total", 1.0, map[string]string{"module": HelmReleaseStatusEvent.ModuleName, "resource": fmt.Sprintf("%s/%s/%s", manifest.Namespace(""), manifest.Kind(), manifest.Name())})
op.engine.MetricStorage.CounterAdd(metrics.ModulesAbsentResourcesTotal, 1.0, map[string]string{"module": HelmReleaseStatusEvent.ModuleName, "resource": fmt.Sprintf("%s/%s/%s", manifest.Namespace(""), manifest.Kind(), manifest.Name())})
}
}

Expand Down
160 changes: 0 additions & 160 deletions pkg/addon-operator/metrics.go

This file was deleted.

27 changes: 24 additions & 3 deletions pkg/addon-operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/flant/addon-operator/pkg/helm_resources_manager"
"github.com/flant/addon-operator/pkg/kube_config_manager"
"github.com/flant/addon-operator/pkg/kube_config_manager/config"
"github.com/flant/addon-operator/pkg/metrics"
"github.com/flant/addon-operator/pkg/module_manager"
gohook "github.com/flant/addon-operator/pkg/module_manager/go_hook"
"github.com/flant/addon-operator/pkg/module_manager/models/hooks/kind"
Expand Down Expand Up @@ -117,7 +118,7 @@ func WithOnConvergeFinish(callback func()) Option {
}
}

func NewAddonOperator(ctx context.Context, opts ...Option) *AddonOperator {
func NewAddonOperator(ctx context.Context, metricsStorage, hookMetricStorage metricsstorage.Storage, opts ...Option) *AddonOperator {
cctx, cancel := context.WithCancel(ctx)

ao := &AddonOperator{
Expand All @@ -136,7 +137,24 @@ func NewAddonOperator(ctx context.Context, opts ...Option) *AddonOperator {
ao.Logger = log.NewLogger().Named("addon-operator")
}

so := shell_operator.NewShellOperator(cctx, shell_operator.WithLogger(ao.Logger.Named("shell-operator")))
if metricsStorage == nil {
ao.Logger.Warn("MetricStorage is not provided, creating a new one")

metricsStorage = metricsstorage.NewMetricStorage(
metricsstorage.WithLogger(ao.Logger.Named("metric-storage")),
)
}

if hookMetricStorage == nil {
ao.Logger.Warn("HookMetricStorage is not provided, creating a new one")

hookMetricStorage = metricsstorage.NewMetricStorage(
metricsstorage.WithNewRegistry(),
metricsstorage.WithLogger(ao.Logger.Named("hook-metric-storage")),
)
}

so := shell_operator.NewShellOperator(cctx, metricsStorage, hookMetricStorage, shell_operator.WithLogger(ao.Logger.Named("shell-operator")))

// initialize logging before Assemble
rc := runtimeConfig.NewConfig(ao.Logger)
Expand All @@ -155,7 +173,10 @@ func NewAddonOperator(ctx context.Context, opts ...Option) *AddonOperator {
panic(err)
}

registerHookMetrics(so.HookMetricStorage)
// Register addon-operator specific metrics
if err := metrics.RegisterHookMetrics(so.HookMetricStorage); err != nil {
panic(fmt.Errorf("register hook metrics: %w", err))
}

labelSelector, err := metav1.ParseToLabelSelector(app.ExtraLabels)
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions pkg/addon-operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func assembleTestAddonOperator(t *testing.T, configPath string) (*AddonOperator,
prometheus.DefaultRegisterer = registry

// Assemble AddonOperator.
op := NewAddonOperator(context.Background(), WithLogger(log.NewNop()))
op := NewAddonOperator(context.Background(), nil, nil, WithLogger(log.NewNop()))
op.engine.KubeClient = kubeClient
// Mock helm client for ModuleManager
result.helmClient = &mockhelm.Client{}
Expand Down Expand Up @@ -139,12 +139,10 @@ func assembleTestAddonOperator(t *testing.T, configPath string) (*AddonOperator,
Helm: op.Helm,
HelmResourcesManager: op.HelmResourcesManager,
MetricStorage: metricstorage.NewMetricStorage(
metricstorage.WithPrefix("addon_operator_"),
metricstorage.WithLogger(log.NewNop()),
metricstorage.WithNewRegistry(),
),
HookMetricStorage: metricstorage.NewMetricStorage(
metricstorage.WithPrefix("addon_operator_"),
metricstorage.WithLogger(log.NewNop()),
metricstorage.WithNewRegistry(),
),
Expand Down
Loading
Loading