Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add celebration mode #1129

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Tetrergeru marked this conversation as resolved.
Show resolved Hide resolved

// AvailableCelebrationMode map with available celebration mode.
var availableCelebrationMode = map[string]struct{}{
Tetrergeru marked this conversation as resolved.
Show resolved Hide resolved
newYear: {},
}

// IsAvailableCelebrationMode return is mode available or not.
func IsAvailableCelebrationMode(mode string) bool {
_, ok := availableCelebrationMode[mode]

return ok
}

// Sentry - config for sentry settings.
Expand Down Expand Up @@ -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
}

Expand Down
18 changes: 14 additions & 4 deletions cmd/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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{
Expand Down
12 changes: 12 additions & 0 deletions cmd/api/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down