Skip to content

Commit

Permalink
chore: use default prometheus url for checks (#1386)
Browse files Browse the repository at this point in the history
* chore: use default prometheus url for checks

* chore: add prometheus option in helm chart

* Update root.go

---------

Co-authored-by: Moshe Immerman <[email protected]>
  • Loading branch information
yashmehrotra and moshloop authored Oct 30, 2023
1 parent 1602670 commit 88b0423
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ spec:
{{- range $k, $v := .Values.extraArgs}}
- --{{$k}}={{$v}}
{{- end }}

{{- if .Values.upstream.enabled }}
- --agent-name={{ .Values.upstream.agentName }}
{{- if .Values.upstream.host }}
Expand All @@ -159,6 +158,9 @@ spec:
- --upstream-insecure-skip-verify=true
{{- end}}
{{- end }}
{{- if ne .Values.prometheusURL "" }}
- --prometheus={{ .Values.prometheusURL }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
livenessProbe:
Expand Down
3 changes: 3 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ nameOverride: ""
pingMode: "unprivileged"
allowPrivilegeEscalation: false

# Prometheus URL
prometheusURL: ""

data:
defaultSearchWindow: 1h
cacheTimeoutDays: 90
Expand Down
9 changes: 7 additions & 2 deletions checks/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ func (c *PrometheusChecker) Check(ctx *context.Context, extConfig external.Check
results = append(results, result)

//nolint:staticcheck
if check.Host != "" && check.URL == "" {
check.URL = check.Host
if check.Host != "" {
return results.Failf("host field is deprecated, use url field instead")
}

// Use global prometheus url if check's url is empty
if check.URL == "" {
check.URL = prometheus.PrometheusURL
}

connection, err := ctx.GetConnection(check.Connection)
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/flanksource/canary-checker/pkg/cache"
"github.com/flanksource/canary-checker/pkg/db"
"github.com/flanksource/canary-checker/pkg/jobs/canary"
"github.com/flanksource/canary-checker/pkg/prometheus"
"github.com/flanksource/canary-checker/pkg/runner"
"github.com/flanksource/canary-checker/pkg/telemetry"
"github.com/flanksource/commons/logger"
Expand Down Expand Up @@ -42,7 +43,6 @@ var Root = &cobra.Command{
var (
httpPort = 8080
publicEndpoint = "http://localhost:8080"
prometheusURL string
pushServers, pullServers []string
sharedLibrary []string
exposeEnv bool
Expand Down Expand Up @@ -71,7 +71,7 @@ func ServerFlags(flags *pflag.FlagSet) {
flags.StringSliceVar(&pushServers, "push-servers", []string{}, "push check results to multiple canary servers")
flags.StringSliceVar(&pullServers, "pull-servers", []string{}, "push check results to multiple canary servers")
flags.StringVar(&runner.RunnerName, "name", "local", "Server name shown in aggregate dashboard")
flags.StringVar(&prometheusURL, "prometheus", "", "URL of the prometheus server that is scraping this instance")
flags.StringVar(&prometheus.PrometheusURL, "prometheus", "", "URL of the prometheus server that is scraping this instance")
flags.StringVar(&db.ConnectionString, "db", "DB_URL", "Connection string for the postgres database. Use embedded:///path/to/dir to use the embedded database")
flags.IntVar(&db.DefaultExpiryDays, "cache-timeout", 90, "Cache timeout in days")
flags.StringVarP(&cache.DefaultWindow, "default-window", "", "1h", "Default search window")
Expand Down
2 changes: 1 addition & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func serve() {
push.AddServers(pushServers)
go push.Start()

runner.Prometheus, _ = prometheus.NewPrometheusAPI(prometheusURL)
runner.Prometheus, _ = prometheus.NewPrometheusAPI(prometheus.PrometheusURL)

if debug {
logger.Infof("Starting pprof at /debug")
Expand Down
2 changes: 2 additions & 0 deletions pkg/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type PrometheusClient struct {
v1.API
}

var PrometheusURL string

func (p PrometheusClient) GetHistogramQuantileLatency(percentile, checkKey, duration string) (latency float64, err error) {
modelValue, _, err := p.Query(context.TODO(), fmt.Sprintf("histogram_quantile(%v, sum(rate(canary_check_duration_bucket{key='%v'}[%v])) by (le))", percentile, checkKey, duration), time.Now())
if err != nil {
Expand Down

0 comments on commit 88b0423

Please sign in to comment.