Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Initial Kafka output metrics #162

Merged
merged 13 commits into from
May 6, 2017
Merged

Initial Kafka output metrics #162

merged 13 commits into from
May 6, 2017

Conversation

GuillaumeBailey
Copy link
Contributor

No description provided.

@GuillaumeBailey GuillaumeBailey requested a review from datoug April 20, 2017 17:50
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.07%) to 68.342% when pulling 3ccb9f5 on kfcOutMetric into c1a8a56 on master.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling bc04a80 on kfcOutMetric into ** on master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling b3cd954 on kfcOutMetric into ** on master**.

@@ -72,3 +71,4 @@ import:
- package: github.com/Shopify/sarama
version: ^1.11.0
repo: http://github.com/Shopify/sarama
- package: github.com/rcrowley/go-metrics
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you give a short summary of:

  • the value this new dependency brings in (that we don't already have)
  • why is that important to us
  • why is this the right way, going forward, say compared to https://github.com/uber-go/tally

Unless there is a strong reason to pull in this dependency, I am not inclined to go down this road.
uber-go/tally is close to what we already have and provides the missing features on top of it.

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 strong reason is that the Kafka client library depends on this to provide metrics, hence we don't get a choice. Either this, or no Kafka metrics.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 68.621% when pulling 43c7e1f on kfcOutMetric into 226fb2c on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.8%) to 68.135% when pulling 7a86f0f on kfcOutMetric into 226fb2c on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 67.873% when pulling 8f593db on kfcOutMetric into ed72be8 on master.

closeCh <-chan struct{},
) gometrics.Registry {
// Make a new registy and give it to the caller. This allows the exporters to operate independently
registry := gometrics.NewRegistry()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be cleaner to actually pass in the 'gometrics.Registry' as an argument to "NewGoMetricsExporter" .. leaving it to the caller to do 'gometrics.NewRegistry', etc.

The purpose of this code should only be an "exporter", in that you give it the 'gometrics.Registry' and the metrics map .. and it would export them to m3.

Copy link
Contributor

Choose a reason for hiding this comment

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

I might also argue, this should not be part of the "common/metrics" package .. but I'll leave it to you if you want to reconsider moving this (gometrics-exporter) out as a separate module, etc.

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 common/metrics package thing might make sense. Let's talk in person.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like making it a package also means that I have to make a new directory, which will contain just this one file.

// goMetricsExporter allows an rcrowley/go-metrics registry to be
// periodically exported to the Cherami metrics system
type goMetricsExporter struct {
c Client
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a "metric" client .. I think 'm' (or perhaps m3) would be more appropriate than 'c':

r.c.AddCounter(r.scope, metricID, count-lastVal)

// Calculate the time to provide the delayToFirstLogDump in export()
lastLogDump: time.Now().Add(-1 * delayBetweenLogDumps).Add(delayToFirstLogDump),
}
go r.run()
Copy link
Contributor

Choose a reason for hiding this comment

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

We tend to use the (New, Start, Stop) pattern in a lot of 'modules' in our code. You might want to consider that .. where 'Start' does a 'go r.run()' and 'Stop' closes the (internal) closeCh, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm trying to keep this quite simple on the calling side, i.e. just an init and it handles itself, i.e. magic. I can see the argument in following an established pattern, but that seems like it just adds a few more lines of code on the caller side, and it's speculative (i.e. it presumes that the caller would want to stop the metric reporting at some time other than the natural end of its life). Let's talk in-person.

}

func (r *goMetricsExporter) export() {
r.registry.Each(func(name string, i interface{}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure I understand this. So for every metric in the 'go-metrics' registry, we emit into m3? This would mean, we are expected to read in every metric, right?

Wouldn't it be better if probably we only pulled in metrics that we have listed in our metrics map that we pass in with 'New' .. that way we can ignore some metrics that we aren't interested in, etc?

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 general problem here is that any metrics solution has a pattern of local-reporting->aggregation->remote-reporting, but rcrowley metrics and m3 both want to do the aggregation step. So I have to de-aggregate from rcrowley to allow m3 to aggregate.

Regarding the Each() call, this is just saying that I get a stab at handling all metrics that Sarama reports through rcrowley/go-metrics. I don't handle all of them. The unhandled ones are periodically (but minimally) reported in the unexported metrics section. I include that unexported reporting, since there may come a time where those metrics are useful for some kind of debugging. Right now, it's a bunch of broker-specific metrics, which I fear will exceed the cardinality limits that M3 imposes on us. See https://godoc.org/github.com/Shopify/sarama

For the handled metrics, I need to de-aggregate them in various ways, and then map them to the equivalent M3 stuff.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 67.661% when pulling 47ec799 on kfcOutMetric into ed72be8 on master.

}

// Run runs the exporter. It blocks until Stop() is called, so it should probably be run in a go-routine
func (r *GoMetricsExporter) Run() {
Copy link
Contributor

@kirg kirg May 5, 2017

Choose a reason for hiding this comment

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

having the caller do a "go Run()" seems to unnecessarily expose internal behaviour, etc. I would (again) suggest including a "Start()" method that does a "go r.run()" internally. That complements the "Stop()" you have, too.

@GuillaumeBailey GuillaumeBailey merged commit 00980c0 into master May 6, 2017
@GuillaumeBailey GuillaumeBailey deleted the kfcOutMetric branch May 6, 2017 17:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants