From f22f795bab2de016e984edda07b5671a1613cd55 Mon Sep 17 00:00:00 2001 From: Xenia Nisskhen Date: Wed, 4 Dec 2024 13:04:52 +0500 Subject: [PATCH 1/2] feat(api): add celebration mode --- api/config.go | 28 +++++++++++++++++++++++----- cmd/api/config.go | 18 ++++++++++++++---- cmd/api/config_test.go | 12 ++++++++++++ 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/api/config.go b/api/config.go index 0b1671e15..d0308eb11 100644 --- a/api/config.go +++ b/api/config.go @@ -19,10 +19,28 @@ type WebContact struct { // FeatureFlags is struct to manage feature flags. type FeatureFlags struct { - IsPlottingDefaultOn bool `json:"isPlottingDefaultOn" example:"false"` - IsPlottingAvailable bool `json:"isPlottingAvailable" example:"true"` - IsSubscriptionToAllTagsAvailable bool `json:"isSubscriptionToAllTagsAvailable" example:"false"` - IsReadonlyEnabled bool `json:"isReadonlyEnabled" example:"false"` + IsPlottingDefaultOn bool `json:"isPlottingDefaultOn" example:"false"` + IsPlottingAvailable bool `json:"isPlottingAvailable" example:"true"` + IsSubscriptionToAllTagsAvailable bool `json:"isSubscriptionToAllTagsAvailable" example:"false"` + IsReadonlyEnabled bool `json:"isReadonlyEnabled" example:"false"` + CelebrationMode CelebrationMode `json:"celebrationMode" example:"new_year"` +} + +// CelebrationMode is type for celebrate Moira. +type CelebrationMode string + +const newYear = "new_year" + +// AvailableCelebrationMode map with available celebration mode. +var availableCelebrationMode = map[string]struct{}{ + newYear: {}, +} + +// IsAvailableCelebrationMode return is mode available or not. +func IsAvailableCelebrationMode(mode string) bool { + _, ok := availableCelebrationMode[mode] + + return ok } // Sentry - config for sentry settings. @@ -58,7 +76,7 @@ type MetricSourceCluster struct { ClusterName string `json:"cluster_name" example:"Graphite Remote Prod"` } -func (WebConfig) Render(w http.ResponseWriter, r *http.Request) error { +func (WebConfig) Render(http.ResponseWriter, *http.Request) error { return nil } diff --git a/cmd/api/config.go b/cmd/api/config.go index 41b998b37..0896ed24e 100644 --- a/cmd/api/config.go +++ b/cmd/api/config.go @@ -136,10 +136,11 @@ type webContact struct { } type featureFlags struct { - IsPlottingDefaultOn bool `yaml:"is_plotting_default_on"` - IsPlottingAvailable bool `yaml:"is_plotting_available"` - IsSubscriptionToAllTagsAvailable bool `yaml:"is_subscription_to_all_tags_available"` - IsReadonlyEnabled bool `yaml:"is_readonly_enabled"` + IsPlottingDefaultOn bool `yaml:"is_plotting_default_on"` + IsPlottingAvailable bool `yaml:"is_plotting_available"` + IsSubscriptionToAllTagsAvailable bool `yaml:"is_subscription_to_all_tags_available"` + IsReadonlyEnabled bool `yaml:"is_readonly_enabled"` + CelebrationMode string `yaml:"celebration_mode"` } func (config *apiConfig) getSettings( @@ -247,9 +248,18 @@ func (config *webConfig) getFeatureFlags() api.FeatureFlags { IsPlottingAvailable: config.FeatureFlags.IsPlottingAvailable, IsSubscriptionToAllTagsAvailable: config.FeatureFlags.IsSubscriptionToAllTagsAvailable, IsReadonlyEnabled: config.FeatureFlags.IsReadonlyEnabled, + CelebrationMode: getCelebrationMode(config.FeatureFlags.CelebrationMode), } } +func getCelebrationMode(mode string) api.CelebrationMode { + if api.IsAvailableCelebrationMode(mode) { + return api.CelebrationMode(mode) + } + + return "" +} + func getDefault() config { return config{ Redis: cmd.RedisConfig{ diff --git a/cmd/api/config_test.go b/cmd/api/config_test.go index 2892ab5db..286a316eb 100644 --- a/cmd/api/config_test.go +++ b/cmd/api/config_test.go @@ -258,6 +258,18 @@ func Test_webConfig_getSettings(t *testing.T) { }) } +func Test_webConfig_getCelebrationMode(t *testing.T) { + Convey("Available celebration mode, should return mode", t, func() { + celebrationMode := getCelebrationMode("new_year") + So(celebrationMode, ShouldEqual, api.CelebrationMode("new_year")) + }) + + Convey("Not available celebration mode, should return empty string", t, func() { + celebrationMode := getCelebrationMode("blablabla") + So(celebrationMode, ShouldEqual, "") + }) +} + func Test_webConfig_validate(t *testing.T) { Convey("With empty web config", t, func() { config := webConfig{} From c0c5eaab679e2c61c21eb67b4b4afcfa3ae7a7f6 Mon Sep 17 00:00:00 2001 From: Xenia Nisskhen Date: Wed, 4 Dec 2024 14:04:07 +0500 Subject: [PATCH 2/2] feat(api): add celebration mode --- api/config.go | 6 +++--- cmd/api/config.go | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/api/config.go b/api/config.go index d0308eb11..2db57ff71 100644 --- a/api/config.go +++ b/api/config.go @@ -29,15 +29,15 @@ type FeatureFlags struct { // CelebrationMode is type for celebrate Moira. type CelebrationMode string -const newYear = "new_year" +const newYear CelebrationMode = "new_year" // AvailableCelebrationMode map with available celebration mode. -var availableCelebrationMode = map[string]struct{}{ +var availableCelebrationMode = map[CelebrationMode]struct{}{ newYear: {}, } // IsAvailableCelebrationMode return is mode available or not. -func IsAvailableCelebrationMode(mode string) bool { +func IsAvailableCelebrationMode(mode CelebrationMode) bool { _, ok := availableCelebrationMode[mode] return ok diff --git a/cmd/api/config.go b/cmd/api/config.go index 0896ed24e..faf1e1d97 100644 --- a/cmd/api/config.go +++ b/cmd/api/config.go @@ -253,8 +253,9 @@ func (config *webConfig) getFeatureFlags() api.FeatureFlags { } func getCelebrationMode(mode string) api.CelebrationMode { - if api.IsAvailableCelebrationMode(mode) { - return api.CelebrationMode(mode) + celebrationMode := api.CelebrationMode(mode) + if api.IsAvailableCelebrationMode(celebrationMode) { + return celebrationMode } return ""