Skip to content

Commit

Permalink
add module_info metric
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Scherba <[email protected]>
  • Loading branch information
miklezzzz committed Oct 24, 2024
1 parent d65a21b commit e7dd27b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM --platform=${TARGETPLATFORM:-linux/amd64} flant/jq:b6be13d5-musl as libjq

# Go builder.
FROM --platform=${TARGETPLATFORM:-linux/amd64} golang:1.22-alpine3.18 AS builder
FROM --platform=${TARGETPLATFORM:-linux/amd64} golang:1.22.8-alpine3.19 AS builder

ARG appVersion=latest
RUN apk --no-cache add git ca-certificates gcc musl-dev libc-dev binutils-gold
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/dominikbraun/graph v0.23.0
github.com/ettle/strcase v0.2.0
github.com/flant/kube-client v1.2.0
github.com/flant/shell-operator v1.4.15
github.com/flant/shell-operator v0.0.0-20241024135129-957d65112c34
github.com/go-chi/chi/v5 v5.1.0
github.com/go-openapi/loads v0.19.5
github.com/go-openapi/spec v0.19.8
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ github.com/flant/kube-client v1.2.0 h1:cOjnZgwoJVm4scqsMGcgO6qctJ+Z6wRVTFqvyhoAO
github.com/flant/kube-client v1.2.0/go.mod h1:qjNvqCqnBqS+kc9Hj+wMBbkFzfdyGyiX4r4teE/0Pm8=
github.com/flant/libjq-go v1.6.3-0.20201126171326-c46a40ff22ee h1:evii83J+/6QGNvyf6tjQ/p27DPY9iftxIBb37ALJRTg=
github.com/flant/libjq-go v1.6.3-0.20201126171326-c46a40ff22ee/go.mod h1:f+REaGl/+pZR97rbTcwHEka/MAipoQQ2Mc0iQUj4ak0=
github.com/flant/shell-operator v1.4.15 h1:HO0QThA+E6/ncIHRFLkjl2EzfYBTeE/Bj6g2OMGm4XI=
github.com/flant/shell-operator v1.4.15/go.mod h1:yGdG7Pc95B4kA6/4Gl8EVrO5IVuLflTcGjaP3EsWHnk=
github.com/flant/shell-operator v0.0.0-20241024135129-957d65112c34 h1:FYB+NtXcUIxBzz8Y6dlisL6+JfusSt7z8BfRY/S3d1U=
github.com/flant/shell-operator v0.0.0-20241024135129-957d65112c34/go.mod h1:yGdG7Pc95B4kA6/4Gl8EVrO5IVuLflTcGjaP3EsWHnk=
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/foxcpp/go-mockdns v1.0.0 h1:7jBqxd3WDWwi/6WhDvacvH1XsN3rOLXyHM1uhvIx6FI=
Expand Down
3 changes: 2 additions & 1 deletion pkg/addon-operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/flant/addon-operator/pkg/task"
"github.com/flant/kube-client/fake"
. "github.com/flant/shell-operator/pkg/hook/types"
"github.com/flant/shell-operator/pkg/metric_storage"
sh_task "github.com/flant/shell-operator/pkg/task"
"github.com/flant/shell-operator/pkg/task/queue"
file_utils "github.com/flant/shell-operator/pkg/utils/file"
Expand Down Expand Up @@ -131,7 +132,7 @@ func assembleTestAddonOperator(t *testing.T, configPath string) (*AddonOperator,
ScheduleManager: op.engine.ScheduleManager,
Helm: op.Helm,
HelmResourcesManager: op.HelmResourcesManager,
MetricStorage: nil,
MetricStorage: metric_storage.NewMetricStorage(op.ctx, "addon_operator_", false),
HookMetricStorage: nil,
}
cfg := module_manager.ModuleManagerConfig{
Expand Down
19 changes: 19 additions & 0 deletions pkg/module_manager/module_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ import (
"github.com/flant/shell-operator/pkg/task/queue"
)

const (
moduleInfoMetricGroup = "mm_module_info"
moduleInfoMetricName = "{PREFIX}mm_module_info"
)

// ModulesState determines which modules should be enabled, disabled or reloaded.
type ModulesState struct {
// All enabled modules.
Expand Down Expand Up @@ -426,6 +431,18 @@ func (mm *ModuleManager) SetGlobalDiscoveryAPIVersions(apiVersions []string) {
}
}

// UpdateModulesMetrics updates modules' states metrics
func (mm *ModuleManager) UpdateModulesMetrics() {
mm.dependencies.MetricStorage.Grouped().ExpireGroupMetricByName(moduleInfoMetricGroup, moduleInfoMetricName)
for _, module := range mm.GetModuleNames() {
enabled := "false"
if mm.IsModuleEnabled(module) {
enabled = "true"
}
mm.dependencies.MetricStorage.Grouped().GaugeSet(moduleInfoMetricGroup, moduleInfoMetricName, 1, map[string]string{"name": module, "enabled": enabled})
}
}

// RefreshEnabledState gets current diff of the graph and forms ModuleState
// - mm.enabledModules
func (mm *ModuleManager) RefreshEnabledState(logLabels map[string]string) (*ModulesState, error) {
Expand All @@ -447,6 +464,8 @@ func (mm *ModuleManager) RefreshEnabledState(logLabels map[string]string) (*Modu
modulesToDisable []string
)

go mm.UpdateModulesMetrics()

for module, enabled := range modulesDiff {
if enabled {
modulesToEnable = append(modulesToEnable, module)
Expand Down

0 comments on commit e7dd27b

Please sign in to comment.