Skip to content

Commit

Permalink
fix(siren): provider plugin interface (#30)
Browse files Browse the repository at this point in the history
* fix: add better logging for plugins provider (#29)

* feat: bump up go
  • Loading branch information
mabdh authored Sep 25, 2023
1 parent 48505b2 commit cd90feb
Show file tree
Hide file tree
Showing 40 changed files with 511 additions and 1,635 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.21
- name: Install dependencies
run: go mod tidy
- name: Test end-to-end
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Lint
on: [ push, pull_request, workflow_dispatch ]
on: [push, workflow_dispatch]

jobs:
golangci-lint:
Expand All @@ -8,10 +8,10 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.21
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
skip-go-installation: true
version: v1.50.1
args: --timeout=10m
version: v1.54.2
args: --timeout=10m
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.21
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_cortex_provider_plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.21
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

name: Test
on: [push, pull_request]
on: [push]

jobs:
test:
Expand All @@ -20,10 +19,10 @@ jobs:
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Set up Go 1.18
- name: Set up Go 1.21
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.21
id: go
- name: Install dependencies
run: sudo apt-get install build-essential
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Explore the following resources to get started with Siren:
Siren requires the following dependencies:

- Docker
- Golang (version 1.18 or above)
- Golang (version 1.21 or above)
- Git

Run the application dependencies using Docker:
Expand Down
10 changes: 7 additions & 3 deletions cli/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ func InitDeps(
templateRepository := postgres.NewTemplateRepository(pgClient)
templateService := template.NewService(templateRepository)

providerRepository := postgres.NewProviderRepository(pgClient)
providerService := provider.NewService(providerRepository)

logRepository := postgres.NewLogRepository(pgClient)
logService := log.NewService(logRepository)

Expand All @@ -89,6 +86,13 @@ func InitDeps(
return nil, nil, nil, nil, nil, err
}

var supportedProviderTypes = []string{}
for typ := range providerPlugins {
supportedProviderTypes = append(supportedProviderTypes, typ)
}
providerRepository := postgres.NewProviderRepository(pgClient)
providerService := provider.NewService(providerRepository, supportedProviderTypes)

var configSyncers = make(map[string]namespace.ConfigSyncer, 0)
var alertTransformers = make(map[string]alert.AlertTransformer, 0)
var ruleUploaders = make(map[string]rule.RuleUploader, 0)
Expand Down
20 changes: 10 additions & 10 deletions core/alert/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestService_List(t *testing.T) {
{ID: 2, ProviderID: 1, ResourceName: "foo", Severity: "CRITICAL", MetricName: "baz", MetricValue: "0",
Rule: "bar", TriggeredAt: timenow},
}
repositoryMock.EXPECT().List(mock.AnythingOfType("*context.emptyCtx"), alert.Filter{
repositoryMock.EXPECT().List(mock.AnythingOfType("context.todoCtx"), alert.Filter{
ProviderID: 1,
ResourceName: "foo",
StartTime: 0,
Expand All @@ -53,7 +53,7 @@ func TestService_List(t *testing.T) {
{ID: 2, ProviderID: 1, ResourceName: "foo", Severity: "CRITICAL", MetricName: "baz", MetricValue: "0",
Rule: "bar", TriggeredAt: timenow},
}
repositoryMock.EXPECT().List(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).Return(dummyAlerts, nil)
repositoryMock.EXPECT().List(mock.AnythingOfType("context.todoCtx"), mock.Anything).Return(dummyAlerts, nil)
actualAlerts, err := dummyService.List(ctx, alert.Filter{
ProviderID: 1,
ResourceName: "foo",
Expand All @@ -68,7 +68,7 @@ func TestService_List(t *testing.T) {
t.Run("should call repository List method and handle errors", func(t *testing.T) {
repositoryMock := &mocks.AlertRepository{}
dummyService := alert.NewService(repositoryMock, nil, nil)
repositoryMock.EXPECT().List(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).
repositoryMock.EXPECT().List(mock.AnythingOfType("context.todoCtx"), mock.Anything).
Return(nil, errors.New("random error"))
actualAlerts, err := dummyService.List(ctx, alert.Filter{
ProviderID: 1,
Expand Down Expand Up @@ -116,19 +116,19 @@ func TestService_CreateAlerts(t *testing.T) {
{
name: "should return error if TransformToAlerts return error",
setup: func(ar *mocks.AlertRepository, at *mocks.AlertTransformer) {
at.EXPECT().TransformToAlerts(mock.AnythingOfType("*context.emptyCtx"), mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64"), mock.AnythingOfType("map[string]interface {}")).Return(nil, 0, errors.New("some error"))
at.EXPECT().TransformToAlerts(mock.AnythingOfType("context.todoCtx"), mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64"), mock.AnythingOfType("map[string]interface {}")).Return(nil, 0, errors.New("some error"))
},
alertsToBeCreated: alertsToBeCreated,
wantErr: true,
},
{
name: "should call repository Create method with proper arguments",
setup: func(ar *mocks.AlertRepository, at *mocks.AlertTransformer) {
at.EXPECT().TransformToAlerts(mock.AnythingOfType("*context.emptyCtx"), mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64"), mock.AnythingOfType("map[string]interface {}")).Return([]alert.Alert{
at.EXPECT().TransformToAlerts(mock.AnythingOfType("context.todoCtx"), mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64"), mock.AnythingOfType("map[string]interface {}")).Return([]alert.Alert{
{ID: 1, ProviderID: 1, ResourceName: "foo", Severity: "CRITICAL", MetricName: "lag", MetricValue: "20",
Rule: "lagHigh", TriggeredAt: timenow},
}, 1, nil)
ar.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), mock.AnythingOfType("alert.Alert")).Return(alert.Alert{ID: 1, ProviderID: 1, ResourceName: "foo", Severity: "CRITICAL", MetricName: "lag", MetricValue: "20",
ar.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), mock.AnythingOfType("alert.Alert")).Return(alert.Alert{ID: 1, ProviderID: 1, ResourceName: "foo", Severity: "CRITICAL", MetricName: "lag", MetricValue: "20",
Rule: "lagHigh", TriggeredAt: timenow}, nil)
},
alertsToBeCreated: alertsToBeCreated,
Expand All @@ -141,23 +141,23 @@ func TestService_CreateAlerts(t *testing.T) {
{
name: "should return error not found if repository return err relation",
setup: func(ar *mocks.AlertRepository, at *mocks.AlertTransformer) {
at.EXPECT().TransformToAlerts(mock.AnythingOfType("*context.emptyCtx"), mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64"), mock.AnythingOfType("map[string]interface {}")).Return([]alert.Alert{
at.EXPECT().TransformToAlerts(mock.AnythingOfType("context.todoCtx"), mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64"), mock.AnythingOfType("map[string]interface {}")).Return([]alert.Alert{
{ID: 1, ProviderID: 1, ResourceName: "foo", Severity: "CRITICAL", MetricName: "lag", MetricValue: "20",
Rule: "lagHigh", TriggeredAt: timenow},
}, 1, nil)
ar.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).Return(alert.Alert{}, alert.ErrRelation)
ar.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), mock.Anything).Return(alert.Alert{}, alert.ErrRelation)
},
alertsToBeCreated: alertsToBeCreated,
wantErr: true,
},
{
name: "should handle errors from repository",
setup: func(ar *mocks.AlertRepository, at *mocks.AlertTransformer) {
at.EXPECT().TransformToAlerts(mock.AnythingOfType("*context.emptyCtx"), mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64"), mock.AnythingOfType("map[string]interface {}")).Return([]alert.Alert{
at.EXPECT().TransformToAlerts(mock.AnythingOfType("context.todoCtx"), mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64"), mock.AnythingOfType("map[string]interface {}")).Return([]alert.Alert{
{ID: 1, ProviderID: 1, ResourceName: "foo", Severity: "CRITICAL", MetricName: "lag", MetricValue: "20",
Rule: "lagHigh", TriggeredAt: timenow},
}, 1, nil)
ar.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).Return(alert.Alert{}, errors.New("random error"))
ar.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), mock.Anything).Return(alert.Alert{}, errors.New("random error"))
},
alertsToBeCreated: alertsToBeCreated,
wantErr: true,
Expand Down
Loading

0 comments on commit cd90feb

Please sign in to comment.