Skip to content

Commit

Permalink
fix(rule): revert silences and fix bug in rules api (#168)
Browse files Browse the repository at this point in the history
* Revert "feat: add silencing notification (#167)"

This reverts commit 1c7ed68.

* fix(rule): revert silence and fix bug in rules api
  • Loading branch information
mabdh authored Feb 2, 2023
1 parent 1c7ed68 commit aa28ac5
Show file tree
Hide file tree
Showing 141 changed files with 1,831 additions and 6,729 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13
image: postgres:12
ports:
- 5432:5432
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13
image: postgres:12
ports:
- 5432:5432
env:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ NAME="github.com/odpf/siren"
LAST_COMMIT := $(shell git rev-parse --short HEAD)
LAST_TAG := "$(shell git rev-list --tags --max-count=1)"
APP_VERSION := "$(shell git describe --tags ${LAST_TAG})-next"
PROTON_COMMIT := "546b6368150b4c12e24f25cf4657bc76dc3177a1"
PROTON_COMMIT := "9cdffc3c1838ec72b35b2a1b9a170ca9c138db66"

.PHONY: all build test clean dist vet proto install

Expand Down
53 changes: 13 additions & 40 deletions cli/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import (

"github.com/newrelic/go-agent/v3/newrelic"
"github.com/odpf/salt/db"
saltlog "github.com/odpf/salt/log"
"github.com/odpf/salt/log"
"github.com/odpf/siren/config"
"github.com/odpf/siren/core/alert"
"github.com/odpf/siren/core/log"
"github.com/odpf/siren/core/namespace"
"github.com/odpf/siren/core/notification"
"github.com/odpf/siren/core/provider"
"github.com/odpf/siren/core/receiver"
"github.com/odpf/siren/core/rule"
"github.com/odpf/siren/core/silence"
"github.com/odpf/siren/core/subscription"
"github.com/odpf/siren/core/template"
"github.com/odpf/siren/internal/api"
Expand All @@ -32,19 +30,18 @@ import (

func InitDeps(
ctx context.Context,
logger saltlog.Logger,
logger log.Logger,
cfg config.Config,
queue notification.Queuer,
) (*api.Deps, *newrelic.Application, *pgc.Client, map[string]notification.Notifier, error) {

telemetry.Init(ctx, cfg.Telemetry, logger)

nrApp, err := newrelic.NewApplication(
newrelic.ConfigAppName(cfg.Telemetry.NewRelicAppName),
newrelic.ConfigAppName(cfg.Telemetry.ServiceName),
newrelic.ConfigLicense(cfg.Telemetry.NewRelicAPIKey),
)
if err != nil {
logger.Warn("failed to init newrelic", "err", err)
return nil, nil, nil, nil, err
}

dbClient, err := db.New(cfg.DB)
Expand All @@ -62,26 +59,22 @@ func InitDeps(
return nil, nil, nil, nil, fmt.Errorf("cannot initialize encryptor: %w", err)
}

idempotencyRepository := postgres.NewIdempotencyRepository(pgClient)
templateRepository := postgres.NewTemplateRepository(pgClient)
templateService := template.NewService(templateRepository)

alertRepository := postgres.NewAlertRepository(pgClient)

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

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

cortexPluginService := cortex.NewPluginService(logger, cfg.Providers.Cortex)
alertRepository := postgres.NewAlertRepository(pgClient)
alertService := alert.NewService(
alertRepository,
logService,
map[string]alert.AlertTransformer{
provider.TypeCortex: cortexPluginService,
},
)

namespaceRepository := postgres.NewNamespaceRepository(pgClient)
alertHistoryService := alert.NewService(alertRepository, map[string]alert.AlertTransformer{
provider.TypeCortex: cortexPluginService,
})
namespaceService := namespace.NewService(encryptor, namespaceRepository, providerService, map[string]namespace.ConfigSyncer{
provider.TypeCortex: cortexPluginService,
})
Expand All @@ -96,9 +89,6 @@ func InitDeps(
},
)

silenceRepository := postgres.NewSilenceRepository(pgClient)
silenceService := silence.NewService(silenceRepository)

// plugin receiver services
slackPluginService := slack.NewPluginService(cfg.Receivers.Slack, encryptor)
pagerDutyPluginService := pagerduty.NewPluginService(cfg.Receivers.Pagerduty)
Expand All @@ -119,7 +109,6 @@ func InitDeps(
subscriptionRepository := postgres.NewSubscriptionRepository(pgClient)
subscriptionService := subscription.NewService(
subscriptionRepository,
logService,
namespaceService,
receiverService,
)
Expand All @@ -132,33 +121,17 @@ func InitDeps(
receiver.TypeFile: filePluginService,
}

idempotencyRepository := postgres.NewIdempotencyRepository(pgClient)
notificationRepository := postgres.NewNotificationRepository(pgClient)
notificationService := notification.NewService(
logger,
notificationRepository,
queue,
notifierRegistry,
notification.Deps{
LogService: logService,
IdempotencyRepository: idempotencyRepository,
ReceiverService: receiverService,
SubscriptionService: subscriptionService,
SilenceService: silenceService,
AlertService: alertService,
},
)
notificationService := notification.NewService(logger, queue, idempotencyRepository, receiverService, subscriptionService, notifierRegistry)

return &api.Deps{
TemplateService: templateService,
RuleService: ruleService,
AlertService: alertService,
AlertService: alertHistoryService,
ProviderService: providerService,
NamespaceService: namespaceService,
ReceiverService: receiverService,
SubscriptionService: subscriptionService,
NotificationService: notificationService,
SilenceService: silenceService,
}, nrApp, pgClient, notifierRegistry,
nil
}
2 changes: 1 addition & 1 deletion cli/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func UploadRules(client sirenv1beta1.SirenServiceClient, yamlFile []byte) ([]uin
payload.Namespace, payload.GroupName, payload.Template), err)
return successfullyUpsertedRulesID, err
}
successfullyUpsertedRulesID = append(successfullyUpsertedRulesID, result.GetId())
successfullyUpsertedRulesID = append(successfullyUpsertedRulesID, result.GetRule().GetId())
fmt.Printf("successfully uploaded %s/%s/%s",
payload.Namespace, payload.GroupName, payload.Template)

Expand Down
2 changes: 1 addition & 1 deletion config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/mcuadros/go-defaults"
"github.com/odpf/siren/core/receiver"
"gopkg.in/yaml.v3"
"gopkg.in/yaml.v2"
)

