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(linter): WSL linter on cmd|docs|expression|image_store|templatin… #1061

Open
wants to merge 2 commits into
base: feat/upgrade_lint_step2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ issues:
exclude-files:
- notifier/registrator.go
exclude-rules:
- path-except: 'api/*/*'
- path-except: 'api|clock|cmd|docs|expression|image_store|templating|support/*/*'
linters:
- wsl
- path: _test\.go
Expand Down
2 changes: 2 additions & 0 deletions checker/metrics/conversion/trigger_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,13 @@ func (m TriggerMetrics) FindMissingMetrics(declaredAloneMetrics set[string]) map
if declaredAloneMetrics.contains(targetName) {
continue
}

diff := metricsSet.diff(fullMetrics)
if len(diff) > 0 {
result[targetName] = diff
}
}

return result
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/checker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (config *config) getSettings(logger moira.Logger) *checker.Config {
for _, v := range config.Checker.SetLogLevel.TriggersToLevel {
logTriggersToLevel[v.ID] = v.Level
}

logger.Info().
Int("number_of_triggers", len(logTriggersToLevel)).
Msg("Found dynamic log rules in config for some triggers")
Expand All @@ -81,6 +82,7 @@ func (config *config) getSettings(logger moira.Logger) *checker.Config {
String("cluster_id", "default").
Msg("MaxParallelChecks is not configured, set it to the number of CPU")
}

sourceCheckConfigs[moira.DefaultLocalCluster] = localCheckConfig

for _, remote := range config.Remotes.Graphite {
Expand All @@ -95,6 +97,7 @@ func (config *config) getSettings(logger moira.Logger) *checker.Config {
String("cluster_id", remote.ClusterID.String()).
Msg("MaxParallelChecks is not configured, set it to the number of CPU")
}

sourceCheckConfigs[moira.MakeClusterKey(moira.GraphiteRemote, remote.ClusterID)] = checkConfig
}

Expand All @@ -110,6 +113,7 @@ func (config *config) getSettings(logger moira.Logger) *checker.Config {
String("cluster_id", remote.ClusterID.String()).
Msg("MaxParallelChecks is not configured, set it to the number of CPU")
}

sourceCheckConfigs[moira.MakeClusterKey(moira.PrometheusRemote, remote.ClusterID)] = checkConfig
}

