Skip to content

Commit

Permalink
chore: remove unused functions (#2260)
Browse files Browse the repository at this point in the history
* chore: lint fixes
  • Loading branch information
adityathebe authored Oct 18, 2024
1 parent 5eea1f5 commit 03b21f7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 103 deletions.
2 changes: 1 addition & 1 deletion checks/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *AlertManagerChecker) Check(ctx *context.Context, extConfig external.Che
Filter: filters,
})
if err != nil {
results.ErrorMessage(fmt.Errorf("Error fetching from alertmanager: %v", err))
results.ErrorMessage(fmt.Errorf("error fetching from alertmanager: %v", err))
return results
}

Expand Down
10 changes: 1 addition & 9 deletions checks/database_backup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package checks

import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"

"github.com/flanksource/canary-checker/api/context"
Expand Down Expand Up @@ -52,13 +51,6 @@ func (c *DatabaseBackupChecker) Check(ctx *context.Context, extConfig external.C
case check.GCP != nil:
return GCPDatabaseBackupCheck(ctx, check)
default:
return FailDatabaseBackupParse(ctx, check)
return pkg.Invalid(check, ctx.Canary, "GCP details not provided in check")
}
}

func FailDatabaseBackupParse(ctx *context.Context, check v1.DatabaseBackupCheck) pkg.Results {
result := pkg.Fail(check, ctx.Canary)
var results pkg.Results
results = append(results, result)
return results.ErrorMessage(errors.New("Could not parse databaseBackup input"))
}
7 changes: 3 additions & 4 deletions checks/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func (c *ElasticsearchChecker) Check(ctx *context.Context, extConfig external.Ch
es.Search.WithIndex(check.Index),
es.Search.WithBody(body),
)

if err != nil {
return results.ErrorMessage(err)
}
Expand All @@ -65,10 +64,10 @@ func (c *ElasticsearchChecker) Check(ctx *context.Context, extConfig external.Ch
var e map[string]any
if err := json.NewDecoder(res.Body).Decode(&e); err != nil {
return results.ErrorMessage(
fmt.Errorf("Error parsing the response body: %s", err),
fmt.Errorf("error parsing the response body: %s", err),
)
} else {
return results.ErrorMessage(fmt.Errorf("Error from elasticsearch [%s]: %v, %v",
return results.ErrorMessage(fmt.Errorf("error from elasticsearch [%s]: %v, %v",
res.Status(),
e["error"].(map[string]any)["type"],
e["error"].(map[string]any)["reason"],
Expand All @@ -82,7 +81,7 @@ func (c *ElasticsearchChecker) Check(ctx *context.Context, extConfig external.Ch
var r map[string]any
if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
return results.ErrorMessage(
fmt.Errorf("Error parsing the response body: %s", err),
fmt.Errorf("error parsing the response body: %s", err),
)
}

Expand Down
4 changes: 0 additions & 4 deletions checks/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,11 @@ func NewNamespaceChecker() *NamespaceChecker {
// Returns check result and metrics
func (c *NamespaceChecker) Run(ctx *context.Context) pkg.Results {
logger.Warnf("namespace check is deprecated. Please use the kubernetes resource check")
var err error
var results pkg.Results
for _, conf := range ctx.Canary.Spec.Namespace {
if c.k8s == nil {
c.k8s = ctx.Kubernetes()
c.ctx = ctx
if err != nil {
return pkg.SetupError(ctx.Canary, err)
}
}
results = append(results, c.Check(c.ctx, conf)...)
}
Expand Down
52 changes: 0 additions & 52 deletions checks/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@ package checks
import (
"fmt"
"sync"
"time"

"github.com/flanksource/canary-checker/api/external"
"github.com/flanksource/canary-checker/pkg"
)

func Error(check external.Check, err error) *pkg.CheckResult {
return &pkg.CheckResult{
Check: check,
Pass: false,
Invalid: true,
Error: err.Error(),
}
}

func Failf(check external.Check, msg string, args ...interface{}) *pkg.CheckResult {
return &pkg.CheckResult{
Check: check,
Expand All @@ -27,48 +17,6 @@ func Failf(check external.Check, msg string, args ...interface{}) *pkg.CheckResu
}
}

// TextFailf used for failure in case of text based results
func TextFailf(check external.Check, textResults bool, msg string, args ...interface{}) *pkg.CheckResult {
if textResults {
return &pkg.CheckResult{
Check: check,
Pass: false,
Invalid: false,
DisplayType: "Text",
Message: fmt.Sprintf(msg, args...),
}
}
return Failf(check, msg, args...)
}
func Success(check external.Check, start time.Time) *pkg.CheckResult {
return &pkg.CheckResult{
Check: check,
Pass: true,
Invalid: false,
Duration: time.Since(start).Milliseconds(),
}
}

func Successf(check external.Check, start time.Time, textResults bool, msg string, args ...interface{}) *pkg.CheckResult {
if textResults {
return &pkg.CheckResult{
Check: check,
Pass: true,
DisplayType: "Text",
Invalid: false,
Message: fmt.Sprintf(msg, args...),
Duration: time.Since(start).Milliseconds(),
}
}
return &pkg.CheckResult{
Check: check,
Pass: true,
Invalid: false,
Message: fmt.Sprintf(msg, args...),
Duration: time.Since(start).Milliseconds(),
}
}

func Passf(check external.Check, msg string, args ...interface{}) *pkg.CheckResult {
return &pkg.CheckResult{
Check: check,
Expand Down
41 changes: 8 additions & 33 deletions pkg/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,20 @@ import (

type Results []*CheckResult

func Fail(check external.Check, canary v1.Canary) *CheckResult {
return &CheckResult{
Check: check,
Data: map[string]interface{}{
"results": make(map[string]interface{}),
},
Start: time.Now(),
Pass: false,
Canary: canary,
}
}

func SetupError(canary v1.Canary, err error) Results {
var results Results
for _, check := range canary.Spec.GetAllChecks() {
results = append(results, &CheckResult{
Start: time.Now(),
Pass: false,
Invalid: true,
Error: err.Error(),
Check: check,
Data: map[string]interface{}{
"results": make(map[string]interface{}),
},
})
}
return results
}

func Invalid(check external.Check, canary v1.Canary, reason string) Results {
return Results{&CheckResult{
Start: time.Now(),
Pass: false,
Error: reason,
Check: check,
Start: time.Now(),
Pass: false,
Invalid: true,
Error: reason,
Check: check,
Data: map[string]interface{}{
"results": make(map[string]interface{}),
},
Canary: canary,
}}
}

func Success(check external.Check, canary v1.Canary) *CheckResult {
result := New(check, canary)
result.Pass = true
Expand Down Expand Up @@ -162,10 +135,12 @@ func (r Results) Failf(msg string, args ...interface{}) Results {
r[0].Failf(msg, args...)
return r
}

func (r Results) Invalidf(msg string, args ...interface{}) Results {
r[0].Invalidf(msg, args...)
return r
}

func (r Results) WithError(err error) Results {
r[0].ErrorObject = err
return r
Expand Down

0 comments on commit 03b21f7

Please sign in to comment.