Skip to content

Commit a03b472

Browse files
author
Pavel Okhlopkov
committed
revert
Signed-off-by: Pavel Okhlopkov <[email protected]>
1 parent 8176ef3 commit a03b472

File tree

20 files changed

+1135
-492
lines changed

20 files changed

+1135
-492
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/dominikbraun/graph v0.23.0
1010
github.com/ettle/strcase v0.2.0
1111
github.com/flant/kube-client v1.2.2
12-
github.com/flant/shell-operator v1.6.2-0.20250314122559-5b79f68c168f
12+
github.com/flant/shell-operator v1.6.2-0.20250319124152-802f50c63897
1313
github.com/go-chi/chi/v5 v5.2.1
1414
github.com/go-openapi/loads v0.19.5
1515
github.com/go-openapi/spec v0.19.8

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ github.com/flant/shell-operator v1.6.2-0.20250314112408-f5efca1a2e68 h1:nZi/liDD
150150
github.com/flant/shell-operator v1.6.2-0.20250314112408-f5efca1a2e68/go.mod h1:u+xooEDFHvkxfpmQie7rMnaFedH8dkGoKaL2V3ZqK54=
151151
github.com/flant/shell-operator v1.6.2-0.20250314122559-5b79f68c168f h1:NjgQw6Dhal2P41reOpX07hm5k/4ZKn/cel7k+dzIUaY=
152152
github.com/flant/shell-operator v1.6.2-0.20250314122559-5b79f68c168f/go.mod h1:u+xooEDFHvkxfpmQie7rMnaFedH8dkGoKaL2V3ZqK54=
153+
github.com/flant/shell-operator v1.6.2-0.20250318085700-329c0ed37b49 h1:DsCV38IrpQb5WYxc1UOKNC1I8lp0K37xQvb5BRdCvOY=
154+
github.com/flant/shell-operator v1.6.2-0.20250318085700-329c0ed37b49/go.mod h1:u+xooEDFHvkxfpmQie7rMnaFedH8dkGoKaL2V3ZqK54=
155+
github.com/flant/shell-operator v1.6.2-0.20250319124152-802f50c63897 h1:jAxlC8UaI7cfTle0LbAkv8QO9UrkASIoC57MTll0sMg=
156+
github.com/flant/shell-operator v1.6.2-0.20250319124152-802f50c63897/go.mod h1:u+xooEDFHvkxfpmQie7rMnaFedH8dkGoKaL2V3ZqK54=
153157
github.com/flopp/go-findfont v0.1.0 h1:lPn0BymDUtJo+ZkV01VS3661HL6F4qFlkhcJN55u6mU=
154158
github.com/flopp/go-findfont v0.1.0/go.mod h1:wKKxRDjD024Rh7VMwoU90i6ikQRCr+JTHB5n4Ejkqvw=
155159
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=

pkg/addon-operator/bootstrap.go

+11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/flant/addon-operator/pkg/kube_config_manager"
1111
"github.com/flant/addon-operator/pkg/kube_config_manager/backend"
1212
"github.com/flant/addon-operator/pkg/module_manager"
13+
taskservice "github.com/flant/addon-operator/pkg/task/service"
1314
shapp "github.com/flant/shell-operator/pkg/app"
1415
"github.com/flant/shell-operator/pkg/debug"
1516
shell_operator "github.com/flant/shell-operator/pkg/shell-operator"
@@ -45,6 +46,16 @@ func (op *AddonOperator) bootstrap() error {
4546
return fmt.Errorf("assemble Debug server: %w", err)
4647
}
4748

49+
cfg := &taskservice.TaskHandlerServiceConfig{
50+
Engine: op.engine,
51+
Helm: op.Helm,
52+
HelmResourcesManager: op.HelmResourcesManager,
53+
ModuleManager: op.ModuleManager,
54+
MetricStorage: op.MetricStorage,
55+
}
56+
57+
op.TaskService = taskservice.NewTaskHandlerService(cfg, op.Logger)
58+
4859
return nil
4960
}
5061

pkg/addon-operator/converge/converge.go

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package converge
22

