Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Add graphite support #114

Merged
merged 4 commits into from
Mar 6, 2020
Merged

Add graphite support #114

merged 4 commits into from
Mar 6, 2020

Conversation

yazgoo
Copy link
Contributor

@yazgoo yazgoo commented Jan 22, 2020

This allows to specify a graphite output via the following config:

  graphite-host = "localhost"
  graphite-port = 2003

This translates prometheus labels into a graphite metric path.

@lightbend-cla-validator

Hi @yazgoo,

Thank you for your contribution! We really value the time you've taken to put this together.

Before we proceed with reviewing this pull request, please sign the Lightbend Contributors License Agreement:

http://www.lightbend.com/contribute/cla

@lightbend-cla-validator

Hi @yazgoo,

Thank you for your contribution! We really value the time you've taken to put this together.

Before we proceed with reviewing this pull request, please sign the Lightbend Contributors License Agreement:

http://www.lightbend.com/contribute/cla

@yazgoo
Copy link
Contributor Author

yazgoo commented Jan 22, 2020

I signed the CLA

@seglo
Copy link
Owner

seglo commented Jan 24, 2020

Thanks @yazgoo. I'll review this shortly.

Copy link
Owner

@seglo seglo left a comment

Choose a reason for hiding this comment

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

Thanks a lot for diving into this. This project was always meant as a Prometheus project, but I don't have any particular objection to supporting Graphite. Instead of mixing the implementation into the PrometheusEndpointSink I would ask that you create a new GraphiteEndpointSink. Since there will now be two available sinks some thought should be given to the design on how to plug and play one (or both?) if it makes sense. We should also try to have at least testing in place, maybe even some integration tests. Are you open to iterating on this further?

@yazgoo
Copy link
Contributor Author

yazgoo commented Jan 28, 2020

Thanks @seglo, 👌 for iterating on this.

@seglo seglo added enhancement New feature or request refactor Refactor of project labels Jan 28, 2020
👌 graphite: add periodInSecond conf and stop

🎨 remove graphite bridge

🥅 handle exceptions
@yazgoo yazgoo force-pushed the master branch 7 times, most recently from 6565a3d to d906ed7 Compare January 30, 2020 08:41
@yazgoo
Copy link
Contributor Author

yazgoo commented Jan 30, 2020

@seglo PR ready for review

creating one metric sink dedicated to graphite
Copy link
Owner

@seglo seglo left a comment

Choose a reason for hiding this comment

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

The reporter abstraction is looking really good! I made some comments about how I would like to see a reporter's creation more config generated.

Please make some updates to the README too. You don't need to mention Graphite with every mention of Prometheus. A separate section would be alright. You should also update the configuration section in the "Run Standalone" section to document graphite config.

Do you use the Helm chart for deployment to Kubernetes? If so, can you update that as well? If not, I'll do it.

def apply(metricWhitelist: List[String], clusterGlobalLabels: ClusterGlobalLabels,
graphiteConfig: Option[GraphiteConfig]): MetricsSink = {
Try(new GraphiteEndpointSink(metricWhitelist, clusterGlobalLabels, graphiteConfig))
.fold(t => throw new Exception("Could not create Prometheus Endpoint", t), sink => sink)
Copy link
Owner

Choose a reason for hiding this comment

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

Update failure message

}
}

