-
Notifications
You must be signed in to change notification settings - Fork 188
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
Adds Prometheus export (requests and variant eval) #221
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package config | |
import ( | ||
"testing" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
|
@@ -29,3 +30,27 @@ func TestSetupStatsd(t *testing.T) { | |
}) | ||
Config.StatsdEnabled = false | ||
} | ||
|
||
func TestSetupPrometheus(t *testing.T) { | ||
prometheus.DefaultRegisterer = prometheus.NewRegistry() | ||
Config.PrometheusEnabled = false | ||
setupPrometheus() | ||
assert.Nil(t, Global.Prometheus.EvalCounter) | ||
Config.PrometheusEnabled = true | ||
setupPrometheus() | ||
assert.NotNil(t, Global.Prometheus.EvalCounter) | ||
assert.NotNil(t, Global.Prometheus.RequestCounter) | ||
assert.Nil(t, Global.Prometheus.RequestHistogram) | ||
Config.PrometheusEnabled = false | ||
} | ||
|
||
func TestSetupPrometheusWithLatencies(t *testing.T) { | ||
prometheus.DefaultRegisterer = prometheus.NewRegistry() | ||
Config.PrometheusEnabled = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you reset the configuration after the test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, no problem |
||
Config.PrometheusIncludeLatencyHistogram = true | ||
setupPrometheus() | ||
assert.NotNil(t, Global.Prometheus.EvalCounter) | ||
assert.NotNil(t, Global.Prometheus.RequestCounter) | ||
assert.NotNil(t, Global.Prometheus.RequestHistogram) | ||
Config.PrometheusEnabled = false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,13 @@ var Config = struct { | |
StatsdAPMPort string `env:"FLAGR_STATSD_APM_PORT" envDefault:"8126"` | ||
StatsdAPMServiceName string `env:"FLAGR_STATSD_APM_SERVICE_NAME" envDefault:"flagr"` | ||
|
||
// PrometheusEnabled - enable prometheus metrics export | ||
PrometheusEnabled bool `env:"FLAGR_PROMETHEUS_ENABLED" envDefault:"false"` | ||
// PrometheusPath - set the path on which prometheus metrics are available to scrape | ||
PrometheusPath string `env:"FLAGR_PROMETHEUS_PATH" envDefault:"/metrics"` | ||
// PrometheusIncludeLatencyHistogram - set whether Prometheus should also export a histogram of request latencies (this increases cardinality significantly) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1, good to know |
||
PrometheusIncludeLatencyHistogram bool `env:"FLAGR_PROMETHEUS_INCLUDE_LATENCY_HISTOGRAM" envDefault:"false"` | ||
|
||
// RecorderEnabled - enable data records logging | ||
RecorderEnabled bool `env:"FLAGR_RECORDER_ENABLED" envDefault:"false"` | ||
// RecorderType - the pipeline to log data records, e.g. Kafka | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,6 +174,7 @@ var logEvalResult = func(r *models.EvalResult, dataRecordsEnabled bool) { | |
} | ||
|
||
logEvalResultToDatadog(r) | ||
logEvalResultToPrometheus(r) | ||
|
||
if !config.Config.RecorderEnabled || !dataRecordsEnabled { | ||
return | ||
|
@@ -199,6 +200,19 @@ var logEvalResultToDatadog = func(r *models.EvalResult) { | |
) | ||
} | ||
|
||
var logEvalResultToPrometheus = func(r *models.EvalResult) { | ||
if config.Global.Prometheus.EvalCounter == nil { | ||
return | ||
} | ||
config.Global.Prometheus.EvalCounter.WithLabelValues( | ||
util.SafeStringWithDefault(r.EvalContext.EntityType, "null"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not very familiar with the convention of prometheus lable values, does it need to have a name in the value? For example,
Otherwise, how can we know if it's variantID or flagID, or something else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zhouzhuojie that's a bit confusing, yeah - the labels are coded in when the Counter is created here: https://github.com/checkr/flagr/pull/221/files#diff-091ace02b49a46f55f2586cfec89a160R96 |
||
util.SafeStringWithDefault(r.FlagID, "null"), | ||
util.SafeStringWithDefault(r.VariantID, "null"), | ||
util.SafeStringWithDefault(r.VariantKey, "null"), | ||
).Inc() | ||
|
||
} | ||
|
||
var evalSegment = func( | ||
flagID uint, | ||
evalContext models.EvalContext, | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, just pushed