-
Notifications
You must be signed in to change notification settings - Fork 233
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
Allow histograms for timer metrics #66
Conversation
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.
LGTM, but @juliusv should take a look as maintainer.
Anything I can do to help on this? We've been running my fork for a while and it seems to be working fine. |
@bakins: Could you provide a sample configuration file? I do not understand how to map the labels with your yaml-solution... 😕 |
@gerricom sorry for the delay. This PR was to start the discussion. I can add documentation if people think this is useful. Example: "normal" config:
YAML version of this: mappings:
- match: test.dispatcher.*.*.*
labels:
name: "dispatcher_events_total"
processor: "$1"
action: "$2"
outcome: "$3"
job: "test_dispatcher" To enable histograms for a single mapping: mappings:
- match: test.dispatcher.*.*.*
timer_type: histogram
labels:
name: "dispatcher_events_total"
... To enable histograms by default: defaults:
timer_type: histogram |
@bakins No problem! Thanks for the example. I must have simply missed the match parameter in the YAML configuration. So after playing around with it: This looks quite useful and I'd like to see this merged. Changing over to the YAML configuration style is very easily done and straightforward. Histograms seem to work as expected. |
@bakins Sorry for ignoring this for so long. I think in general changing this to YML is a great idea, to get rid of yet another custom language. Taking a closer look now. |
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.
Looks pretty good in general. I left some comments. Documentation would be great, as you said.
I think sometime in the future we could maybe even drop the custom config format.
mapper.go
Outdated
|
||
mappingsCount.Set(float64(len(parsedMappings))) | ||
|
||
return nil | ||
} | ||
|
||
func (m *metricMapper) initFromYamlString(fileContents string) error { | ||
|
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.
style: avoid empty lines at the beginning of a function.
mapper.go
Outdated
|
||
mappingsCount.Set(float64(len(parsedMappings))) | ||
|
||
return nil | ||
} | ||
|
||
func (m *metricMapper) initFromYamlString(fileContents string) error { |
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.
style: Yaml -> YAML (https://github.com/golang/go/wiki/CodeReviewComments#initialisms)
mapper_test.go
Outdated
@@ -148,7 +148,7 @@ func TestMetricMapper(t *testing.T) { | |||
test.bar | |||
name="name_bar" | |||
label="foo" | |||
|
|||
test.foo | |||
name="name_foo" | |||
label="bar"`, |
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.
Would be great to have some YAML-based tests here of course.
exporter.go
Outdated
timerType = b.mapper.Defaults.TimerType | ||
} | ||
|
||
if timerType == "histogram" { |
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.
As far as I can see, the timer type string isn't validated at config load time, but probably should be?
And then I'd change this to a switch timerType {...}
here with a default case that panics. Could be good to extract the strings into named constants too.
exporter.go
Outdated
|
||
if timerType == "histogram" { | ||
histogram := b.Histograms.Get( | ||
b.suffix(metricName, "timer"), |
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.
Hmm, I think we should only suffix metrics that don't have an explicitly mapped metric name (if there is a mapping, use exactly the metric name provided in the mapping). But I see we also do that for gauges and counters already. So that should probably be fixed in a separate change.
This now validates the timer type when it reads the configuration. Also addresses a couple of the style issues. Let me know what you think. I'll add docs to this PR after we think the code looks good. |
mapper.go
Outdated
func (m *metricMapper) initFromYAMLString(fileContents string) error { | ||
var n metricMapper | ||
|
||
fmt.Println(fileContents) |
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.
Remove debug Println here and Printf below.
exporter.go
Outdated
log.Errorf(regErrF, metricName, err) | ||
conflictingEventStats.WithLabelValues("timer").Inc() | ||
switch t { | ||
case "histogram": |
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.
"histogram"
-> timerTypeHistogram
?
Could you add some tests for the new feature? |
Added basic config tests. |
This looks like a very nice change. One critique of mine would be to separate the conversion to yaml config and the addition of histograms as two separate PRs. I'm a big fan of both changes though personally. |
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.
Couple of last nits and then let's ship this :)
mapper.go
Outdated
return fmt.Errorf("invalid match: %s", currentMapping.Match) | ||
} | ||
|
||
// check that label is correct |
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.
nit: start all comments upper-cased, end with period.
mapper.go
Outdated
// check that label is correct | ||
for k, v := range currentMapping.Labels { | ||
label := fmt.Sprintf("%s=%q", k, v) | ||
if len(labelLineRE.FindStringSubmatch(label)) != 3 { |
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.
It is a bit complicated to first make a k=v string out of this and then match the entire string against labelLineRE
. The label value can be anything, so it would be better to just check whether the label name (k
) matches identifierRE
.
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.
Not sure why I did it this way. fixing.
mapper.go
Outdated
} | ||
|
||
if _, ok := currentMapping.Labels["name"]; !ok { | ||
return fmt.Errorf("Line %d: metric mapping didn't set a metric name", i) |
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.
"Line" -> "line" (start error strings lower-cased)
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.
FWIW, errors in updateMapping
in this same file use uppercase "L". I'll change my to lower.
Added initial docs. |
@bakins I think it's fine to just merge it as it is this time (YAML + histograms combined), although in the future I would recommend separating changes into multiple PRs. Thanks for all the patience and sorry for being so slow here! I'll merge it and then we can still do followup cleanups as needed. |
@juliusv thanks. As with most things, this PR started very simple... |
Based on comments in #19 this allows the use of a YAML config file that allows setting histograms for timer metrics per mapping or as the default timer type. Previous behavior is the same when using the "old" config file format.
This is fairly rough and could probably be cleaner. I did the minimum possible to enable histograms as an experiment. Consider this enough to start a conversation.