From 821493a496781506df638cfb65390e3b11856df0 Mon Sep 17 00:00:00 2001 From: Moshe Immerman Date: Sun, 22 Oct 2023 19:39:19 +0300 Subject: [PATCH 1/7] feat: add extraArgs to chart --- chart/templates/deployment.yaml | 3 +++ chart/values.yaml | 2 ++ 2 files changed, 5 insertions(+) diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index f29f3751a..9dffa4d40 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -140,6 +140,9 @@ spec: {{- if gt (int .Values.replicas) 1 }} - --enable-leader-election=true {{- end }} + {{- range $k, $v := .Values.extraArgs}} + - --{{$k}}={{$v}} + {{- end }} {{- if .Values.upstream.enabled }} - --agent-name={{ .Values.upstream.agentName }} - --upstream-host=$UPSTREAM_HOST diff --git a/chart/values.yaml b/chart/values.yaml index 32198c9a4..2a86af245 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -133,6 +133,8 @@ disableChecks: {} # a list of db properties to update on startup properties: {} +# a map of extra arguments to the canary-checker cli +extraArgs: {} extra: # nodeSelector: # key: value From 557f729a8158f7d5908fde3f08d7518320b5ece0 Mon Sep 17 00:00:00 2001 From: Moshe Immerman Date: Sun, 22 Oct 2023 19:43:26 +0300 Subject: [PATCH 2/7] chore: make upstream secret optional --- chart/templates/deployment.yaml | 15 +++++++++++---- chart/values.yaml | 7 +++++-- cmd/root.go | 13 ++++++++----- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index 9dffa4d40..36cab6485 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -95,7 +95,7 @@ spec: {{- else }} value: "embedded:///opt/database/" {{- end }} - {{- if .Values.upstream.enabled }} + {{- if .Values.upstream.secretKeyRef.name }} envFrom: - secretRef: name: {{ .Values.upstream.secretKeyRef.name }} @@ -143,11 +143,18 @@ spec: {{- range $k, $v := .Values.extraArgs}} - --{{$k}}={{$v}} {{- end }} + {{- if .Values.upstream.enabled }} - --agent-name={{ .Values.upstream.agentName }} - - --upstream-host=$UPSTREAM_HOST - - --upstream-user=$UPSTREAM_USER - - --upstream-password=$UPSTREAM_PASSWORD + {{- if .Values.upstream.host }} + - --upstream-host={{ .Values.upstream.host }} + {{- end}} + {{- if .Values.upstream.user }} + - --upstream-user={{ .Values.upstream.user }} + {{- end}} + {{- if .Values.upstream.password }} + - --upstream-password={{ .Values.upstream.password }} + {{- end}} {{- end }} resources: {{- toYaml .Values.resources | nindent 12 }} diff --git a/chart/values.yaml b/chart/values.yaml index 2a86af245..09b7299ec 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -73,9 +73,12 @@ data: upstream: enabled: false agentName: default-agent - # Must contain: UPSTREAM_USER, UPSTREAM_PASS & UPSTREAM_HOST + host: "" + user: "" + password: "" + # Alternative to inlining values, secret must contain: UPSTREAM_NAME, UPSTREAM_USER, UPSTREAM_PASSWORD & UPSTREAM_HOST secretKeyRef: - name: canary-checker-upstream + name: ingress: enabled: false diff --git a/cmd/root.go b/cmd/root.go index 19405fed9..6f3ce11a2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -27,6 +27,10 @@ var Root = &cobra.Command{ if db.ConnectionString == "DB_URL" { db.ConnectionString = "" } + + if canary.UpstreamConf.Valid() { + logger.Infof("Pushing checks to %s with name=%s user=%s", canary.UpstreamConf.Host, canary.UpstreamConf.AgentName, canary.UpstreamConf.Username) + } }, } @@ -65,13 +69,12 @@ func ServerFlags(flags *pflag.FlagSet) { flags.IntVar(&db.CheckRetentionDays, "check-retention-period", db.DefaultCheckRetentionDays, "Check retention period in days") flags.IntVar(&db.CanaryRetentionDays, "canary-retention-period", db.DefaultCanaryRetentionDays, "Canary retention period in days") - // Flags for push/pull - flags.StringVar(&canary.UpstreamConf.Host, "upstream-host", "", "central canary checker instance to push/pull canaries") - flags.StringVar(&canary.UpstreamConf.Username, "upstream-user", "", "upstream username") - flags.StringVar(&canary.UpstreamConf.Password, "upstream-password", "", "upstream password") - flags.StringVar(&canary.UpstreamConf.AgentName, "agent-name", "", "name of this agent") flags.IntVar(&canary.ReconcilePageSize, "upstream-page-size", 500, "upstream reconciliation page size") flags.DurationVar(&canary.ReconcileMaxAge, "upstream-max-age", time.Hour*48, "upstream reconciliation max age") + flags.StringVar(&canary.UpstreamConf.Host, "upstream-host", os.Getenv("UPSTREAM_HOST"), "central canary checker instance to push/pull canaries") + flags.StringVar(&canary.UpstreamConf.Username, "upstream-user", os.Getenv("UPSTREAM_USER"), "upstream username") + flags.StringVar(&canary.UpstreamConf.Password, "upstream-password", os.Getenv("UPSTREAM_PASSWORD"), "upstream password") + flags.StringVar(&canary.UpstreamConf.AgentName, "agent-name", os.Getenv("UPSTREAM_NAME"), "name of this agent") } func readFromEnv(v string) string { From c7cb670201ca143bc45873d948737fc0b9ceaf9f Mon Sep 17 00:00:00 2001 From: Moshe Immerman Date: Sun, 22 Oct 2023 19:55:13 +0300 Subject: [PATCH 3/7] chore: revert back to mergestat fork --- build/full/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build/full/Dockerfile b/build/full/Dockerfile index 07258e4b8..b780b4aea 100644 --- a/build/full/Dockerfile +++ b/build/full/Dockerfile @@ -62,8 +62,7 @@ RUN curl -L https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-${JMETER_VER ENV PATH /opt/apache-jmeter-${JMETER_VERSION}/bin/:$PATH - -RUN curl -L https://github.com/mergestat/mergestat-lite/releases/download/v0.6.1/mergestat-linux-amd64.tar.gz -o mergestat.tar.gz && \ +RUN curl -L https://github.com/flanksource/askgit/releases/download/v0.61.0-flanksource.1/mergestat-linux-amd64.tar.gz -o mergestat.tar.gz && \ tar zxf mergestat.tar.gz -C /usr/local/bin/ && \ rm mergestat.tar.gz From 7b1227165f4b42a436ecd3c9276cbeef60b9f421 Mon Sep 17 00:00:00 2001 From: Moshe Immerman Date: Sun, 22 Oct 2023 21:49:03 +0300 Subject: [PATCH 4/7] feat: add support for exporting to json from run --- cmd/run.go | 41 +++++++++++++++++++++++++++++++++++++++-- pkg/api.go | 30 ++++++++++++++++-------------- 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 50f80db70..9bcb488a7 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -1,6 +1,7 @@ package cmd import ( + "encoding/json" "fmt" "log" "os" @@ -22,7 +23,7 @@ import ( ) var outputFile, dataFile, runNamespace string -var junit, csv bool +var junit, csv, jsonExport bool var Run = &cobra.Command{ Use: "run ", @@ -112,6 +113,21 @@ var Run = &cobra.Command{ logger.Fatalf("error writing output file: %v", err) } } + if jsonExport { + + for _, result := range results { + result.Name = def(result.Name, result.Check.GetName(), result.Canary.Name) + result.Description = def(result.Description, result.Check.GetDescription()) + result.Labels = merge(result.Check.GetLabels(), result.Labels) + fmt.Println(result.Name) + } + + data, err := json.Marshal(results) + if err != nil { + logger.Fatalf("Failed to marshall json: %s", err) + } + output.HandleOutput(string(data), outputFile) + } logger.Infof("%d passed, %d failed in %s", passed, failed, timer) @@ -121,11 +137,32 @@ var Run = &cobra.Command{ }, } +func merge(m1, m2 map[string]string) map[string]string { + out := make(map[string]string) + for k, v := range m1 { + out[k] = v + } + for k, v := range m2 { + out[k] = v + } + return out +} + +func def(a ...string) string { + for _, s := range a { + if s != "" { + return s + } + } + return "" +} + func init() { Run.PersistentFlags().StringVarP(&dataFile, "data", "d", "", "Template out each spec using the JSON or YAML data in this file") Run.PersistentFlags().StringVarP(&outputFile, "output-file", "o", "", "file to output the results in") Run.Flags().StringVarP(&runNamespace, "namespace", "n", "", "Namespace to run canary checks in") - Run.Flags().BoolVarP(&junit, "junit", "j", false, "output results in junit format") + Run.Flags().BoolVar(&junit, "junit", false, "output results in junit format") + Run.Flags().BoolVarP(&jsonExport, "json", "j", false, "output results in json format") Run.Flags().BoolVar(&csv, "csv", false, "output results in csv format") } diff --git a/pkg/api.go b/pkg/api.go index 4560b616f..fe81eab06 100644 --- a/pkg/api.go +++ b/pkg/api.go @@ -401,21 +401,23 @@ type URL struct { type SystemResult struct{} type CheckResult struct { - Start time.Time - Pass bool - Invalid bool - Detail interface{} - Data map[string]interface{} - Duration int64 - Description string - DisplayType string - Message string - Error string - Metrics []Metric - Transformed bool + Name string `json:"name,omitempty"` + Start time.Time `json:"start,omitempty"` + Pass bool `json:"pass,omitempty"` + Invalid bool `json:"invalid,omitempty"` + Detail interface{} `json:"detail,omitempty"` + Data map[string]interface{} `json:"data,omitempty"` + Labels map[string]string `json:"labels,omitempty"` + Duration int64 `json:"duration,omitempty"` + Description string `json:"description,omitempty"` + DisplayType string `json:"display_type,omitempty"` + Message string `json:"message,omitempty"` + Error string `json:"error,omitempty"` + Metrics []Metric `json:"metrics,omitempty"` + Transformed bool `json:"transformed,omitempty"` // Check is the configuration - Check external.Check - Canary v1.Canary + Check external.Check `json:"-"` + Canary v1.Canary `json:"-"` } func (result CheckResult) GetDescription() string { From 2134686803a50992701ced5c36d0d2cb6399102d Mon Sep 17 00:00:00 2001 From: Moshe Immerman Date: Sun, 22 Oct 2023 21:56:48 +0300 Subject: [PATCH 5/7] chore: switch to cel for alertmanager / aws checks --- checks/alertmanager.go | 8 +- checks/aws_config_rule.go | 100 ++++++++++++++------ checks/cloudwatch.go | 6 +- checks/common.go | 16 ++++ fixtures/aws/aws_config_rule_pass.yaml | 20 +++- fixtures/aws/cloudwatch_pass.yaml | 33 ++++--- fixtures/datasources/alertmanager_fail.yaml | 26 +++-- go.mod | 2 +- go.sum | 10 +- 9 files changed, 146 insertions(+), 75 deletions(-) diff --git a/checks/alertmanager.go b/checks/alertmanager.go index 8b08694d9..a1c7aec13 100644 --- a/checks/alertmanager.go +++ b/checks/alertmanager.go @@ -71,7 +71,11 @@ func (c *AlertManagerChecker) Check(ctx *context.Context, extConfig external.Che return results } - var alertMessages []map[string]any + type Alerts struct { + Alerts []map[string]interface{} `json:"alerts,omitempty"` + } + + var alertMessages []map[string]interface{} for _, alert := range alerts.Payload { alertMap := map[string]any{ "name": generateFullName(alert.Labels["alertname"], alert.Labels), @@ -83,7 +87,7 @@ func (c *AlertManagerChecker) Check(ctx *context.Context, extConfig external.Che alertMessages = append(alertMessages, alertMap) } - result.AddDetails(alertMessages) + result.AddDetails(Alerts{Alerts: alertMessages}) return results } diff --git a/checks/aws_config_rule.go b/checks/aws_config_rule.go index b57a454ed..cab405ad9 100644 --- a/checks/aws_config_rule.go +++ b/checks/aws_config_rule.go @@ -3,8 +3,8 @@ package checks import ( - "fmt" "strings" + "time" "github.com/aws/aws-sdk-go-v2/service/configservice" "github.com/aws/aws-sdk-go-v2/service/configservice/types" @@ -65,44 +65,82 @@ func (c *AwsConfigRuleChecker) Check(ctx *context.Context, extConfig external.Ch if err != nil { return results.Failf("failed to describe compliance rules: %v", err) } - var complianceResults pkg.Results + + type ConfigRuleResource struct { + ID string `json:"id"` + Annotation string `json:"annotation"` + Type string `json:"type"` + Recorded time.Time `json:"recorded"` + Mode string `json:"mode"` + } + + type ComplianceResult struct { + + // Supplementary information about how the evaluation determined the compliance. + Annotation string `json:"annotation"` + + ConfigRule string `json:"rule"` + + Description string `json:"description"` + // Indicates whether the Amazon Web Services resource complies with the Config + // rule that evaluated it. For the EvaluationResult data type, Config supports + // only the COMPLIANT , NON_COMPLIANT , and NOT_APPLICABLE values. Config does not + // support the INSUFFICIENT_DATA value for the EvaluationResult data type. + ComplianceType string `json:"type"` + + Resources []ConfigRuleResource `json:"resources"` + } + + var complianceResults []ComplianceResult + var failures []string for _, complianceRule := range output.ComplianceByConfigRules { if configRuleInRules(check.IgnoreRules, *complianceRule.ConfigRuleName) || complianceRule.Compliance.ComplianceType == "INSUFFICIENT_DATA" || complianceRule.Compliance.ComplianceType == "NOT_APPLICABLE" { continue } - if complianceRule.Compliance != nil { - var complianceResult *pkg.CheckResult - complianceCheck := check - complianceCheck.Description.Description = fmt.Sprintf("%s - checking compliance for config rule: %s", check.Description.Description, *complianceRule.ConfigRuleName) - if complianceRule.Compliance.ComplianceType != "COMPLIANT" { - complianceResult = pkg.Fail(complianceCheck, ctx.Canary) - complianceDetailsOutput, err := client.GetComplianceDetailsByConfigRule(ctx, &configservice.GetComplianceDetailsByConfigRuleInput{ - ComplianceTypes: []types.ComplianceType{ - "NON_COMPLIANT", - }, - ConfigRuleName: complianceRule.ConfigRuleName, + + if complianceRule.Compliance == nil { + continue + } + var data = ComplianceResult{ + ConfigRule: *complianceRule.ConfigRuleName, + ComplianceType: string(complianceRule.Compliance.ComplianceType), + } + + if complianceRule.Compliance.ComplianceType != "COMPLIANT" { + failures = append(failures, *complianceRule.ConfigRuleName) + complianceDetailsOutput, err := client.GetComplianceDetailsByConfigRule(ctx, &configservice.GetComplianceDetailsByConfigRuleInput{ + ComplianceTypes: []types.ComplianceType{ + "NON_COMPLIANT", + }, + ConfigRuleName: complianceRule.ConfigRuleName, + }) + if err != nil { + result.Failf("failed to get compliance details: %v", err) + continue + } + for _, result := range complianceDetailsOutput.EvaluationResults { + id := *result.EvaluationResultIdentifier.EvaluationResultQualifier + data.Resources = append(data.Resources, ConfigRuleResource{ + ID: *id.ResourceId, + Type: *id.ResourceType, + Mode: string(id.EvaluationMode), + Recorded: *result.ResultRecordedTime, + Annotation: *result.Annotation, }) - if err != nil { - complianceResult.Failf("failed to get compliance details: %v", err) - continue - } - var resources []string - for _, result := range complianceDetailsOutput.EvaluationResults { - if result.EvaluationResultIdentifier.EvaluationResultQualifier.ResourceId != nil { - resources = append(resources, *result.EvaluationResultIdentifier.EvaluationResultQualifier.ResourceId) - } - } - complianceResult.AddDetails(resources) - complianceResult.ResultMessage(strings.Join(resources, ",")) - } else { - complianceResult = pkg.Success(complianceCheck, ctx.Canary) - complianceResult.AddDetails(complianceRule) - complianceResult.ResultMessage(fmt.Sprintf("%s rule is %v", *complianceRule.ConfigRuleName, complianceRule.Compliance.ComplianceType)) } - complianceResults = append(complianceResults, complianceResult) } + complianceResults = append(complianceResults, data) } - return complianceResults + + if check.Test.IsEmpty() && len(failures) > 0 { + result.Failf(strings.Join(failures, ", ")) + } + if r, err := unstructure(map[string]interface{}{"rules": complianceResults}); err != nil { + result.Failf(err.Error()) + } else { + result.AddDetails(r) + } + return results } func configRuleInRules(rules []string, ruleName string) bool { diff --git a/checks/cloudwatch.go b/checks/cloudwatch.go index aeb745aae..ecca776ff 100644 --- a/checks/cloudwatch.go +++ b/checks/cloudwatch.go @@ -58,7 +58,11 @@ func (c *CloudWatchChecker) Check(ctx *context.Context, extConfig external.Check if err != nil { return results.ErrorMessage(err) } - result.AddDetails(alarms) + if o, err := unstructure(alarms); err != nil { + return results.ErrorMessage(err) + } else { + result.AddDetails(o) + } firing := []string{} for _, alarm := range alarms.MetricAlarms { if alarm.StateValue == types.StateValueAlarm { diff --git a/checks/common.go b/checks/common.go index 3d6cc782f..1464b1f20 100644 --- a/checks/common.go +++ b/checks/common.go @@ -51,6 +51,17 @@ func def(a, b string) string { return b } +// unstructure marshalls a struct to and from JSON to remove any type details +func unstructure(o any) (out interface{}, err error) { + + data, err := json.Marshal(o) + if err != nil { + return nil, err + } + err = json.Unmarshal(data, &out) + return out, err +} + func template(ctx *context.Context, template v1.Template) (string, error) { return gomplate.RunTemplate(ctx.Environment, template.Gomplate()) } @@ -107,6 +118,7 @@ func transform(ctx *context.Context, in *pkg.CheckResult) ([]*pkg.CheckResult, e // We use this label to set the transformed column to true // This label is used and then removed in pkg.FromV1 function r.Canary.Labels["transformed"] = "true" //nolint:goconst + r.Labels = t.Labels r.Transformed = true results = append(results, &r) } @@ -144,6 +156,9 @@ func transform(ctx *context.Context, in *pkg.CheckResult) ([]*pkg.CheckResult, e if t.DisplayType != "" { in.DisplayType = t.DisplayType } + if len(t.Labels) > 0 { + in.Labels = t.Labels + } if len(t.Data) > 0 { for k, v := range t.Data { in.Data[k] = v @@ -166,6 +181,7 @@ func GetJunitReportFromResults(canaryName string, results []*pkg.CheckResult) Ju test.Name = result.Check.GetDescription() test.Message = result.Message test.Duration = float64(result.Duration) / 1000 + test.Properties = result.Labels testSuite.Duration += float64(result.Duration) / 1000 if result.Pass { testSuite.Passed++ diff --git a/fixtures/aws/aws_config_rule_pass.yaml b/fixtures/aws/aws_config_rule_pass.yaml index ad48c0015..bc762a835 100644 --- a/fixtures/aws/aws_config_rule_pass.yaml +++ b/fixtures/aws/aws_config_rule_pass.yaml @@ -5,7 +5,19 @@ metadata: spec: interval: 30 awsConfigRule: - - description: Test config rules - name: non compliant rules - complianceTypes: - - NON_COMPLIANT \ No newline at end of file + - name: AWS Config Rule + region: "eu-west-1" + complianceTypes: [NON_COMPLIANT] + transform: + expr: | + results.rules.map(i, + i.resources.map(r, + { + 'name': i.rule + "/" + r.type + "/" + r.id, + 'description': i.rule, + 'icon': 'aws-config-alarm', + 'duration': time.Since(timestamp(r.recorded)).getMilliseconds(), + 'labels': {'id': r.id, 'type': r.type}, + 'message': i.description + i.annotation + r.annotation + }) + ).flatten().toJSON() diff --git a/fixtures/aws/cloudwatch_pass.yaml b/fixtures/aws/cloudwatch_pass.yaml index b748310ac..597c9f930 100644 --- a/fixtures/aws/cloudwatch_pass.yaml +++ b/fixtures/aws/cloudwatch_pass.yaml @@ -1,13 +1,20 @@ -cloudwatch: - - accessKey: - valueFrom: - secretKeyRef: - key: aws - name: access-key - secretKey: - valueFrom: - secretKeyRef: - key: aws - name: secrey-key - region: "us-east-1" - #skipTLSVerify: true +apiVersion: canaries.flanksource.com/v1 +kind: Canary +metadata: + name: cloudwatch +spec: + interval: 30 + cloudwatch: + region: "eu-west-1" + transform: + expr: | + results.MetricAlarms.filter(i, i.StateValue != 'OK' ).map(i, + { + 'name': i.MetricName, + 'icon': 'aws-cloudwatch-alarm', + 'duration': time.Since(timestamp(i.StateTransitionedTimestamp)).getMilliseconds(), + 'labels': fromAWSMap(i.Dimensions). + merge({'arn': i.AlarmArn}), + 'message': "%s (%s) %s".format([i.AlarmDescription, i.AlarmArn, fromAWSMap(i.Dimensions)]), + } + ).toJSON() diff --git a/fixtures/datasources/alertmanager_fail.yaml b/fixtures/datasources/alertmanager_fail.yaml index 07f4c9ee0..45f8cbcee 100644 --- a/fixtures/datasources/alertmanager_fail.yaml +++ b/fixtures/datasources/alertmanager_fail.yaml @@ -15,18 +15,14 @@ spec: - KubeScheduler.* exclude_filters: namespace: elastic-system - transform: - javascript: | - var out = _.map(results, function(r) { - return { - name: r.name, - labels: r.labels, - icon: 'alert', - message: r.message, - description: r.message, - status: 'unhealthy', - } - }) - JSON.stringify(out); - test: - template: "true" + transform: + expr: | + results.alerts.map(r, + { + 'name': r.name + r.fingerprint, + 'labels': r.labels, + 'icon': 'alert', + 'message': r.message, + 'description': r.message, + } + ).toJSON() diff --git a/go.mod b/go.mod index 5abc126f6..b7be68d8d 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/fergusstrange/embedded-postgres v1.24.0 github.com/flanksource/commons v1.17.0 github.com/flanksource/duty v1.0.201 - github.com/flanksource/gomplate/v3 v3.20.18 + github.com/flanksource/gomplate/v3 v3.20.19 github.com/flanksource/is-healthy v0.0.0-20231003215854-76c51e3a3ff7 github.com/flanksource/kommons v0.31.4 github.com/flanksource/postq v1.0.0 diff --git a/go.sum b/go.sum index 8240c2962..a99236571 100644 --- a/go.sum +++ b/go.sum @@ -818,8 +818,8 @@ github.com/flanksource/commons v1.17.0/go.mod h1:RDdQI0/QYC4GzicbDaXIvBPjWuQWKLz github.com/flanksource/duty v1.0.201 h1:c8r02bfuF47E2svK+qXCLHKaSqOCZZHKPj+v54eimqc= github.com/flanksource/duty v1.0.201/go.mod h1:aO1uXnT1eVtiIcicriK4brqJLmeXgbrYWtNR0H5IkLE= github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc= -github.com/flanksource/gomplate/v3 v3.20.18 h1:qYiznMxhq+Zau5iWnVzW1yDzA1deHOsmo6yldCN7JhQ= -github.com/flanksource/gomplate/v3 v3.20.18/go.mod h1:2GgHZ2vWmtDspJMBfUIryOuzJSwc8jU7Kw9fDLr0TMA= +github.com/flanksource/gomplate/v3 v3.20.19 h1:xl+XMYWXtlrO6FfU+VxwjNwX4/oBK3/soOtHRvUt2us= +github.com/flanksource/gomplate/v3 v3.20.19/go.mod h1:2GgHZ2vWmtDspJMBfUIryOuzJSwc8jU7Kw9fDLr0TMA= github.com/flanksource/is-healthy v0.0.0-20230705092916-3b4cf510c5fc/go.mod h1:4pQhmF+TnVqJroQKY8wSnSp+T18oLson6YQ2M0qPHfQ= github.com/flanksource/is-healthy v0.0.0-20231003215854-76c51e3a3ff7 h1:s6jf6P1pRfdvksVFjIXFRfnimvEYUR0/Mmla1EIjiRM= github.com/flanksource/is-healthy v0.0.0-20231003215854-76c51e3a3ff7/go.mod h1:BH5gh9JyEAuuWVP6Q5y9h43VozS0RfKyjNpM9L4v4hw= @@ -2318,22 +2318,16 @@ k8s.io/api v0.24.2/go.mod h1:AHqbSkTm6YrQ0ObxjO3Pmp/ubFF/KuM7jU+3khoBsOg= k8s.io/api v0.26.4/go.mod h1:WwKEXU3R1rgCZ77AYa7DFksd9/BAIKyOmRlbVxgvjCk= k8s.io/api v0.28.2 h1:9mpl5mOb6vXZvqbQmankOfPIGiudghwCoLl1EYfUZbw= k8s.io/api v0.28.2/go.mod h1:RVnJBsjU8tcMq7C3iaRSGMeaKt2TWEUXcpIt/90fjEg= -k8s.io/api v0.28.3 h1:Gj1HtbSdB4P08C8rs9AR94MfSGpRhJgsS+GF9V26xMM= -k8s.io/api v0.28.3/go.mod h1:MRCV/jr1dW87/qJnZ57U5Pak65LGmQVkKTzf3AtKFHc= k8s.io/apiextensions-apiserver v0.28.0 h1:CszgmBL8CizEnj4sj7/PtLGey6Na3YgWyGCPONv7E9E= k8s.io/apiextensions-apiserver v0.28.0/go.mod h1:uRdYiwIuu0SyqJKriKmqEN2jThIJPhVmOWETm8ud1VE= k8s.io/apimachinery v0.24.2/go.mod h1:82Bi4sCzVBdpYjyI4jY6aHX+YCUchUIrZrXKedjd2UM= k8s.io/apimachinery v0.26.4/go.mod h1:ats7nN1LExKHvJ9TmwootT00Yz05MuYqPXEXaVeOy5I= k8s.io/apimachinery v0.28.2 h1:KCOJLrc6gu+wV1BYgwik4AF4vXOlVJPdiqn0yAWWwXQ= k8s.io/apimachinery v0.28.2/go.mod h1:RdzF87y/ngqk9H4z3EL2Rppv5jj95vGS/HaFXrLDApU= -k8s.io/apimachinery v0.28.3 h1:B1wYx8txOaCQG0HmYF6nbpU8dg6HvA06x5tEffvOe7A= -k8s.io/apimachinery v0.28.3/go.mod h1:uQTKmIqs+rAYaq+DFaoD2X7pcjLOqbQX2AOiO0nIpb8= k8s.io/cli-runtime v0.28.0 h1:Tcz1nnccXZDNIzoH6EwjCs+7ezkUGhorzCweEvlVOFg= k8s.io/cli-runtime v0.28.0/go.mod h1:U+ySmOKBm/JUCmebhmecXeTwNN1RzI7DW4+OM8Oryas= k8s.io/client-go v0.28.2 h1:DNoYI1vGq0slMBN/SWKMZMw0Rq+0EQW6/AK4v9+3VeY= k8s.io/client-go v0.28.2/go.mod h1:sMkApowspLuc7omj1FOSUxSoqjr+d5Q0Yc0LOFnYFJY= -k8s.io/client-go v0.28.3 h1:2OqNb72ZuTZPKCl+4gTKvqao0AMOl9f3o2ijbAj3LI4= -k8s.io/client-go v0.28.3/go.mod h1:LTykbBp9gsA7SwqirlCXBWtK0guzfhpoW4qSm7i9dxo= k8s.io/component-base v0.28.1 h1:LA4AujMlK2mr0tZbQDZkjWbdhTV5bRyEyAFe0TJxlWg= k8s.io/component-base v0.28.1/go.mod h1:jI11OyhbX21Qtbav7JkhehyBsIRfnO8oEgoAR12ArIU= k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= From d2d2153267faf0b33b534013578d4acc913f3cba Mon Sep 17 00:00:00 2001 From: Moshe Immerman Date: Sun, 22 Oct 2023 22:05:05 +0300 Subject: [PATCH 6/7] chore: lint fixes --- checks/common.go | 1 - cmd/run.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/checks/common.go b/checks/common.go index 1464b1f20..7809801e2 100644 --- a/checks/common.go +++ b/checks/common.go @@ -53,7 +53,6 @@ func def(a, b string) string { // unstructure marshalls a struct to and from JSON to remove any type details func unstructure(o any) (out interface{}, err error) { - data, err := json.Marshal(o) if err != nil { return nil, err diff --git a/cmd/run.go b/cmd/run.go index 9bcb488a7..4c2c525b9 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -126,7 +126,7 @@ var Run = &cobra.Command{ if err != nil { logger.Fatalf("Failed to marshall json: %s", err) } - output.HandleOutput(string(data), outputFile) + _ = output.HandleOutput(string(data), outputFile) } logger.Infof("%d passed, %d failed in %s", passed, failed, timer) From 323d5b0a691689a0ac2306253ecce3d3bfb3e80f Mon Sep 17 00:00:00 2001 From: Moshe Immerman Date: Mon, 23 Oct 2023 08:17:54 +0300 Subject: [PATCH 7/7] chore: fix test --- fixtures/datasources/alertmanager_fail.yaml | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/fixtures/datasources/alertmanager_fail.yaml b/fixtures/datasources/alertmanager_fail.yaml index 45f8cbcee..9ca7f73a6 100644 --- a/fixtures/datasources/alertmanager_fail.yaml +++ b/fixtures/datasources/alertmanager_fail.yaml @@ -15,14 +15,14 @@ spec: - KubeScheduler.* exclude_filters: namespace: elastic-system - transform: - expr: | - results.alerts.map(r, - { - 'name': r.name + r.fingerprint, - 'labels': r.labels, - 'icon': 'alert', - 'message': r.message, - 'description': r.message, - } - ).toJSON() + transform: + expr: | + results.alerts.map(r, + { + 'name': r.name + r.fingerprint, + 'labels': r.labels, + 'icon': 'alert', + 'message': r.message, + 'description': r.message, + } + ).toJSON()