def metricNameToGraphiteMetricName(metricValue: MetricValue): String = {
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure I understand what's happening here. The metrics are already snakecase. Can you add a scaladoc comment with an example of the conversion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added @example

Copy link
Owner

Choose a reason for hiding this comment

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

I see.

Metrics.definitions, appConfig.metricWhitelist, appConfig.clustersGlobalLabels(), server, CollectorRegistry.defaultRegistry
))
),
KafkaClusterManager.NamedCreator(
Copy link
Owner

Choose a reason for hiding this comment

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

I'd prefer to only create the graphite-lag-reporter if its config exists, otherwise it seems like a waste to create it at all and report all metrics to it.

@@ -18,6 +18,11 @@ import scala.util.Try
object AppConfig {
Copy link
Owner

Choose a reason for hiding this comment

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

Now that we have more than 1 reporter lets generate them based on configuration and only create them when necessary. Example application.conf:

kafka-lag-exporter {
  reporters {
	prometheus {
      port = 8000
    }
    graphite {
      host = "foo"
      port = 9999
    }
  }
}

@@ -134,6 +147,7 @@ final case class AppConfig(pollInterval: FiniteDuration, lookupTableSize: Int, p
|Prometheus metrics whitelist: [${metricWhitelist.mkString(", ")}]
Copy link
Owner

Choose a reason for hiding this comment

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

We can rename this to "metrics whitelist"

Copy link
Owner

Choose a reason for hiding this comment

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

Add an indented section for prometheus like you did for Graphite

Prometheus:
  Port: $prometheusPort

}
}

override def remove(m: RemoveMetric): Unit = {
Copy link
Owner

Choose a reason for hiding this comment

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

This is used in prometheus to unpublish a metric for a consumer group that disappears. If a consumer group isn't reported for awhile and we don't push metrics for it to Graphite, what would the Graphite metric for that now removed consumed group look like? Do we need to worry about unpublishing metrics?

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 don't think in graphite you have to unregister a metric since graphite is push based.
When the max retention is reached the metric will be totally removed by graphite itself.

for (host <- Try(c.getString("graphite-host"));
port <- Try(c.getInt("graphite-port")),
) yield GraphiteConfig(
host, port, Try(c.getString("graphite-prefix")).toOption)).toOption
val pollInterval = c.getDuration("poll-interval").toScala
val lookupTableSize = c.getInt("lookup-table-size")
val port = c.getInt("port")
Copy link
Owner

Choose a reason for hiding this comment

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

Support getting the prometheus port from here, and from the new report configuration section I mentioned above. Use kafka-lag-exporter.port as the default and override with kafka-lag-exporter.prometheus.port if it exists. This will maintain backwards compatibility.

Please update the reference.conf to include the kafka-lag-exporter.reporters.prometheus section.

@yazgoo yazgoo force-pushed the master branch 3 times, most recently from 40da0e9 to d4cff9d Compare February 11, 2020 10:04
@yazgoo
Copy link
Contributor Author

yazgoo commented Feb 11, 2020

Do you use the Helm chart for deployment to Kubernetes? If so, can you update that as well? If not, I'll do it.

Unfortunately I'm not using kafka-lag-exporter w/ kubernetes :)

@yazgoo
Copy link
Contributor Author

yazgoo commented Feb 19, 2020

ready for review @seglo

Copy link
Owner

@seglo seglo left a comment

Choose a reason for hiding this comment

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

LGTM. Just a few minor docs fixes to add.

@@ -224,20 +224,32 @@ To run the project in standalone mode you must first define a configuration `app
contain at least connection info to your Kafka cluster (`kafka-lag-exporter.clusters`). All other configuration has
defaults defined in the project itself. See [`reference.conf`](./src/main/resources/reference.conf) for defaults.

### Reporters
Copy link
Owner

Choose a reason for hiding this comment

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

Please add this section to the ToC.

README.md Outdated
| Key | Default | Description |
|-----------------------------|--------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| `reporters.prometheus.port` | `8000` | The port to run the Prometheus endpoint on |
| `reporters.graphite.host` | None | The graphite host to send metrics to (if not set, will not output to grahpite) |
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
| `reporters.graphite.host` | None | The graphite host to send metrics to (if not set, will not output to grahpite) |
| `reporters.graphite.host` | None | The graphite host to send metrics to (if not set, will not output to graphite) |

README.md Outdated
| `reporters.prometheus.port` | `8000` | The port to run the Prometheus endpoint on |
| `reporters.graphite.host` | None | The graphite host to send metrics to (if not set, will not output to grahpite) |
| `reporters.graphite.port` | None | The graphite port to send metrics to (if not set, will not output to graphite) |
| `reporters.graphite.prefix` | None | The graphite metric prefix (if not set, prefix will be embty) |
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
| `reporters.graphite.prefix` | None | The graphite metric prefix (if not set, prefix will be embty) |
| `reporters.graphite.prefix` | None | The graphite metric prefix (if not set, prefix will be empty) |

}
}

def metricNameToGraphiteMetricName(metricValue: MetricValue): String = {
Copy link
Owner

Choose a reason for hiding this comment

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

I see.

@seglo seglo merged commit 28910ed into seglo:master Mar 6, 2020
@seglo
Copy link
Owner

seglo commented Mar 6, 2020

Great, thanks for your patience @yazgoo. I'll push a release soon.

@yazgoo
Copy link
Contributor Author

yazgoo commented Mar 9, 2020

Thank you !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request refactor Refactor of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants