mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Wire up to full alert rule struct * Extract group change detection logic to dedicated file * GroupDiff -> GroupDelta for consistency * Calculate deltas and handle backwards compatible requests * Separate changes and insert/update/delete as needed * Regenerate files * Don't touch the DB if there are no changes * Quota checking, delete unused file * Mark modified records as provisioned * Validation + a couple API layer tests * Address linter errors * Fix issue with UID assignment and rule creation * Propagate top level group fields to all rules * Tests for repeated updates and versioning * Tests for quota and provenance checks * Fix linter errors * Regenerate * Factor out some shared logic * Drop unnecessary multiple nilchecks * Use alternative strategy for rolling UIDs on inserted rules * Fix tests, add back nilcheck, refresh UIDs during test * Address feedback * Add missing nil-check
48 lines
2.5 KiB
Go
48 lines
2.5 KiB
Go
package provisioning
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
|
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
|
"github.com/grafana/grafana/pkg/services/quota"
|
|
)
|
|
|
|
// AMStore is a store of Alertmanager configurations.
|
|
//go:generate mockery --name AMConfigStore --structname MockAMConfigStore --inpackage --filename persist_mock.go --with-expecter
|
|
type AMConfigStore interface {
|
|
GetLatestAlertmanagerConfiguration(ctx context.Context, query *models.GetLatestAlertmanagerConfigurationQuery) error
|
|
UpdateAlertmanagerConfiguration(ctx context.Context, cmd *models.SaveAlertmanagerConfigurationCmd) error
|
|
}
|
|
|
|
// ProvisioningStore is a store of provisioning data for arbitrary objects.
|
|
//go:generate mockery --name ProvisioningStore --structname MockProvisioningStore --inpackage --filename provisioning_store_mock.go --with-expecter
|
|
type ProvisioningStore interface {
|
|
GetProvenance(ctx context.Context, o models.Provisionable, org int64) (models.Provenance, error)
|
|
GetProvenances(ctx context.Context, org int64, resourceType string) (map[string]models.Provenance, error)
|
|
SetProvenance(ctx context.Context, o models.Provisionable, org int64, p models.Provenance) error
|
|
DeleteProvenance(ctx context.Context, o models.Provisionable, org int64) error
|
|
}
|
|
|
|
// TransactionManager represents the ability to issue and close transactions through contexts.
|
|
type TransactionManager interface {
|
|
InTransaction(ctx context.Context, work func(ctx context.Context) error) error
|
|
}
|
|
|
|
// RuleStore represents the ability to persist and query alert rules.
|
|
type RuleStore interface {
|
|
GetAlertRuleByUID(ctx context.Context, query *models.GetAlertRuleByUIDQuery) error
|
|
ListAlertRules(ctx context.Context, query *models.ListAlertRulesQuery) error
|
|
GetRuleGroupInterval(ctx context.Context, orgID int64, namespaceUID string, ruleGroup string) (int64, error)
|
|
InsertAlertRules(ctx context.Context, rule []models.AlertRule) (map[string]int64, error)
|
|
UpdateAlertRules(ctx context.Context, rule []store.UpdateRule) error
|
|
DeleteAlertRulesByUID(ctx context.Context, orgID int64, ruleUID ...string) error
|
|
GetAlertRulesGroupByRuleUID(ctx context.Context, query *models.GetAlertRulesGroupByRuleUIDQuery) error
|
|
}
|
|
|
|
// QuotaChecker represents the ability to evaluate whether quotas are met.
|
|
//go:generate mockery --name QuotaChecker --structname MockQuotaChecker --inpackage --filename quota_checker_mock.go --with-expecter
|
|
type QuotaChecker interface {
|
|
CheckQuotaReached(ctx context.Context, target string, scopeParams *quota.ScopeParameters) (bool, error)
|
|
}
|