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

chore: use default prometheus url for checks #1386

Merged
merged 4 commits into from
Oct 30, 2023
Merged
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
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add this as a chart value as well ?

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 @@ -80,7 +80,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
Loading