From 79f885a4138f21f023b0bc7d58c7e7f749fc1c4c Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Wed, 8 Nov 2023 17:50:14 +0100 Subject: [PATCH] Add tests for the collector (#6) --- go.mod | 6 ++ go.sum | 19 ++++ internal/alerts_collector/alerts_collector.go | 25 ++--- .../alerts_collector/alerts_collector_test.go | 93 +++++++++++++++++++ .../alerts_collector/mock/alert_service.go | 88 ++++++++++++++++++ main.go | 2 +- tools/tools.go | 5 + 7 files changed, 225 insertions(+), 13 deletions(-) create mode 100644 internal/alerts_collector/alerts_collector_test.go create mode 100644 internal/alerts_collector/mock/alert_service.go create mode 100644 tools/tools.go diff --git a/go.mod b/go.mod index eee47c2..d31577c 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,10 @@ go 1.21.4 require ( github.com/go-openapi/runtime v0.26.0 + github.com/golang/mock v1.6.0 github.com/prometheus/alertmanager v0.26.0 github.com/prometheus/client_golang v1.17.0 + github.com/stretchr/testify v1.8.4 golang.org/x/exp v0.0.0-20231006140011-7918f672742d ) @@ -13,6 +15,7 @@ require ( github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-logr/logr v1.2.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/analysis v0.21.4 // indirect @@ -31,13 +34,16 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/oklog/ulid v1.3.1 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect github.com/prometheus/common v0.44.0 // indirect github.com/prometheus/procfs v0.11.1 // indirect go.mongodb.org/mongo-driver v1.11.3 // indirect go.opentelemetry.io/otel v1.14.0 // indirect go.opentelemetry.io/otel/trace v1.14.0 // indirect + golang.org/x/mod v0.13.0 // indirect golang.org/x/sys v0.13.0 // indirect + golang.org/x/tools v0.14.0 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 7eef1ab..5810ff1 100644 --- a/go.sum +++ b/go.sum @@ -77,6 +77,8 @@ github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWe github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ= github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= @@ -169,6 +171,7 @@ github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23n github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.mongodb.org/mongo-driver v1.7.3/go.mod h1:NqaYOwnXWr5Pm7AOpO5QFxKJ503nbMse/R79oO62zWg= go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4xhp5Zvxng= go.mongodb.org/mongo-driver v1.10.0/go.mod h1:wsihk0Kdgv8Kqu1Anit4sfK+22vSFbUrAVEYRhCXrA8= @@ -183,12 +186,18 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= +golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -205,13 +214,16 @@ golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= @@ -220,7 +232,14 @@ golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= +golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= diff --git a/internal/alerts_collector/alerts_collector.go b/internal/alerts_collector/alerts_collector.go index 574d473..3f301d3 100644 --- a/internal/alerts_collector/alerts_collector.go +++ b/internal/alerts_collector/alerts_collector.go @@ -5,7 +5,6 @@ import ( "log" "strings" - "github.com/prometheus/alertmanager/api/v2/client" "github.com/prometheus/alertmanager/api/v2/client/alert" "github.com/prometheus/client_golang/prometheus" "golang.org/x/exp/slices" @@ -14,14 +13,14 @@ import ( func newDesc(labels []string) *prometheus.Desc { return prometheus.NewDesc( "alerts_exporter_alerts", - "Alertmanager alerts", + "Alerts queried from the Alertmanager API. Alert state can be found in the '_alerts_exporter_alert_state' label.", labels, nil, ) } type AlertsCollector struct { - API *client.AlertmanagerAPI + AlertService alert.ClientService WithInhibited, WithSilenced, WithUnprocessed, WithActive *bool @@ -42,7 +41,7 @@ func (o *AlertsCollector) Collect(ch chan<- prometheus.Metric) { WithInhibited(o.WithInhibited). WithFilter(o.Filters) - as, err := o.API.Alert.GetAlerts(p) + as, err := o.AlertService.GetAlerts(p) if err != nil { ch <- prometheus.NewInvalidMetric(newDesc([]string{}), err) @@ -51,14 +50,16 @@ func (o *AlertsCollector) Collect(ch chan<- prometheus.Metric) { } for _, a := range as.Payload { - if a.Status.State != nil { - a.Labels["_alerts_exporter_alert_status"] = *a.Status.State - } - if len(a.Status.InhibitedBy) > 0 { - a.Labels["_alerts_exporter_alert_inhibited_by"] = strings.Join(a.Status.InhibitedBy, ",") - } - if len(a.Status.SilencedBy) > 0 { - a.Labels["_alerts_exporter_alert_silenced_by"] = strings.Join(a.Status.SilencedBy, ",") + if a.Status != nil { + if a.Status.State != nil { + a.Labels["_alerts_exporter_alert_state"] = *a.Status.State + } + if len(a.Status.InhibitedBy) > 0 { + a.Labels["_alerts_exporter_alert_inhibited_by"] = strings.Join(a.Status.InhibitedBy, ",") + } + if len(a.Status.SilencedBy) > 0 { + a.Labels["_alerts_exporter_alert_silenced_by"] = strings.Join(a.Status.SilencedBy, ",") + } } k, v := pairs(a.Labels) diff --git a/internal/alerts_collector/alerts_collector_test.go b/internal/alerts_collector/alerts_collector_test.go new file mode 100644 index 0000000..c55b47b --- /dev/null +++ b/internal/alerts_collector/alerts_collector_test.go @@ -0,0 +1,93 @@ +package alertscollector_test + +import ( + "context" + "errors" + "strings" + "testing" + + "github.com/golang/mock/gomock" + "github.com/prometheus/alertmanager/api/v2/client/alert" + "github.com/prometheus/alertmanager/api/v2/models" + "github.com/prometheus/client_golang/prometheus/testutil" + "github.com/stretchr/testify/require" + + alertscollector "github.com/appuio/alerts_exporter/internal/alerts_collector" + "github.com/appuio/alerts_exporter/internal/alerts_collector/mock" +) + +//go:generate go run github.com/golang/mock/mockgen -destination=./mock/alert_service.go -package mock github.com/prometheus/alertmanager/api/v2/client/alert ClientService + +func TestAlertsCollector(t *testing.T) { + ctrl := gomock.NewController(t) + + mockAlertService := mock.NewMockClientService(ctrl) + + mockAlertService. + EXPECT(). + GetAlerts( + gomock.Eq(alert.NewGetAlertsParamsWithContext(context.Background()).WithActive(ptr(true))), + gomock.Any(), + ). + Return(&alert.GetAlertsOK{ + Payload: []*models.GettableAlert{ + { + Alert: models.Alert{ + Labels: map[string]string{ + "alertname": "ImportantAlert", + "severity": "critical", + }, + }, + Status: &models.AlertStatus{ + State: ptr("active"), + InhibitedBy: []string{"22a8bdd0-9b1e-4855-b8fb-8c1e18fa434f"}, + SilencedBy: []string{"d505b8d4-c5ce-466f-abd7-c704864299f5"}, + }, + }, + { + Alert: models.Alert{ + Labels: map[string]string{ + "alertname": "WhateverHappensHappens", + "severity": "low", + }, + }, + }, + }, + }, nil) + + subject := &alertscollector.AlertsCollector{ + AlertService: mockAlertService, + + WithActive: ptr(true), + } + + require.NoError(t, + testutil.CollectAndCompare(subject, strings.NewReader(` +# HELP alerts_exporter_alerts Alerts queried from the Alertmanager API. Alert state can be found in the '_alerts_exporter_alert_state' label. +# TYPE alerts_exporter_alerts gauge +alerts_exporter_alerts{alertname="WhateverHappensHappens",severity="low"} 1 +alerts_exporter_alerts{_alerts_exporter_alert_inhibited_by="22a8bdd0-9b1e-4855-b8fb-8c1e18fa434f",_alerts_exporter_alert_silenced_by="d505b8d4-c5ce-466f-abd7-c704864299f5",_alerts_exporter_alert_state="active",alertname="ImportantAlert",severity="critical"} 1 +`), + ), + ) +} + +func TestAlertsCollector_Err(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + mockAlertService := mock.NewMockClientService(ctrl) + + mockAlertService.EXPECT().GetAlerts(gomock.Any(), gomock.Any()).Return(nil, errors.New("API error")) + + subject := &alertscollector.AlertsCollector{ + AlertService: mockAlertService, + } + + require.ErrorContains(t, + testutil.CollectAndCompare(subject, nil), + "API error", + ) +} + +func ptr[T any](t T) *T { return &t } diff --git a/internal/alerts_collector/mock/alert_service.go b/internal/alerts_collector/mock/alert_service.go new file mode 100644 index 0000000..bc349c6 --- /dev/null +++ b/internal/alerts_collector/mock/alert_service.go @@ -0,0 +1,88 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/prometheus/alertmanager/api/v2/client/alert (interfaces: ClientService) + +// Package mock is a generated GoMock package. +package mock + +import ( + reflect "reflect" + + runtime "github.com/go-openapi/runtime" + gomock "github.com/golang/mock/gomock" + alert "github.com/prometheus/alertmanager/api/v2/client/alert" +) + +// MockClientService is a mock of ClientService interface. +type MockClientService struct { + ctrl *gomock.Controller + recorder *MockClientServiceMockRecorder +} + +// MockClientServiceMockRecorder is the mock recorder for MockClientService. +type MockClientServiceMockRecorder struct { + mock *MockClientService +} + +// NewMockClientService creates a new mock instance. +func NewMockClientService(ctrl *gomock.Controller) *MockClientService { + mock := &MockClientService{ctrl: ctrl} + mock.recorder = &MockClientServiceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockClientService) EXPECT() *MockClientServiceMockRecorder { + return m.recorder +} + +// GetAlerts mocks base method. +func (m *MockClientService) GetAlerts(arg0 *alert.GetAlertsParams, arg1 ...alert.ClientOption) (*alert.GetAlertsOK, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0} + for _, a := range arg1 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetAlerts", varargs...) + ret0, _ := ret[0].(*alert.GetAlertsOK) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAlerts indicates an expected call of GetAlerts. +func (mr *MockClientServiceMockRecorder) GetAlerts(arg0 interface{}, arg1 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0}, arg1...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAlerts", reflect.TypeOf((*MockClientService)(nil).GetAlerts), varargs...) +} + +// PostAlerts mocks base method. +func (m *MockClientService) PostAlerts(arg0 *alert.PostAlertsParams, arg1 ...alert.ClientOption) (*alert.PostAlertsOK, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0} + for _, a := range arg1 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "PostAlerts", varargs...) + ret0, _ := ret[0].(*alert.PostAlertsOK) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PostAlerts indicates an expected call of PostAlerts. +func (mr *MockClientServiceMockRecorder) PostAlerts(arg0 interface{}, arg1 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0}, arg1...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PostAlerts", reflect.TypeOf((*MockClientService)(nil).PostAlerts), varargs...) +} + +// SetTransport mocks base method. +func (m *MockClientService) SetTransport(arg0 runtime.ClientTransport) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetTransport", arg0) +} + +// SetTransport indicates an expected call of SetTransport. +func (mr *MockClientServiceMockRecorder) SetTransport(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetTransport", reflect.TypeOf((*MockClientService)(nil).SetTransport), arg0) +} diff --git a/main.go b/main.go index d79c2a1..f615931 100644 --- a/main.go +++ b/main.go @@ -73,7 +73,7 @@ func main() { reg := prometheus.NewRegistry() reg.MustRegister(&alertscollector.AlertsCollector{ - API: ac, + AlertService: ac.Alert, WithActive: &withActive, WithSilenced: &withSilenced, diff --git a/tools/tools.go b/tools/tools.go new file mode 100644 index 0000000..63ba1f3 --- /dev/null +++ b/tools/tools.go @@ -0,0 +1,5 @@ +//go:build tools + +package tools + +import _ "github.com/golang/mock/mockgen"