Code Monkey home page Code Monkey logo

thanos-federate-proxy's Introduction

Thanos Federate Proxy

A proxy to convert /federate queries to /v1/api/query and respond in open metrics format.

The most common use case for this proxy is to be used as a side car with Thanos, to provide /federate api for thanos (currently Thanos does not support it). So this way you can add Thanos as a federation source in another prometheus. Also Thanos does not support remote write (Note that being able to write metrics remotely from thanos to another prometheus is a different concept than thanos receiver component).

Usage

Docker

sudo docker run -p 9099:9099 ghcr.io/snapp-incubator/thanos-federate-proxy:main -insecure-listen-address="0.0.0.0:9099"

Binary releases

export VERSION=0.1.0
wget https://github.com/snapp-incubator/thanos-federate-proxy/releases/download/v${VERSION}/thanos-federate-proxy-${VERSION}.linux-amd64.tar.gz
tar xvzf thanos-federate-proxy-${VERSION}.linux-amd64.tar.gz thanos-federate-proxy-${VERSION}.linux-amd64/thanos-federate-proxy

From source

git clone https://github.com/snapp-incubator/thanos-federate-proxy
cd thanos-federate-proxy && go build
./thanos-federate-proxy <optional-extra-flags>

Configuration

Flags:

  -insecure-listen-address string
        The address which proxy listens on (default "127.0.0.1:9099")
  -tlsSkipVerify
        Skip TLS Verfication (default false)
  -upstream string
        The upstream thanos URL (default "http://127.0.0.1:9090")
  -bearer-file string
        Path to file containing Authorization bearer token, if needed.
  -force-get
        Force prometheus api.Client to use GET requests instead of POST (default false)

Sample k8s deployment (as a side car with thanos or prometheus):

containers:
  ...
- name: thanos-federate-proxy
  image: ghcr.io/snapp-incubator/thanos-federate-proxy:main
  args:
  - -insecure-listen-address=0.0.0.0:9099
  - -upstream=http://127.0.0.1:9090
  ports:
  - containerPort: 9099
    name: fedproxy
    protocol: TCP

Sample prometheus config for federation:

scrape_configs:
- job_name: 'thanos-federate'
    scrape_timeout: 1m
    metrics_path: '/federate'
    params:
    'match[]':
    - 'up{namespace=~"perfix.*"}'
    static_configs:
    - targets:
        - 'thanos.svc.cluster:9099'

Limitations

The following limitations will be addressed in future releases (see Roadmap):

  • You can not pass empty matcher to prometheus for scraping all the metrics (see this prometheus issue). A workaround is to use the following matcher:

    'match[]':
      - '{__name__=~".+"}'

    Note that {__name__=~".*"} won't also work and you should use ".+" instead of ".*".

Roadmap

  • test federation
  • tlsSkipVerify flag
  • Dockerfile
  • Github actions
  • metrics
  • support multiple matchers
  • support empty matchers
  • support store-API for better performance
  • return error message instead of only logging it (??)
  • remove space after comma in metrics (causing no issues)
  • make query timeouts configurable
  • add markdown lint to CI

Metrics

Metric Notes
thanosfederateproxy_scrape_duration_seconds_count Total number of scrape requests with response code
thanosfederateproxy_scrape_duration_seconds_sum Duration of scrape requests with response code
thanosfederateproxy_scrape_duration_seconds_bucket Count of scrape requests per bucket (for calculating percentile)

Changelog

See CHANGELOG.md

Security

Reporting security vulnerabilities

If you find a security vulnerability or any security related issues, please DO NOT file a public issue, instead send your report privately to [email protected]. Security reports are greatly appreciated and we will publicly thank you for it.

License

Apache-2.0 License, see LICENSE.

thanos-federate-proxy's People

Contributors

dependabot[bot] avatar luisdavim avatar m-yosefpor avatar navidshariaty avatar therealak12 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

thanos-federate-proxy's Issues

Is this still maintained?

I'd like to use this project in my stack but it does not look like actively maintained. Is this still something you're using and are willing to maintain?
Thank you

instance label is not included if missing

Prometheus always includes instance label in federation
https://github.com/prometheus/prometheus/blob/7a07a279c90e5eed35069a4d5cecb15e0aa7ec8b/web/federate.go#L180C2-L182

This proxy does not do that, but it could be added. Along with support for external labels.

Example

$ cat prometheus.yml
rule_files:
- recording.rules
$ cat recording.rules
groups:
  - name: example
    rules:
    - record: test
      expr: 1
$ prometheus
ts=2023-11-05T15:56:15.361Z caller=main.go:556 level=info msg="Starting Prometheus Server" mode=server version="(version=2.42.0, branch=non-git, revision=non-git)"
...
curl -v 'http://127.0.0.1:9090/federate?match[]=test'
*   Trying 127.0.0.1:9090...
* Connected to 127.0.0.1 (127.0.0.1) port 9090 (#0)
> GET /federate?match[]=test HTTP/1.1
> Host: 127.0.0.1:9090
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/plain; version=0.0.4; charset=utf-8
< Date: Sun, 05 Nov 2023 15:54:34 GMT
< Content-Length: 54
<
# TYPE test untyped
test{instance=""} 1 1699199580857
* Connection #0 to host 127.0.0.1 left intact

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.