33
import (
4+
"fmt"
45
"sync"
56
"time"
67

@@ -55,8 +56,14 @@ func (cs *ConvergeState) SetFirstRunPhase(ph FirstRunPhaseType) {
5556

5657
const ConvergeEventProp = "converge.event"
5758

59+
var _ fmt.Stringer = (*ConvergeEvent)(nil)
60+
5861
type ConvergeEvent string
5962

63+
func (e ConvergeEvent) String() string {
64+
return string(e)
65+
}
66+
6067
const (
6168
// OperatorStartup is a first converge during startup.
6269
OperatorStartup ConvergeEvent = "OperatorStartup"

pkg/addon-operator/handler_manager_events.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/gofrs/uuid/v5"
77

8+
"github.com/flant/addon-operator/pkg"
89
"github.com/flant/addon-operator/pkg/module_manager/models/hooks"
910
"github.com/flant/addon-operator/pkg/module_manager/models/modules"
1011
"github.com/flant/addon-operator/pkg/task"
@@ -19,8 +20,8 @@ func (op *AddonOperator) RegisterManagerEventsHandlers() {
1920
// Register handler for schedule events
2021
op.engine.ManagerEventsHandler.WithScheduleEventHandler(func(crontab string) []sh_task.Task {
2122
logLabels := map[string]string{
22-
"event.id": uuid.Must(uuid.NewV4()).String(),
23-
"binding": string(htypes.Schedule),
23+
"event.id": uuid.Must(uuid.NewV4()).String(),
24+
pkg.LogKeyBinding: string(htypes.Schedule),
2425
}
2526
logEntry := utils.EnrichLoggerWithLabels(op.Logger, logLabels)
2627
logEntry.Debug("Create tasks for 'schedule' event",
@@ -37,8 +38,8 @@ func (op *AddonOperator) RegisterManagerEventsHandlers() {
3738
// Register handler for kubernetes events
3839
op.engine.ManagerEventsHandler.WithKubeEventHandler(func(kubeEvent types.KubeEvent) []sh_task.Task {
3940
logLabels := map[string]string{
40-
"event.id": uuid.Must(uuid.NewV4()).String(),
41-
"binding": string(htypes.OnKubernetesEvent),
41+
"event.id": uuid.Must(uuid.NewV4()).String(),
42+
pkg.LogKeyBinding: string(htypes.OnKubernetesEvent),
4243
}
4344
logEntry := utils.EnrichLoggerWithLabels(op.Logger, logLabels)
4445
logEntry.Debug("Create tasks for 'kubernetes' event",
@@ -69,9 +70,9 @@ func (op *AddonOperator) createGlobalHookTaskFactory(
6970
}
7071

7172
hookLabels := utils.MergeLabels(logLabels, map[string]string{
72-
"hook": globalHook.GetName(),
73-
"hook.type": "global",
74-
"queue": info.QueueName,
73+
pkg.LogKeyHook: globalHook.GetName(),
74+
"hook.type": "global",
75+
"queue": info.QueueName,
7576
})
7677

7778
if len(info.BindingContext) > 0 {
@@ -113,10 +114,10 @@ func (op *AddonOperator) createModuleHookTaskFactory(
113114
}
114115

115116
hookLabels := utils.MergeLabels(logLabels, map[string]string{
116-
"module": module.GetName(),
117-
"hook": moduleHook.GetName(),
118-
"hook.type": "module",
119-
"queue": info.QueueName,
117+
"module": module.GetName(),
118+
pkg.LogKeyHook: moduleHook.GetName(),
119+
"hook.type": "module",
120+
"queue": info.QueueName,
120121
})
121122

122123
if len(info.BindingContext) > 0 {

pkg/addon-operator/metrics.go

+23-22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package addon_operator
33
import (
44
"time"
55

6+
"github.com/flant/addon-operator/pkg"
67
"github.com/flant/shell-operator/pkg/metric"
78
"github.com/flant/shell-operator/pkg/task/queue"
89
)
@@ -36,19 +37,19 @@ func registerHookMetrics(metricStorage metric.Storage) {
3637
metricStorage.RegisterHistogram(
3738
"{PREFIX}module_run_seconds",
3839
map[string]string{
39-
"module": "",
40-
"activation": "",
40+
"module": "",
41+
pkg.MetricKeyActivation: "",
4142
},
4243
buckets_1msTo10s,
4344
)
4445
metricStorage.RegisterCounter("{PREFIX}module_run_errors_total", map[string]string{"module": ""})
4546

4647
moduleHookLabels := map[string]string{
47-
"module": "",
48-
"hook": "",
49-
"binding": "",
50-
"queue": "",
51-
"activation": "",
48+
"module": "",
49+
"hook": "",
50+
pkg.MetricKeyBinding: "",
51+
"queue": "",
52+
pkg.MetricKeyActivation: "",
5253
}
5354
metricStorage.RegisterHistogram(
5455
"{PREFIX}module_hook_run_seconds",
@@ -69,10 +70,10 @@ func registerHookMetrics(metricStorage metric.Storage) {
6970

7071
// global hook running
7172
globalHookLabels := map[string]string{
72-
"hook": "",
73-
"binding": "",
74-
"queue": "",
75-
"activation": "",
73+
"hook": "",
74+
pkg.MetricKeyBinding: "",
75+
"queue": "",
76+
pkg.MetricKeyActivation: "",
7677
}
7778
metricStorage.RegisterHistogram(
7879
"{PREFIX}global_hook_run_seconds",
@@ -92,23 +93,23 @@ func registerHookMetrics(metricStorage metric.Storage) {
9293
metricStorage.RegisterCounter("{PREFIX}global_hook_success_total", globalHookLabels)
9394

9495
// converge duration
95-
metricStorage.RegisterCounter("{PREFIX}convergence_seconds", map[string]string{"activation": ""})
96-
metricStorage.RegisterCounter("{PREFIX}convergence_total", map[string]string{"activation": ""})
96+
metricStorage.RegisterCounter("{PREFIX}convergence_seconds", map[string]string{pkg.MetricKeyActivation: ""})
97+
metricStorage.RegisterCounter("{PREFIX}convergence_total", map[string]string{pkg.MetricKeyActivation: ""})
9798

9899
// helm operations
99100
metricStorage.RegisterHistogram(
100101
"{PREFIX}module_helm_seconds",
101102
map[string]string{
102-
"module": "",
103-
"activation": "",
103+
"module": "",
104+
pkg.MetricKeyActivation: "",
104105
},
105106
buckets_1msTo10s)
106107
metricStorage.RegisterHistogram(
107108
"{PREFIX}helm_operation_seconds",
108109
map[string]string{
109-
"module": "",
110-
"activation": "",
111-
"operation": "",
110+
"module": "",
111+
pkg.MetricKeyActivation: "",
112+
"operation": "",
112113
},
113114
buckets_1msTo10s)
114115

@@ -117,10 +118,10 @@ func registerHookMetrics(metricStorage metric.Storage) {
117118
metricStorage.RegisterCounter(
118119
"{PREFIX}task_wait_in_queue_seconds_total",
119120
map[string]string{
120-
"module": "",
121-
"hook": "",
122-
"binding": "",
123-
"queue": "",
121+
"module": "",
122+
"hook": "",
123+
pkg.MetricKeyBinding: "",
124+
"queue": "",
124125
})
125126
}
126127

0 commit comments

Comments
 (0)