func Init(configFile string) error {
Expand Down
24 changes: 11 additions & 13 deletions core/alert/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@ import (
type Repository interface {
Create(context.Context, Alert) (Alert, error)
List(context.Context, Filter) ([]Alert, error)
BulkUpdateSilence(context.Context, []int64, string) error
}

type Alert struct {
ID uint64 `json:"id"`
ProviderID uint64 `json:"provider_id"`
NamespaceID uint64 `json:"namespace_id"`
ResourceName string `json:"resource_name"`
MetricName string `json:"metric_name"`
MetricValue string `json:"metric_value"`
Severity string `json:"severity"`
Rule string `json:"rule"`
TriggeredAt time.Time `json:"triggered_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
SilenceStatus string `json:"silence_status"`
ID uint64 `json:"id"`
ProviderID uint64 `json:"provider_id"`
NamespaceID uint64 `json:"namespace_id"`
ResourceName string `json:"resource_name"`
MetricName string `json:"metric_name"`
MetricValue string `json:"metric_value"`
Severity string `json:"severity"`
Rule string `json:"rule"`
TriggeredAt time.Time `json:"triggered_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`

// These fields won't be stored in the DB
// these are additional information for notification purposes
Expand Down
2 changes: 0 additions & 2 deletions core/alert/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ type Filter struct {
NamespaceID uint64
StartTime int64
EndTime int64
SilenceID string
IDs []int64
}
39 changes: 0 additions & 39 deletions core/alert/mocks/alert_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 0 additions & 84 deletions core/alert/mocks/log_service.go

This file was deleted.

Loading

0 comments on commit aa28ac5

Please sign in to comment.