Skip to content

Commit 256b2f9

Browse files
feat(api): Add alert path prefix as configuration field (#648)
# Description This PR simply introduces a new configuration field for the Merlin API server to make the alert path prefix (currently hardcoded as `alerts/merlin`) into a configurable field. This allows for more customisable paths to be used when setting up alerts using the current GitOps approach. # Modifications - `api/config/config.go` - Added a new configuration field `AlertPathPrefix` - `api/service/model_endpoint_alert_service.go` - Made changes to the current way an alert file path is generated # Tests <!-- Besides the existing / updated automated tests, what specific scenarios should be tested? Consider the backward compatibility of the changes, whether corner cases are covered, etc. Please describe the tests and check the ones that have been completed. Eg: - [x] Deploying new and existing standard models - [ ] Deploying PyFunc models --> # Checklist - [x] Added PR label - [x] Added unit test, integration, and/or e2e tests - [x] Tested locally - [ ] Updated documentation - [ ] Update Swagger spec if the PR introduce API changes - [ ] Regenerated Golang and Python client if the PR introduces API changes # Release Notes <!-- Does this PR introduce a user-facing change? If no, just write "NONE" in the release-note block below. If yes, a release note is required. Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required". For more information about release notes, see kubernetes' guide here: http://git.k8s.io/community/contributors/guide/release-notes.md --> ```release-note NONE ```
1 parent b7a429d commit 256b2f9

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

api/cmd/api/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func buildDependencies(ctx context.Context, cfg *config.Config, db *gorm.DB, dis
320320
modelEndpointAlertService := service.NewModelEndpointAlertService(
321321
storage.NewAlertStorage(db), gitlabClient, wardenClient,
322322
gitlabConfig.DashboardRepository, gitlabConfig.DashboardBranch,
323-
gitlabConfig.AlertRepository, gitlabConfig.AlertBranch,
323+
gitlabConfig.AlertRepository, gitlabConfig.AlertBranch, gitlabConfig.AlertPathPrefix,
324324
cfg.FeatureToggleConfig.MonitoringConfig.MonitoringBaseURL)
325325

326326
mlflowConfig := cfg.MlflowConfig

api/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ type GitlabConfig struct {
288288
DashboardBranch string `default:"master"`
289289
AlertRepository string
290290
AlertBranch string `default:"master"`
291+
AlertPathPrefix string
291292
}
292293

293294
type WardenConfig struct {

api/config/config_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,9 @@ func TestLoad(t *testing.T) {
490490
BaseURL: "https://test.io/",
491491
DashboardRepository: "dashboards/merlin",
492492
DashboardBranch: "master",
493-
AlertRepository: "alerts/merlin",
493+
AlertRepository: "alerts_repository/merlin",
494494
AlertBranch: "master",
495+
AlertPathPrefix: "alerts/merlin",
495496
},
496497
WardenConfig: WardenConfig{
497498
APIHost: "https://test.io/",

api/config/testdata/base-configs-1.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ FeatureToggleConfig:
115115
BaseURL: https://test.io/
116116
DashboardRepository: dashboards/merlin
117117
DashboardBranch: master
118-
AlertRepository: alerts/merlin
118+
AlertRepository: alerts_repository/merlin
119119
AlertBranch: master
120+
AlertPathPrefix: alerts/merlin
120121
WardenConfig:
121122
APIHost: https://test.io/
122123
ModelDeletionConfig:

api/service/model_endpoint_alert_service.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type modelEndpointAlertService struct {
4444
dashboardBranch string
4545
alertRepository string
4646
alertBranch string
47+
alertPathPrefix string
4748

4849
dashboardBaseURL string
4950
}
@@ -53,7 +54,7 @@ func NewModelEndpointAlertService(
5354
alertStorage storage.AlertStorage,
5455
gitlabClient gitlab.Client, wardenClient warden.Client,
5556
dashboardRepository, dashboardBranch,
56-
alertRepository, alertBranch, dashboardBaseURL string) ModelEndpointAlertService {
57+
alertRepository, alertBranch, alertPathPrefix, dashboardBaseURL string) ModelEndpointAlertService {
5758
return &modelEndpointAlertService{
5859
alertStorage: alertStorage,
5960
gitlabClient: gitlabClient,
@@ -63,6 +64,7 @@ func NewModelEndpointAlertService(
6364
dashboardBranch: dashboardBranch,
6465
alertRepository: alertRepository,
6566
alertBranch: alertBranch,
67+
alertPathPrefix: alertPathPrefix,
6668

6769
dashboardBaseURL: dashboardBaseURL,
6870
}
@@ -91,7 +93,7 @@ func (s *modelEndpointAlertService) CreateModelEndpointAlert(user string, alert
9193
if err != nil {
9294
return nil, err
9395
}
94-
alertFilename := fmt.Sprintf("alerts/merlin/%s/%s_%s.yaml", alert.Model.Project.Name, alert.Model.Name, alert.EnvironmentName)
96+
alertFilename := fmt.Sprintf("%s/%s/%s_%s.yaml", s.alertPathPrefix, alert.Model.Project.Name, alert.Model.Name, alert.EnvironmentName)
9597

9698
createAlertOpt := gitlab.CreateFileOptions{
9799
Repository: s.alertRepository,
@@ -125,7 +127,7 @@ func (s *modelEndpointAlertService) UpdateModelEndpointAlert(user string, alert
125127
if err != nil {
126128
return nil, err
127129
}
128-
alertFilename := fmt.Sprintf("alerts/merlin/%s/%s_%s.yaml", alert.Model.Project.Name, alert.Model.Name, alert.EnvironmentName)
130+
alertFilename := fmt.Sprintf("%s/%s/%s_%s.yaml", s.alertPathPrefix, alert.Model.Project.Name, alert.Model.Name, alert.EnvironmentName)
129131

130132
updateAlertOpt := gitlab.UpdateFileOptions{
131133
Repository: s.alertRepository,

0 commit comments

Comments
 (0)