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

metrics/influx: fix the package implementation #369

Merged
merged 5 commits into from
Oct 12, 2016

Conversation

kpacha
Copy link
Contributor

@kpacha kpacha commented Oct 2, 2016

As reviewing the #367 I've found all the implementations of the metrics used the labels as fields, so I generalized the hack for gauges and histograms too.

Also, the histogram implementation wasn't aggregating the results, so they couldn't be stored properly in the backend (same problem as in #367, because influx accepts just one combination of fields for a given combination of tags and timestamp).

Finally, I added 3 tests where you can see how the messages are being sent over the wire.

Copy link
Member

@peterbourgon peterbourgon left a comment

Choose a reason for hiding this comment

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

Brilliant, thank you! I'm no Influx guru so I really appreciate you taking the time to correct my misunderstanding :) Just one doc comment update and I'm happy to merge this in.

var p *influxdb.Point
p, err = influxdb.NewPoint(name, in.tags, fields, now)
fields := map[string]interface{}{"value": last(values)}
p, err = influxdb.NewPoint(name, tags, fields, now)
Copy link
Member

Choose a reason for hiding this comment

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

Can you please update the comment on the Influx struct to reflect the new role of fields and tags?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Let's see what do you think about it...

BTW, very nice project!!!

@peterbourgon
Copy link
Member

execute the new influx tests as examples

Why? What is the advantage?

@kpacha
Copy link
Contributor Author

kpacha commented Oct 11, 2016

aren't the examples automatically linked to the documentation? since those tests were added in order to give a better explanation about how the influx metrics work, I believe adding them in the doc will help a lot.

Copy link
Member

@peterbourgon peterbourgon left a comment

Choose a reason for hiding this comment

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

OK, moving to Example tests makes sense to me. Just a few more small things to clean up :) Thanks for bearing with me!

// may be mutated via With functions. Actual metric values are provided as
// Influx tags are attached to the Influx object, can be given to each
// metric at construction and can be updated anytime via With function. Influx fields
// are mapped to Go kit label values directly by this collector. Actual metric values are provided as
// fields with specific names depending on the metric.
Copy link
Member

Choose a reason for hiding this comment

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

Please wrap comments at 80col

@@ -31,6 +30,33 @@ func TestCounter(t *testing.T) {
}
}

func ExampleCounter() {
Copy link
Member

Choose a reason for hiding this comment

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

Best not to mix Examples and real Tests in the same file. In the past I've stuck all the examples in an example_test.go file, can we do the same here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. I'll move them to the influxexample_test.go file

Copy link
Member

Choose a reason for hiding this comment

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

Please just example_test.go in the appropriate directory.

// influx_counter,a=b count=60
// influx_counter,a=b,error=true count=1
// influx_counter,a=b,error=false count=2
}
Copy link
Member

Choose a reason for hiding this comment

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

Since this is now an Example, the test runner will take care of validating the output; there's no need for a separate step with the regexes. So,

in := New(...)
counter := in.NewCounter("...")
// etc.

client := &bufWriter{}
in.WriteTo(client)
io.Copy(os.Stdout, client.buf)

// Output:
// foo
// bar
// baz

should be sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the result is not deterministic because it adds a timestamp at the end of every line. That's why I used the regex extraction.

Copy link
Member

Choose a reason for hiding this comment

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

Then why is the example not failing? Is it not being run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't fail because it extracts the timestamp before printing each line. so, instead of printing influx_counter,a=b count=60 1234567891234567890 (sample timestamp), it just prints influx_counter,a=b count=60.

If any of the given patterns doesn't match, it also prints an error message and the example fails

Copy link
Member

Choose a reason for hiding this comment

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

Ah! That's a bit tricky, but I understand now. Thanks.

fmt.Println(match[1])
}
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

re: above comments, I think this whole function can now be removed.

Copy link
Member

Choose a reason for hiding this comment

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

With the clarifications in the previous comment, this can stay :)

@kpacha
Copy link
Contributor Author

kpacha commented Oct 11, 2016

The branch now is including the changes you requested:

  • Comment line fixed
  • Examples in a dedicated file

Let me know if there is something else we could improve

@peterbourgon
Copy link
Member

Nice! Thank you very much for the contribution.

@peterbourgon peterbourgon merged commit 9fa4a1d into go-kit:master Oct 12, 2016
@kpacha kpacha deleted the fix_influxdb_metrics branch October 12, 2016 12:38
jamesgist pushed a commit to jamesgist/kit that referenced this pull request Nov 1, 2024
metrics/influx: fix the package implementation
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.

2 participants