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

Allow histograms for timer metrics #66

Merged
merged 13 commits into from
Aug 3, 2017

Conversation

bakins
Copy link
Contributor

@bakins bakins commented Mar 13, 2017

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.

Copy link
Member

@grobie grobie left a 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.

@SuperQ SuperQ requested a review from juliusv May 12, 2017 12:51
@bakins
Copy link
Contributor Author

bakins commented Jun 21, 2017

Anything I can do to help on this? We've been running my fork for a while and it seems to be working fine.

@gerricom
Copy link

@bakins: Could you provide a sample configuration file? I do not understand how to map the labels with your yaml-solution... 😕

@bakins
Copy link
Contributor Author

bakins commented Jul 10, 2017

@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:

test.dispatcher.*.*.*
name="dispatcher_events_total"
processor="$1"
action="$2"
outcome="$3"
job="test_dispatcher"

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

@gerricom
Copy link

@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.

@juliusv
Copy link
Member

juliusv commented Jul 17, 2017

@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.

Copy link
Member

@juliusv juliusv left a 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 {

Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

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

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"`,
Copy link
Member

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" {
Copy link
Member

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"),
Copy link
Member

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.

@bakins
Copy link
Contributor Author

bakins commented Jul 26, 2017

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)
Copy link
Member

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":
Copy link
Member

Choose a reason for hiding this comment

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

"histogram" -> timerTypeHistogram?

@grobie
Copy link
Member

grobie commented Jul 27, 2017

Could you add some tests for the new feature?

@bakins
Copy link
Contributor Author

bakins commented Jul 31, 2017

Added basic config tests.

@drawks
Copy link
Contributor

drawks commented Jul 31, 2017

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.

Copy link
Member

@juliusv juliusv left a 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
Copy link
Member

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 {
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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)

Copy link
Contributor Author

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.

@bakins
Copy link
Contributor Author

bakins commented Aug 1, 2017

@juliusv Addressed your comments.

@drawks I can split this up if that's the consensus. YAML change would need to be merged first, IMO. In #19 it seems people did not want to mangle the current config format any more. I guess splitting or not is up to @juliusv ?

@bakins
Copy link
Contributor Author

bakins commented Aug 1, 2017

Added initial docs.

@juliusv
Copy link
Member

juliusv commented Aug 3, 2017

@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 juliusv merged commit aeab290 into prometheus:master Aug 3, 2017
@bakins
Copy link
Contributor Author

bakins commented Aug 3, 2017

@juliusv thanks. As with most things, this PR started very simple...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants