Skip to content

Commit 590c23c

Browse files
committed
use old mock
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
1 parent 0033be8 commit 590c23c

21 files changed

+266
-4991
lines changed

pkg/hook/task_metadata/task_metadata_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
bctx "github.com/flant/shell-operator/pkg/hook/binding_context"
1212
htypes "github.com/flant/shell-operator/pkg/hook/types"
13-
"github.com/flant/shell-operator/pkg/mock"
13+
"github.com/flant/shell-operator/pkg/metric"
1414
"github.com/flant/shell-operator/pkg/task"
1515
"github.com/flant/shell-operator/pkg/task/queue"
1616
)
@@ -46,7 +46,7 @@ func Test_HookMetadata_QueueDump_Task_Description(t *testing.T) {
4646
"hook": "hook1.sh",
4747
}
4848

49-
metricStorage := mock.NewMetricStorageMock(t)
49+
metricStorage := metric.NewStorageMock(t)
5050
metricStorage.HistogramObserveMock.Set(func(metric string, value float64, labels map[string]string, buckets []float64) {
5151
assert.Equal(t, metric, "{PREFIX}tasks_queue_action_duration_seconds")
5252
assert.NotZero(t, value)

pkg/kube_events_manager/error_handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ import (
99
apierrors "k8s.io/apimachinery/pkg/api/errors"
1010
"k8s.io/client-go/tools/cache"
1111

12-
"github.com/flant/shell-operator/pkg"
12+
"github.com/flant/shell-operator/pkg/metric"
1313
utils "github.com/flant/shell-operator/pkg/utils/labels"
1414
)
1515

1616
type WatchErrorHandler struct {
1717
description string
1818
kind string
19-
metricStorage pkg.MetricStorage
19+
metricStorage metric.Storage
2020

2121
logger *log.Logger
2222
}
2323

24-
func newWatchErrorHandler(description string, kind string, logLabels map[string]string, metricStorage pkg.MetricStorage, logger *log.Logger) *WatchErrorHandler {
24+
func newWatchErrorHandler(description string, kind string, logLabels map[string]string, metricStorage metric.Storage, logger *log.Logger) *WatchErrorHandler {
2525
return &WatchErrorHandler{
2626
description: description,
2727
kind: kind,

pkg/kube_events_manager/kube_events_manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
"github.com/deckhouse/deckhouse/pkg/log"
1111

1212
klient "github.com/flant/kube-client/client"
13-
"github.com/flant/shell-operator/pkg"
1413
kemtypes "github.com/flant/shell-operator/pkg/kube_events_manager/types"
14+
"github.com/flant/shell-operator/pkg/metric"
1515
)
1616

1717
type KubeEventsManager interface {
18-
WithMetricStorage(mstor pkg.MetricStorage)
18+
WithMetricStorage(mstor metric.Storage)
1919
AddMonitor(monitorConfig *MonitorConfig) error
2020
HasMonitor(monitorID string) bool
2121
GetMonitor(monitorID string) Monitor
@@ -35,7 +35,7 @@ type kubeEventsManager struct {
3535

3636
ctx context.Context
3737
cancel context.CancelFunc
38-
metricStorage pkg.MetricStorage
38+
metricStorage metric.Storage
3939

4040
m sync.RWMutex
4141
Monitors map[string]Monitor
@@ -61,7 +61,7 @@ func NewKubeEventsManager(ctx context.Context, client *klient.Client, logger *lo
6161
return em
6262
}
6363

64-
func (mgr *kubeEventsManager) WithMetricStorage(mstor pkg.MetricStorage) {
64+
func (mgr *kubeEventsManager) WithMetricStorage(mstor metric.Storage) {
6565
mgr.metricStorage = mstor
6666
}
6767

pkg/kube_events_manager/monitor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/deckhouse/deckhouse/pkg/log"
1010

1111
klient "github.com/flant/kube-client/client"
12-
"github.com/flant/shell-operator/pkg"
1312
kemtypes "github.com/flant/shell-operator/pkg/kube_events_manager/types"
13+
"github.com/flant/shell-operator/pkg/metric"
1414
utils "github.com/flant/shell-operator/pkg/utils/labels"
1515
)
1616

@@ -46,12 +46,12 @@ type monitor struct {
4646

4747
ctx context.Context
4848
cancel context.CancelFunc
49-
metricStorage pkg.MetricStorage
49+
metricStorage metric.Storage
5050

5151
logger *log.Logger
5252
}
5353

54-
func NewMonitor(ctx context.Context, client *klient.Client, mstor pkg.MetricStorage, config *MonitorConfig, eventCb func(kemtypes.KubeEvent), logger *log.Logger) *monitor {
54+
func NewMonitor(ctx context.Context, client *klient.Client, mstor metric.Storage, config *MonitorConfig, eventCb func(kemtypes.KubeEvent), logger *log.Logger) *monitor {
5555
cctx, cancel := context.WithCancel(ctx)
5656

5757
return &monitor{

pkg/kube_events_manager/monitor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/flant/kube-client/fake"
1515
"github.com/flant/kube-client/manifest"
1616
kemtypes "github.com/flant/shell-operator/pkg/kube_events_manager/types"
17-
"github.com/flant/shell-operator/pkg/mock"
17+
"github.com/flant/shell-operator/pkg/metric"
1818
)
1919

2020
func Test_Monitor_should_handle_dynamic_ns_events(t *testing.T) {
@@ -39,7 +39,7 @@ func Test_Monitor_should_handle_dynamic_ns_events(t *testing.T) {
3939
}
4040
objsFromEvents := make([]string, 0)
4141

42-
metricStorage := mock.NewMetricStorageMock(t)
42+
metricStorage := metric.NewStorageMock(t)
4343
metricStorage.HistogramObserveMock.Set(func(metric string, value float64, labels map[string]string, buckets []float64) {
4444
metrics := []string{
4545
"{PREFIX}kube_event_duration_seconds",

pkg/kube_events_manager/resource_informer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616
"k8s.io/client-go/tools/cache"
1717

1818
klient "github.com/flant/kube-client/client"
19-
"github.com/flant/shell-operator/pkg"
2019
"github.com/flant/shell-operator/pkg/app"
2120
"github.com/flant/shell-operator/pkg/filter/jq"
2221
kemtypes "github.com/flant/shell-operator/pkg/kube_events_manager/types"
22+
"github.com/flant/shell-operator/pkg/metric"
2323
"github.com/flant/shell-operator/pkg/utils/measure"
2424
)
2525

@@ -58,7 +58,7 @@ type resourceInformer struct {
5858
ctx context.Context
5959
cancel context.CancelFunc
6060

61-
metricStorage pkg.MetricStorage
61+
metricStorage metric.Storage
6262

6363
// a flag to stop handle events after Stop()
6464
stopped bool
@@ -69,7 +69,7 @@ type resourceInformer struct {
6969
// resourceInformer should implement ResourceInformer
7070
type resourceInformerConfig struct {
7171
client *klient.Client
72-
mstor pkg.MetricStorage
72+
mstor metric.Storage
7373
eventCb func(kemtypes.KubeEvent)
7474
monitor *MonitorConfig
7575

pkg/metric/storage.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
package metric
22

33
import (
4+
"net/http"
5+
46
"github.com/prometheus/client_golang/prometheus"
57

68
"github.com/flant/shell-operator/pkg/metric_storage/operation"
79
)
810

911
type Storage interface {
10-
GaugeSet(metric string, value float64, labels map[string]string)
11-
GaugeAdd(metric string, value float64, labels map[string]string)
12-
Gauge(metric string, labels map[string]string) *prometheus.GaugeVec
13-
RegisterGauge(metric string, labels map[string]string) *prometheus.GaugeVec
12+
ApplyOperation(op operation.MetricOperation, commonLabels map[string]string)
1413

15-
CounterAdd(metric string, value float64, labels map[string]string)
1614
Counter(metric string, labels map[string]string) *prometheus.CounterVec
17-
RegisterCounter(metric string, labels map[string]string) *prometheus.CounterVec
15+
CounterAdd(metric string, value float64, labels map[string]string)
16+
17+
Gauge(metric string, labels map[string]string) *prometheus.GaugeVec
18+
GaugeAdd(metric string, value float64, labels map[string]string)
19+
GaugeSet(metric string, value float64, labels map[string]string)
20+
21+
Grouped() GroupedStorage
22+
23+
Handler() http.Handler
1824

19-
HistogramObserve(metric string, value float64, labels map[string]string, buckets []float64)
2025
Histogram(metric string, labels map[string]string, buckets []float64) *prometheus.HistogramVec
26+
HistogramObserve(metric string, value float64, labels map[string]string, buckets []float64)
27+
28+
RegisterCounter(metric string, labels map[string]string) *prometheus.CounterVec
29+
RegisterGauge(metric string, labels map[string]string) *prometheus.GaugeVec
2130
RegisterHistogram(metric string, labels map[string]string, buckets []float64) *prometheus.HistogramVec
2231

2332
SendBatch(ops []operation.MetricOperation, labels map[string]string) error
24-
ApplyOperation(op operation.MetricOperation, commonLabels map[string]string)
25-
26-
Grouped() GroupedStorage
2733
}
2834

2935
type GroupedStorage interface {

0 commit comments

Comments
 (0)