Expand Down
9 changes: 8 additions & 1 deletion cmd/checker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (

func main() {
flag.Parse()

if *printVersion {
fmt.Println("Moira Checker")
fmt.Println("Version:", MoiraVersion)
Expand Down Expand Up @@ -107,12 +108,14 @@ func main() {
LazyTriggersCache: cache.New(time.Minute*10, time.Minute*60), //nolint
PatternCache: cache.New(cacheExpiration, time.Minute*60), //nolint
}

err = checkerWorkerManager.StartWorkers()
if err != nil {
logger.Fatal().
Error(err).
Msg("Failed to start worker check")
}

defer stopChecker(checkerWorkerManager)

logger.Info().
Expand All @@ -129,20 +132,23 @@ func main() {
}

func checkSingleTrigger(database moira.Database, metrics *metrics.CheckerMetrics, settings *checker.Config, sourceProvider *metricSource.SourceProvider) {
triggerChecker, err := checker.MakeTriggerChecker(*triggerID, database, logger, settings, sourceProvider, metrics)
logger.String(moira.LogFieldNameTriggerID, *triggerID)

triggerChecker, err := checker.MakeTriggerChecker(*triggerID, database, logger, settings, sourceProvider, metrics)
if err != nil {
logger.Error().
Error(err).
Msg("Failed initialize trigger checker")
os.Exit(1)
}

if err = triggerChecker.Check(); err != nil {
logger.Error().
Error(err).
Msg("Failed check trigger")
os.Exit(1)
}

os.Exit(0)
}

Expand All @@ -159,5 +165,6 @@ func clusterKeyList(provider *metricSource.SourceProvider) []moira.ClusterKey {
for ck := range provider.GetAllSources() {
keys = append(keys, ck)
}

return keys
}
4 changes: 4 additions & 0 deletions cmd/cli/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ func renameKey(database moira.Database, oldValue, newValue string) error {
case *redis.DbConnector:
pipe := d.Client().TxPipeline()
iter := d.Client().Scan(d.Context(), 0, oldValue, 0).Iterator()

for iter.Next(d.Context()) {
oldKey := iter.Val()
newKey := strings.Replace(iter.Val(), oldValue, newValue, 1)
pipe.Rename(d.Context(), oldKey, newKey)
}

_, err := pipe.Exec(d.Context())
if err != nil {
return err
Expand All @@ -46,11 +48,13 @@ func changeKeysPrefix(database moira.Database, oldPrefix string, newPrefix strin
case *redis.DbConnector:
pipe := d.Client().TxPipeline()
iter := d.Client().Scan(d.Context(), 0, oldPrefix+"*", 0).Iterator()

for iter.Next(d.Context()) {
oldKey := iter.Val()
newKey := strings.Replace(iter.Val(), oldPrefix, newPrefix, 1)
pipe.Rename(d.Context(), oldKey, newKey)
}

_, err := pipe.Exec(d.Context())
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions cmd/cli/extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,31 @@ func enablePlottingInAllSubscriptions(logger moira.Logger, database moira.Databa
if err != nil {
return err
}

allSubscriptions, err := database.GetTagsSubscriptions(allTags)
if err != nil {
return err
}

for _, subscription := range allSubscriptions {
if subscription == nil {
continue
}

subscription.Plotting = moira.PlottingData{
Enabled: true,
Theme: "light",
}

if err := database.SaveSubscription(subscription); err != nil {
return err
}

logger.Debug().
String("subscription_id", subscription.ID).
String("contacts", strings.Join(subscription.Contacts, ", ")).
Msg("Successfully enabled plotting")
}

return nil
}
5 changes: 5 additions & 0 deletions cmd/cli/from_2.3_to_2.4.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ func updateFrom23(logger moira.Logger, dataBase moira.Database) error {
logger.Info().Msg("Update 2.3 -> 2.4 start")

logger.Info().Msg("Start marking unused triggers")

if err := resaveTriggers(dataBase); err != nil {
return err
}

logger.Info().Msg("Update 2.3 -> 2.4 finish")

return nil
}

Expand All @@ -23,16 +25,19 @@ func resaveTriggers(database moira.Database) error {
if err != nil {
return err
}

allTriggers, err := database.GetTriggers(allTriggerIDs)
if err != nil {
return err
}

for _, trigger := range allTriggers {
if trigger != nil {
if err = database.SaveTrigger(trigger.ID, trigger); err != nil {
return err
}
}
}

return nil
}
4 changes: 4 additions & 0 deletions cmd/cli/from_2.6_to_2.7.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@ func updateFrom26(logger moira.Logger, dataBase moira.Database) error {
logger.Info().Msg("Update 2.6 -> 2.7 was started")

logger.Info().Msg("Adding Redis Cluster support was started")

if err := addRedisClusterSupport(logger, dataBase); err != nil {
return err
}

logger.Info().Msg("Update 2.6 -> 2.7 was finished")

return nil
}

func downgradeTo26(logger moira.Logger, dataBase moira.Database) error {
logger.Info().Msg("Downgrade 2.7 -> 2.6 started")

logger.Info().Msg("Removing Redis Cluster support was started")

if err := removeRedisClusterSupport(logger, dataBase); err != nil {
return err
}

logger.Info().Msg("Downgrade 2.7 -> 2.6 was finished")

return nil
}
4 changes: 4 additions & 0 deletions cmd/cli/from_2.7_to_2.8.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func updateFrom27(logger moira.Logger, dataBase moira.Database) error {
logger.Info().Msg("Update 2.7 -> 2.8 was started")

logger.Info().Msg("Rename keys was started")

if err := updateSubscriptionKeyForAnonymous(logger, dataBase); err != nil {
return fmt.Errorf("failed updateSubscriptionKeyForAnonymous, has error %w", err)
}
Expand All @@ -19,13 +20,15 @@ func updateFrom27(logger moira.Logger, dataBase moira.Database) error {
}

logger.Info().Msg("Update 2.7 -> 2.8 was finished")

return nil
}

func downgradeTo27(logger moira.Logger, dataBase moira.Database) error {
logger.Info().Msg("Downgrade 2.8 -> 2.7 started")

logger.Info().Msg("Rename keys was started")

if err := downgradeSubscriptionKeyForAnonymous(logger, dataBase); err != nil {
return err
}
Expand All @@ -35,6 +38,7 @@ func downgradeTo27(logger moira.Logger, dataBase moira.Database) error {
}

logger.Info().Msg("Downgrade 2.8 -> 2.7 was finished")

return nil
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/cli/from_2.9_to_2.10.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,29 @@ func updateFrom29(logger moira.Logger, database moira.Database) error {
logger.Info().Msg("Update 2.9 -> 2.10 was started")

ctx := context.Background()

err := createKeyForLocalTriggers(ctx, logger, database)
if err != nil {
return err
}

logger.Info().Msg("Update 2.9 -> 2.10 was finished")

return nil
}

func downgradeTo29(logger moira.Logger, database moira.Database) error {
logger.Info().Msg("Downgrade 2.10 -> 2.9 started")

ctx := context.Background()

err := revertCreateKeyForLocalTriggers(ctx, logger, database)
if err != nil {
return err
}

logger.Info().Msg("Downgrade 2.10 -> 2.9 was finished")

return nil
}

Expand Down
Loading
Loading