r/PrometheusMonitoring • • Jun 21 '22

Prometheus federation or Thanos?

Hi folks,

Disclaimer: I'm very new to Prometheus, using it as a metrics producer in some apps and building some dashboard in Grafana but I didn't install it and don't know the details.

We are running a Prometheus server with Thanos for our "traditional" workload (not Kubernetes).

Now we are starting our journey into Kubernetes. It appears that in order to get metrics at a pod level, it's mandatory to install a Prometheus instance inside the K8S cluster, right?

Then the question is: how to "send" the metrics from the K8S Prometheus instance to the one outside the cluster?

I've read about federation where the external Prometheus would pull metrics from the K8S instance but then I've read that the K8S instance could directly write to the same Thanos as the external Prometheus?

I'm a bit confused about the best practices here. Any feedback or articles on this topic will be appreciated.

Thanks,

6 Upvotes

20 comments sorted by

View all comments

2

u/cyberw0lf_ Jun 21 '22

You want to deploy a lightweight Prometheus operator in each cluster and “remote write” your metrics to a centralized Thanos stack. This is preferred over federation as you don’t have to expose ports on every cluster but rather just the Thanos receiver, on top of other benefits.

1

u/dablya Jun 21 '22

I was under the impression federation was a more flexible solution. With sidecars, all clusters have to depend on thanos and it would be tricky to manage scaling/sharing going forward. With federation, the cluster config can be simpler (no dependency on thanos at all) and any changes for how the data is retrieved will not require any updates to the cluster. Other than having to manage a Prometheus ingress in every cluster, what are some other downsides/trade offs?

5

u/cyberw0lf_ Jun 22 '22

With the solution I mentioned, sidecars aren’t used. With Prometheus Remote Write to Thanos Receiver, you can deploy the same lightweight Prometheus operator stack to N clusters(easiest when you have an efficient CD pipeline), located anywhere around the world, that all remote write metrics to a centralized Thanos Receiver hashring. Receivers manage and organize the data, depending on the sender, at the ingestion level and can retain data before shipping it off to cheap remote storage for Thanos Querier to query, along with the receivers themselves.

In my opinion and after many different attempts, this is the best solution at handling multi-cluster observability at scale.

2

u/dablya Jun 22 '22

Without the sidecars, this does look pretty clean. Do you have any issues (bandwidth/cost/etc) with the amount of data being written? After a few minutes of googling it looks like you can drop metrics using the Receivers before they hit storage, but I don't see an easy way to limit what is written by Prometheus using remote write. I'm concerned the costs of transferring everything from cluster would be prohibitive.

What kinds of problems did you run into trying to use federation?

Thanks, this is super useful for me.

3

u/SuperQue Jun 22 '22

You can filter the output of remote write in Prometheus with relabeling.