profile
viewpoint
Matthias Loibl metalmatze Red Hat Berlin http://matthiasloibl.com Software Engineer working on monitoring with Prometheus and Kubernetes at Red Hat CoreOS. Interested in web development, distributed systems and metal.

gopasspw/gopass 3626

The slightly more awesome standard unix password manager for teams

metalmatze/alertmanager-bot 387

Bot for Prometheus' Alertmanager

conprof/conprof 325

Continuous profiling in for pprof compatible profiles.

brancz/kube-rbac-proxy 213

Kubernetes RBAC authorizing HTTP proxy for a single upstream.

brancz/kubernetes-grafana 170

The future of Grafana on Kubernetes with Prometheus.

justwatchcom/github-releases-notifier 109

Receive Slack notifications for new releases of your favorite software on GitHub.

go-pluto/pluto 53

A distributed IMAP server based on Conflict-free Replicated Data Types.

drone/drone-kubernetes-runtime 51

Goto drone/drone-runtime

metalmatze/awesome-jsonnet 20

A curated list of awesome Jsonnet projects and mixins

push eventmetalmatze/promtools.dev

Matthias Loibl

commit sha 16fba7ab4c7c682ac84a7c40d175efc33cff8af7

Trigger Deployment

view details

push time in 3 days

push eventmetalmatze/promtools.dev

Matthias Loibl

commit sha b4336eef5d0857a8b8bf9af899ed609d3606e8c3

Creat DO app.yaml

view details

push time in 3 days

push eventmetalmatze/promtools.dev

Matthias Loibl

commit sha d1d40454c7337eea0d5ea02bd20fcf5c752a39e3

Remove files not needed for DO Apps

view details

Matthias Loibl

commit sha b517aebeb4654f08f834ca53babecaf06d7cce27

Create Dockerfile with multi stage build

view details

push time in 3 days

push eventmetalmatze/promtools.dev

Matthias Loibl

commit sha c714dfd969ab7127649be3deb7df57d8504e4e30

Add Procfile

view details

push time in 3 days

create barnchmetalmatze/promtools.dev

branch : apps

created branch time in 3 days

push eventmetalmatze/promtools.dev

Matthias Loibl

commit sha e8a4e6912eb9df59a0e68cbdbd914e6ebc4c8615

Create nextjs based UI

view details

push time in 3 days

issue commentthanos-io/thanos

An official, community driven Thanos Helm Chart in thanos-community organization.

I think there's still interest generally speaking. :)

daixiang0

comment created time in 3 days

PullRequestReviewEvent

delete branch metalmatze/kube-state-metrics

delete branch : no-ksonnet

delete time in 3 days

PullRequestReviewEvent

Pull request review commentobservatorium/observatorium

Add rate limiting per tenant

 func main() { 			Addr:         cfg.server.listen, 			Handler:      r, 			TLSConfig:    tlsConfig,-			ReadTimeout:  readTimeout,  // best set per handler-			WriteTimeout: writeTimeout, // best set per handler+			ReadTimeout:  readTimeout,  // best set per handler.

I guess that's a question for the original author and not Kemal? It means that the timeouts are best set specifically per handler, as the handlers probably have different requirements. /query should for example take only fewer seconds compared to /query_range.

kakkoyun

comment created time in 3 days

PullRequestReviewEvent

PR opened kubernetes/kube-state-metrics

Remove ksonnet and move to absolute import paths

What this PR does / why we need it:

In an effort to move kube-prometheus to use absolute import paths (for better discoverability) I needed to refactor these jsonnet bits. Next to that, I also refactored the Kubernetes object generation to use plain Jsonnet objects and not ksonnet anymore.

Over the last months/years, we've come to the conclusion that readability is more important than the "type safety" that ksonnet promised. Instead we're going for external tools that check the generated YAML after it has been generated like kubeval

<!-- Thanks for sending a pull request! Here are some tips for you:

  1. If this is your first time, read our contributor guidelines https://git.k8s.io/community/contributors/guide/pull-requests.md#the-pull-request-submit-process and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
  2. If you want faster PR reviews, read how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
  3. Follow the instructions for writing a release note: https://git.k8s.io/community/contributors/guide/pull-requests.md#write-release-notes-if-needed
  4. If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests -->

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):

Fixes issues outside this repository. I've talked to @lilic before making this PR though :innocent:

+280 -253

0 comment

5 changed files

pr created time in 4 days

push eventmetalmatze/kube-state-metrics

Frederic Branczyk

commit sha c3c20b77e2834bd540ff63adcb054af15da673af

CHANGELOG.md: Add entry for v1.4.0-rc.0

view details

zoues

commit sha 49423c295761564f47afab8d51aacf11441dc632

add myself to review Recommend yourself as an reviewer

view details

k8s-ci-robot

commit sha 0d47aefa3270fcbe61790dc5d5cc53974e04246c

Merge pull request #504 from zouyee/patch-5 add myself to review

view details

k8s-ci-robot

commit sha d5b4ff7645586dcd4caee85aa3aacefe95f3d374

Merge pull request #503 from brancz/cut-1.4.0-rc.0 Cut v1.4.0-rc.0

view details

Marian Lobur

commit sha fd048c8bc81e2ea25d9ca8a7424b861bcfd56241

Update release documentation.

view details

WakeupTsai

commit sha 0f9ade847aa3c68203ceecc5dc578fa8d2e4957b

Add uid info in kube_pod_info metric

view details

k8s-ci-robot

commit sha 4f6644c6667e169ef082c01c83bcb883a7738cb5

Merge pull request #509 from loburm/update_doc Update release documentation

view details

Max Leonard Inden

commit sha 183c7988fb1de050284bd26da88abdba2886d439

main_test.go: Introduce overarching benchmark test This patch adds a simple go benchmark test, injecting Kubernetes objects and simulating scrape requests. It uses the Kubernetes client-go fake client. Alongside comes some refactoring of each collectors structure using informer factories to be compatible with the fake client. The patch lays the groundwork to make future performance optimizations comparable with past versions. How to run test: `go test -race -bench . -memprofile=mem.out -cpuprofile=cpu.out`

view details

Lv Jiawei

commit sha 4543513eb469cbf4f563ccbb27465580506cf9bf

Fix a typo

view details

k8s-ci-robot

commit sha 126d048537e2ac1fbb7992535d65aab06e8d2b22

Merge pull request #521 from MIBc/patch-1 Fix a typo

view details

Andy Xie

commit sha 991e511f11a9bb201b8f10f6dc4c5703c0065e06

add kube_replicatset_owner metric

view details

k8s-ci-robot

commit sha 579952020a2d57b8960365c9e30af3b1fb71b15a

Merge pull request #513 from mxinden/unit main_test.go: Introduce overarching benchmark test

view details

k8s-ci-robot

commit sha 38361029bb488e4973860a4c85d411fa74896859

Merge pull request #520 from andyxning/add_replicaset_owner add kube_replicatset_owner metric

view details

Frederic Branczyk

commit sha c6da2cf9df12a69062589b825772b69d23262e06

*: cut v1.4.0

view details

k8s-ci-robot

commit sha 8cd1a01915940c4b02657c2401a9fa48bfcb8ec4

Merge pull request #529 from brancz/1.4-into-master Merge Release 1.4 back into master

view details

zouyee

commit sha 2c42c3fa16d2e98a8bf3c53cbeec35808880fc76

Heapster with supplementary information

view details

k8s-ci-robot

commit sha 8108d76496fb9242f78905493339d7b5c374f575

Merge pull request #519 from zouyee/patch-5 Heapster with supplementary information

view details

Pei Hsuan Tsai

commit sha 5fe7838bd750eeb6e7c10f2ef0b6edbe36f856a8

update unit test

view details

k8s-ci-robot

commit sha b2258148f4846ab1cc5bc0b1a14350a4de15f99c

Merge pull request #508 from linkernetworks/master Add uid info in kube_pod_info metric

view details

zouyee

commit sha 62fea200268b3f37290c583facea6333ad23c5c8

remove unused func

view details

push time in 4 days

create barnchmetalmatze/kube-state-metrics

branch : no-ksonnet

created branch time in 4 days

issue commentmetalmatze/alertmanager-bot

did you try bot on the OpenShift 3.11?

@Nurlan199206 Looks good. You probably don't need to run it as root though. Be careful with /tmp/bot.db in production too. This will lose all data once the machine gets restarted. Otherwise looking good.

Nurlan199206

comment created time in 4 days

issue commentmetalmatze/alertmanager-bot

did you try bot on the OpenShift 3.11?

The logs look like the bot is up and running successfully. It has to be the configuration outside of the bot most liekly.

Nurlan199206

comment created time in 4 days

push eventmetalmatze/kube-thanos

Matthias Loibl

commit sha 2840d8064b99d894e7fc1ecff14747424ebff51f

Introduce bingo for tool deps and kubeval for validation We want to validate the generated YAMl with kubeval. To add this tools dependency as binary I moved to using bingo for managing those. Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

view details

push time in 4 days

PR opened thanos-io/kube-thanos

Introduce bingo for tool deps and kubeval for validation

We want to validate the generated YAMl with kubeval. To add this tools dependency as binary I moved to using bingo for managing those.

+145 -36

0 comment

13 changed files

pr created time in 4 days

create barnchmetalmatze/kube-thanos

branch : bingo

created branch time in 4 days

delete branch metalmatze/kube-thanos

delete branch : remove-ksonnet

delete time in 4 days

create barnchmetalmatze/kube-thanos

branch : remove-ksonnet

created branch time in 4 days

PR opened thanos-io/kube-thanos

Remove ksonnet

All ksonnet dependencies have been removed. As a matter of fact there are no dependencies for kube-thanos left. These are pure jsonnet,JSON,YAML files now.

+5 -39

0 comment

6 changed files

pr created time in 4 days

delete branch metalmatze/kube-thanos

delete branch : no-ksonnet-thanos-store

delete time in 5 days

delete branch metalmatze/kube-thanos

delete branch : no-ksonnet-thanos-rule

delete time in 5 days

PR opened thanos-io/kube-thanos

Rewrite the thanos-receive component without ksonnet

There was one inconsistency in the service ports, otherwise it's all the same.

+92 -86

0 comment

3 changed files

pr created time in 5 days

create barnchmetalmatze/kube-thanos

branch : no-ksonnet-thanos-store

created branch time in 5 days

create barnchmetalmatze/kube-thanos

branch : no-ksonnet-thanos-rule

created branch time in 5 days

PR opened thanos-io/kube-thanos

Rewrite the thanos-receive component without ksonnet

Adding rules to the all example too.

+85 -71

0 comment

3 changed files

pr created time in 5 days

delete branch metalmatze/kube-thanos

delete branch : no-ksonnet-thanos-receive

delete time in 5 days

PR opened thanos-io/kube-thanos

Rewrite the thanos-receive component without ksonnet

There were some changes in places were the receive component hasn't been consistent with the other components. Additionally, I also added PodDisruptionBudget to the examples/all/

+135 -116

0 comment

4 changed files

pr created time in 5 days

create barnchmetalmatze/kube-thanos

branch : no-ksonnet-thanos-receive

created branch time in 5 days

delete branch metalmatze/kube-thanos

delete branch : no-ksonnet-thanos-query

delete time in 5 days

delete branch metalmatze/kube-thanos

delete branch : no-ksonnet-thanos-query-frontend

delete time in 5 days

delete branch metalmatze/kube-thanos

delete branch : no-ksonnet-thanos-compact

delete time in 5 days

pull request commentthanos-io/kube-thanos

Rewrite the thanos-bucket component without ksonnet

In the end this is about readability mostly. It's 10x easier for people to read and write this kind of code, whereas ksonnet only adds so much type safety. Over the last couple of years it became more and more obvious that we should focus on the first one and use some other tool to check the output. kubeval so far has been really helpful.

metalmatze

comment created time in 5 days

delete branch metalmatze/kube-thanos

delete branch : no-ksonnet-thanos-bucket

delete time in 5 days

PR opened thanos-io/kube-thanos

Rewrite the thanos-query component without ksonnet

As you can see there are no changes in the examples/all so the output generated is equal to before.

+74 -59

0 comment

1 changed file

pr created time in 5 days

create barnchmetalmatze/kube-thanos

branch : no-ksonnet-thanos-query

created branch time in 5 days

push eventmetalmatze/kube-thanos

Matthias Loibl

commit sha 26cbb8ae8abdd2d4b96517e99832939a0e061ddd

Rewrite the thanos-compact component without ksonnet As you can see there are no changes in the examples/all so the output generated is equal to before. Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

view details

push time in 5 days

push eventmetalmatze/kube-thanos

Matthias Loibl

commit sha 033cdab86cd5ad18c2b902cf27cef99772d2853d

Rewrite the thanos-bucket component without ksonnet As you can see there are no changes in the examples/all so the output generated is equal to before. Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

view details

push time in 5 days

PR opened thanos-io/kube-thanos

Rewrite the thanos-query-frontend component without ksonnet

As you can see there are no changes in the examples/all so the output generated is equal to before.

+67 -57

0 comment

1 changed file

pr created time in 5 days

push eventmetalmatze/kube-thanos

Matthias Loibl

commit sha f6dbb77a2e123a3dfc5bda0d4c9d35e366c6b80c

Rewrite the thanos-query-frontend component without ksonnet As you can see there are no changes in the examples/all so the output generated is equal to before. Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

view details

push time in 5 days

create barnchmetalmatze/kube-thanos

branch : no-ksonnet-thanos-query-frontend

created branch time in 5 days

pull request commentthanos-io/kube-thanos

Rewrite the thanos-bucket component without ksonnet

Yes, lol :smile:

metalmatze

comment created time in 5 days

push eventmetalmatze/kube-thanos

Matthias Loibl

commit sha 168937f9d5386c6527f3ce27041ef2f7c1921b2e

Rewrite the thanos-compact component without ksonnet As you can see there are no changes in the examples/all so the output generated is equal to before. Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

view details

push time in 5 days

PR opened thanos-io/kube-thanos

Rewrite the thanos-compact component without ksonnet

As you can see there are no changes in the examples/all so the output generated is equal to before.

+63 -59

0 comment

1 changed file

pr created time in 5 days

create barnchmetalmatze/kube-thanos

branch : no-ksonnet-thanos-compact

created branch time in 5 days

push eventmetalmatze/kube-cockroachdb

Frederic Branczyk

commit sha a56dd2cea326aef73335047d4abcea4de11bb446

kubernetes.libsonnet: Run as nobody user by default

view details

Matthias Loibl

commit sha 7a77b2adbacaa6da6918fdd75a6496bed8522aba

Merge pull request #9 from metalmatze/nobody-sc kubernetes.libsonnet: Run as nobody user by default

view details

push time in 5 days

PullRequestReviewEvent

PR opened thanos-io/kube-thanos

Reviewers
Rewrite the thanos-bucket component without ksonnet

As you can see there are no changes in the examples/all so the output generated is equal to before.

+57 -46

0 comment

1 changed file

pr created time in 5 days

create barnchmetalmatze/kube-thanos

branch : no-ksonnet-thanos-bucket

created branch time in 5 days

delete branch metalmatze/kubernetes-grafana

delete branch : no-ksonnet

delete time in 5 days

push eventmetalmatze/kubernetes-grafana

Matthias Loibl

commit sha e7889fa22d4636ec0b20f474eb8f0277ebf662f5

Update examples in README.md

view details

push time in 5 days

pull request commentbrancz/kubernetes-grafana

Restructure to not use ksonnet

Rewrote all example to not use ksonnet. Let's see if that works.

metalmatze

comment created time in 5 days

push eventmetalmatze/kubernetes-grafana

Matthias Loibl

commit sha b5529668d15500cab95a2e1d40d23131a2c54fb0

Rewrite example to not use ksonnet

view details

push time in 5 days

pull request commentbrancz/kubernetes-grafana

Restructure to not use ksonnet

Looks like the examples/basic.jsonnet file still uses ksonnet, which fails the build.

So obvious. Not sure how I didn't grasp that :joy:

metalmatze

comment created time in 6 days

delete branch metalmatze/node_exporter

delete branch : mixin-jsonnet-absolute-import-paths

delete time in 6 days

delete branch metalmatze/prometheus

delete branch : mixin-jsonnet-absolute-import-paths

delete time in 6 days

pull request commentopenfaas/faas

Use rate[30s] for APIHighInvocationRate alert

Not sure why the CI failed here.

metalmatze

comment created time in 6 days

PR opened brancz/kubernetes-grafana

Restructure to not use ksonnet

ksonnet isn't needed anymore, going forward. I tested these new objects by generating a YAML diff with the old output vs the new ones.

+197 -114

0 comment

2 changed files

pr created time in 6 days

create barnchmetalmatze/kubernetes-grafana

branch : no-ksonnet

created branch time in 6 days

PR opened prometheus/prometheus

Use absolute jsonnet import paths

This should be the way forward when importing libraries in jsonnet. It's closer to how Go imports look and makes it more obvious where packages live.

This is not breaking anything, as the old imports were already symlinks to the now directly used directories.

<!-- Don't forget!

- If the PR adds or changes a behaviour or fixes a bug of an exported API it would need a unit/e2e test.

- Where possible use only exported APIs for tests to simplify the review and make it as close as possible to an actual library usage.

- No tests are needed for internal implementation changes.

- Performance improvements would need a benchmark test to prove it.

- All exposed objects should have a comment.

- All comments should start with a capital letter and end with a full stop.

-->

+3 -3

0 comment

2 changed files

pr created time in 7 days

create barnchmetalmatze/prometheus

branch : mixin-jsonnet-absolute-import-paths

created branch time in 7 days

push eventmetalmatze/prometheus

Björn Rabenstein

commit sha 9f35c75c21a063a6f2014ffe9fcca3b0aa055538

Merge pull request #6323 from prometheus/beorn7/build Add tsdb/tsdb to .gitignore

view details

Jean-Baptiste Le Duigou

commit sha 59732274348de10e51b4ce5f4911df2f268aadce

adding additional unit tests for getDataCenter() in consul (#6192) * adding additional unit tests for getDataCenter() in consul Signed-off-by: Jean-Baptiste Le Duigou <jb.leduigou@gmail.com> * Consult Tests : update comments to start with uppercase and end with point Signed-off-by: Jean-Baptiste Le Duigou <jb.leduigou@gmail.com> * Consult Test : using table-driven tests Signed-off-by: Jean-Baptiste Le Duigou <jb.leduigou@gmail.com> * Consul Test : cleaner syntax Signed-off-by: Jean-Baptiste Le Duigou <jb.leduigou@gmail.com> * Consul Test : even cleaner syntax Signed-off-by: Jean-Baptiste Le Duigou <jb.leduigou@gmail.com> * Consul Test : update comments Signed-off-by: Jean-Baptiste Le Duigou <jb.leduigou@gmail.com> * Fixing naming convention by removing underscore in function name Signed-off-by: Jean-Baptiste Le Duigou <jb.leduigou@gmail.com> * Removing duplicated test case for getDatacenter() Signed-off-by: Jean-Baptiste Le Duigou <jb.leduigou@gmail.com>

view details

naivewong

commit sha 23c0299d85bfeb5d9b59e994861553a25ca578e5

[tsdb] Improve mergeSeriesSet (#5920) * refactor and simplify mergeSeriesSet Signed-off-by: naivewong <867245430@qq.com>

view details

Tom Wilkie

commit sha de0a772b8e7d27dc744810a1a693d97be027049a

Port tsdb to use pkg/labels. (#6326) * Port tsdb to use pkg/labels. Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com> * Get tests passing. Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com> * Remove useless cast. Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com> * Appease linters. Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com> * Fix review comments Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>

view details

akerele abraham

commit sha 9d39fdad0cb62fcbea3e6841b7f9188eb6120a26

unittest: check for rule files existence (#6075) Signed-off-by: akerele abraham <abrahamakerele38@gmail.com>

view details

Callum Styan

commit sha f4fb6dc2088507b236f04042dc6cc845c783ad01

Simplify remote write dashboard in mixin. Signed-off-by: Callum Styan <callumstyan@gmail.com>

view details

johncming

commit sha ad4bc5701e2d9380ea04181f67401404f5f2200c

remove unwanted break (#6338) Signed-off-by: johncming <johncming@yahoo.com>

view details

shreyassrivatsan

commit sha e825282dd1b7a62999ed50d5c8039c5fdda89bea

Add exemplar support to the openmetrics parser (#6292) * Add exemplar support to the openmetrics parser Signed-off-by: Shreyas Srivatsan <shreyas@chronosphere.io>

view details

Tim Bart

commit sha 2e77f3a52b6aed60b36d0fa7722222f30c0df018

Fix typo in posting stats. (#6343) Signed-off-by: Tim Bart <tbart@cloudflare.com>

view details

Callum Styan

commit sha 2d3ce3916c17fd440aa80e15fa44910fece4bb3d

Log the start and end of the WAL replay within the WAL watcher. Signed-off-by: Callum Styan <callumstyan@gmail.com>

view details

Björn Rabenstein

commit sha ba9332972c2891d0ae1c0600d30ce3802276044d

Merge pull request #6335 from cstyan/rw-dashboard-simplify Simplify remote write dashboard in mixin.

view details

Julien Pivotto

commit sha 2a190d1168a94ac4bca455b7ff4ca7b2261b4a2c

Fix small typo in docs (#6345) Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>

view details

Boyko

commit sha 3e3b7ceb0bc5d96b85cbfbc26580f080d799b7b5

React UI: Change the dynamic react key with static id (#6325) * change the dynamic key with static id for react key prop Signed-off-by: blalov <boyko.lalov@tick42.com> * test fix Signed-off-by: blalov <boyko.lalov@tick42.com> * add initial panel on did mount Signed-off-by: blalov <boyko.lalov@tick42.com> * lint fix Signed-off-by: blalov <boyko.lalov@tick42.com> * remove filter for empty expression Signed-off-by: blalov <boyko.lalov@tick42.com> * refactoring Signed-off-by: blalov <boyko.lalov@tick42.com> * refactor encodePanelOptionsToQueryString Signed-off-by: blalov <boyko.lalov@tick42.com> * refactor encodePanelOptionsToQueryString Signed-off-by: blalov <boyko.lalov@tick42.com> * revert to format range/endTime Signed-off-by: blalov <boyko.lalov@tick42.com> * urlParams unit tests Signed-off-by: blalov <boyko.lalov@tick42.com> * unit tests adjustments Signed-off-by: Boyko Lalov <boyskila@gmail.com>

view details

Julius Volz

commit sha d2cb05846b981edba675e13e43608a6432c29235

React UI: Add /tsdb-status to React-handled routes (#6313) Signed-off-by: Julius Volz <julius.volz@gmail.com>

view details

Callum Styan

commit sha 7bf17b654cda9ea02c11355bb02ae3fed1e758ff

As per dev summit, SD moratorium has been lifted. (#6324) Signed-off-by: Callum Styan <callumstyan@gmail.com>

view details

Dipack P Panjabi

commit sha e2dd5b61efa58ac8adc0eb1fb6291af7ef059c62

Added CreateBlock and CreateHead functions to new file (#6331) * Added CreateBlock and CreateHead functions to new file to make it reusable across packages. Signed-off-by: Dipack P Panjabi <dipack.panjabi@gmail.com>

view details

Tobias Guggenmos

commit sha ac3932ea35a20cf81d385df802176991d4bae867

Improve PromQL parser performance by making it non-concurrent (#6356) Before this commit, the PromQL parser ran in two goroutines: * The lexer goroutine that splits the input into tokens and sent them over a channel to * the parser goroutine which produces the abstract syntax tree The Problem with this approach is that the parser spends more time on goroutine creation and syncronisation than on actual parsing. This commit removes that concurrency and replaces the channel by a slice based buffer. Benchmarks show that this makes the up to 7 times faster than before. Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>

view details

Julius Volz

commit sha 20ec57160c7fe9b9ac9938f58f4992872212ac88

React UI: Clarify VSCode usage requirements (#6357) Signed-off-by: Julius Volz <julius.volz@gmail.com>

view details

Julius Volz

commit sha 22d884b38e089897aab25b43650579d143928fde

React UI: Fix tests harder (#6316) * React UI: Fix tests harder Again not sure why this passed last time (?), but now I was getting an error about 'NaN' not being a valid value to assign to the 'height' property of the input element. This changes it so that only the blur() function is actually mocked out on the active input element. Signed-off-by: Julius Volz <julius.volz@gmail.com> * Fixup Signed-off-by: Julius Volz <julius.volz@gmail.com>

view details

Julius Volz

commit sha d2a3ef2f129c3d08497e91dfbc071d7eb43a2f87

Remove broken Travis badge (#6364) The "green" status of this badge was actually last updated 4 years ago, until I manually ran a master branch test today that made the current Travis test failures in the React tests visible. But those test failures seem to be Travis-related and not real (the same tests pass on CircleCI). Maybe we can completely remove Travis by now, but let's remove the now-failing badge for now to not scare users. Signed-off-by: Julius Volz <julius.volz@gmail.com>

view details

push time in 7 days

PR opened prometheus/node_exporter

Use absolute jsonnet import paths

This should be the way forward when importing libraries in jsonnet. It's closer to how Go imports look and makes it more obvious where packages live.

This is not breaking anything, as the old imports were already symlinks to the now directly used directories.

+4 -4

0 comment

3 changed files

pr created time in 7 days

push eventmetalmatze/node_exporter

mknapphrt

commit sha 09b4305090a6af1e69c528539fba63fc5ff781c6

Changed the way that stuck mounts are handled. If a mount fails to return, it will stop being queried until it returns. (#997) Fixed spelling mistakes. Update transport_generic.go Changed to a mutex approach instead of channels and added a timeout before declaring a mount stuck. Removed unnecessary lock channel and clarified some var names. Fixed style nits. Signed-off-by: Mark Knapp <mknapp@hudson-trading.com>

view details

Jan Klat

commit sha c4102f117584f92e18e9612d9a9eecd0815e89bd

Add sys/class/net parsing from procfs and expose its metrics (#851) * add sys/class/net parsing from procfs and expose its metrics Signed-off-by: Jan Klat <jenik@klatys.cz> * change code to use int pointers per procfs change, move netclass to separate collector, change metric naming Signed-off-by: Jan Klat <jenik@klatys.cz> * bump year in licence, remove redundant newline, correct fixtures Signed-off-by: Jan Klat <jenik@klatys.cz> * fix style Signed-off-by: Jan Klat <jenik@klatys.cz> * change carrier changes to counter type Signed-off-by: Jan Klat <jenik@klatys.cz> * fix e2e output Signed-off-by: Jan Klat <jenik@klatys.cz> * add fixtures Signed-off-by: Jan Klat <jenik@klatys.cz> * update vendor, use fixtures correctly Signed-off-by: Jan Klat <jenik@klatys.cz> * change fixtures (device in /sys/class/net should be symlinked) Signed-off-by: Jan Klat <jenik@klatys.cz> * correct fixtures for 64k page, updated readme Signed-off-by: Jan Klat <jenik@klatys.cz>

view details

Brandon Gilmore

commit sha 76bbd8dd1865b63e52fd19322e84a1bb4ea97b29

Use /proc/mounts instead of statfs(2) for ro state (#1002) While the statfs(2) approach is reliable for normally mounted filesystems, the flags returned can be inconsistent when filesystem has been remounted read-only after encountering an error. The returned flags do accurately represent the internal state of the filesystem, but they do not reflect whether the VFS layer will accept writes. Instead, it makes sense to parse the current VFS mount state from the options field in /proc/mounts since it takes precedence. Signed-off-by: Brandon Gilmore <bgilmore@valvesoftware.com>

view details

xginn8

commit sha 9b97f44a704c9c31e45c864c105643e6b197abad

Add a counter for refused socket unit connections, available as of systemd 239 (#995) Signed-off-by: xginn8 <mamcgi@gmail.com>

view details

neiledgar

commit sha 7e4d9bd1501f315504808d70ac5e80d77fd7660c

Update wifi stats to support multiple stations (#977) (#980) Signed-off-by: neiledgar <neil.edgar@btinternet.com>

view details

Ben Kochie

commit sha 354115511c61c71a46eacf541908f6fb75a63c9a

Add note about SYS_TIME capability for Docker. (#1001) Signed-off-by: Ben Kochie <superq@gmail.com>

view details

Sven Lange

commit sha 2ae8c1c7a7c6a82b2c779aaf84a02899b0ada21b

Add systemd uptime metric collection (#952) * Add systemd uptime metric collection Signed-off-by: Sven Lange <tdl@hadiko.de>

view details

xginn8

commit sha 140b8b85c37553f5baebf433ac9be284cd1dd80d

Filter out uninstalled systemd units when collecting all units (#1011) fixes #567 Signed-off-by: Matthew McGinn <mamcgi@gmail.com>

view details

Ben Kochie

commit sha 23f95c8e04bb21f7a20d93097ace6a5de61c882b

Fix ntp collector thread safety (#1014) Make the ntp collector thread safe by wrapping a mutex lock around the leapMidnight variable. Signed-off-by: Ben Kochie <superq@gmail.com>

view details

Ben Kochie

commit sha 981de58fadfb50c688a274d01e7a382919b4c19a

Update build (#1010) * Update from upstream `Makefile.common`. * Update CircleCI with simplifed upstream templating. * Cleanup `Makefile`. Signed-off-by: Ben Kochie <superq@gmail.com>

view details

Ben Kochie

commit sha ca2fa4684b53d3021ce6f8c98886a1c93767000d

Fix docker build (#1016) Fix override of make docker target to include new `DOCKER_REPO` variable pattern. Signed-off-by: Ben Kochie <superq@gmail.com>

view details

Johannes Wienke

commit sha 5c780d132c963acadf82846840864b700b095136

Exclude only subdirectories of /var/lib/docker (#1003) It is quite common to put /var/lib/docker itself on a separate partition and that should be monitored as well. Signed-off-by: Johannes Wienke <languitar@semipol.de>

view details

Hannes Körber

commit sha 14a4f0028e02ba1c21d6833482bd8f7529035b07

Enable nfs protocol (#998) * vendor: Update prometheus/procfs Signed-off-by: Hannes Körber <hannes.koerber@haktec.de> * mountstats: Use new NFS protocol field In https://github.com/prometheus/procfs/pull/100, the NFSTransportStats struct was expanded by a field called protocol that specifies the NFS protocol in use, either "tcp" or "udp". This commit adds the protocol as a label to all NFS metrics exported via the mountstats collector. Signed-off-by: Hannes Körber <hannes.koerber@haktec.de> * Update fixtures for UDP mount Signed-off-by: Hannes Körber <hannes.koerber@haktec.de>

view details

Rene Treffer

commit sha 80a5712b97cd649b6bf2f9f60cf5c497043ef187

Fix sample rules for migration (#1022) - add conversion from _ms to _seconds on disk metrics - add missing node_textfile_mtime section - add groups: header to pass promtool check rules Signed-off-by: Rene Treffer <rene.treffer@soundcloud.com>

view details

Christian Hoffmann

commit sha 6bdc5558ecfa90f81107f65fc14f55ac46f69643

build: make staticcheck happy by using real regexp patterns #1025 (#1026) Signed-off-by: Christian Hoffmann <mail@hoffmann-christian.info>

view details

Julius Volz

commit sha 2c52b8c76147f0f0671029e9fd7454b9866ace0d

systemd: Remove unneeded/unhandled error returns (#1035) Signed-off-by: Julius Volz <julius.volz@gmail.com>

view details

Ben Kochie

commit sha 5d23ad0ca7aea9efb4115af73490da6f8e9d7175

Fix supervisord collector (#978) * Replace supervisord xmlrpc library * Use `github.com/mattn/go-xmlrpc` that doesn't leak goroutines. * Fix uptime metric * Use Prometheus best practices for uptime metric. * Use "start time" rather than "uptime". * Don't emit a start time if the process is down. * Add changelog entry. * Add example compatibility rules. Signed-off-by: Ben Kochie <superq@gmail.com>

view details

Ben Kochie

commit sha 0662673ad6a626e93eb79bc784776a95164024a3

Disable wifi collector by default (#1037) * Disable wifi collector by default Disable the wifi collector by default due to suspected cashing issues and goroutine leaks. * https://github.com/prometheus/node_exporter/issues/870 * https://github.com/prometheus/node_exporter/issues/1008 Signed-off-by: Ben Kochie <superq@gmail.com>

view details

Ben Kochie

commit sha 099c1527f191e9715a42d338f0d89e34690a6d5b

Update build (#1041) Update build * Update to Go 1.10. * Enable `ppc64le` build. * Enable MIPS builds. Signed-off-by: Ben Kochie <superq@gmail.com>

view details

Ben Kochie

commit sha fe5a1178313b2f56e53d4194ae306373d92a208a

Handle vanishing PIDs (#1043) PIDs can vanish (exit) from /proc/ between gathering the list of PIDs and getting all of their stats. * Ignore file not found errors. * Explicitly count the PIDs we find. * Cleanup some error style issues. Signed-off-by: Ben Kochie <superq@gmail.com>

view details

push time in 7 days

create barnchmetalmatze/node_exporter

branch : mixin-jsonnet-absolute-import-paths

created branch time in 7 days

push eventmetalmatze/faas

Matthias Loibl

commit sha cf152fb9f765ca121eb238551c5a69de97f1103c

Use rate[30s] for APIHighInvocationRate alert The problem with rate[10s], because the gateway scrape interval is 5s, is that it most likely only contains around 2 samples in the given range. Here's an excellent blog post on why 30s should be a lot better: https://www.robustperception.io/what-range-should-i-use-with-rate Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

view details

push time in 7 days

PR opened openfaas/faas

Use rate[30s] for APIHighInvocationRate alert

The problem with rate[10s], because the gateway scrape interval is 5s, is that it most likely only contains around 2 samples in the given range.

Here's an excellent blog post on why 30s should be a lot better: https://www.robustperception.io/what-range-should-i-use-with-rate

How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. -->

I haven't tried this particular change personally, as it's just two characters changing.

Types of changes

<!--- What types of changes does your code introduce? Put an x in all the boxes that apply: -->

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

<!--- Go over all the following points, and put an x in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

  • [ ] My code follows the code style of this project.
  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [ ] I've read the CONTRIBUTION guide
  • [ ] I have signed-off my commits with git commit -s
  • [ ] I have added tests to cover my changes.
  • [ ] All new and existing tests passed.
+1 -1

0 comment

1 changed file

pr created time in 7 days

create barnchmetalmatze/faas

branch : prometheus-alert-rate-range

created branch time in 7 days

fork metalmatze/faas

OpenFaaS - Serverless Functions Made Simple

https://www.openfaas.com/

fork in 7 days

Pull request review commentobservatorium/observatorium

Add rate limiting per tenant

+package internal++import "net/http"++// Middleware is a convenience type for functions that wrap http.Handlers.+type Middleware func(http.Handler) http.Handler

Rather than moving this around, wh not copy the code into the package you need it? This can easily stay in the internal/authentication package unmodified. Simply create a new one in internal/ratelimit/gubernator.

kakkoyun

comment created time in 7 days

PullRequestReviewEvent
PullRequestReviewEvent

pull request commentobservatorium/observatorium

Add rate limiting per tenant

If only internal/ratelimit/gubernator/gubernator.proto is depending on protoc/google can't we move those files into the that directory for now to scope it pretty closely? We tried avoiding globals and broader scope in this project so far. :blush:

kakkoyun

comment created time in 7 days

Pull request review commentobservatorium/observatorium

Add rate limiting per tenant

 token=$(curl --request POST \   --data client_secret=ZXhhbXBsZS1hcHAtc2VjcmV0 \   --data scope="openid email" | sed 's/^{.*"id_token":[^"]*"\([^"]*\)".*}/\1/') +(GUBER_MEMBERLIST_KNOWN_NODES=127.0.0.1:7946 gubernator-v0.8.4-0.20200617200142-07e238f8cd86) &+++echo "-------------------------------------------"+echo "- Waiting for Gubernator to come up...  -"+echo "-------------------------------------------"++until curl --output /dev/null --silent --fail --insecure http://127.0.0.1:80/v1/HealthCheck; do

That comment is probably also really good to put into the code at this exact place. :blush:

kakkoyun

comment created time in 7 days

PullRequestReviewEvent

push eventmetalmatze/transmission-exporter

Matthias Loibl

commit sha e578c0e3ff042648a15f76abf520fd50034d876d

Looking for maintainers

view details

push time in 8 days

Pull request review commentobservatorium/observatorium

Add rate limiting per tenant

+package ratelimit++import (+	"context"+	"fmt"+	"net/http"+	"regexp"+	"time"++	"github.com/go-chi/httprate"++	"github.com/observatorium/observatorium/internal"+	"github.com/observatorium/observatorium/internal/authentication"+	"github.com/observatorium/observatorium/internal/ratelimit/gubernator"+)++const (+	requestName    = "observatorium:tenant_per_endpoint"+	requestTimeout = time.Millisecond * 500+)++// Config configures a rate limiter per endpoint, per tenant.+type Config struct {+	Tenant  string+	Matcher *regexp.Regexp+	Limit   int+	Window  time.Duration+}++type middleware struct {+	matcher *regexp.Regexp+	handler internal.Middleware+}++// WithLocalRateLimiter returns a middleware that controls amount of requests per tenant using in-memory store.+func WithLocalRateLimiter(configs ...Config) internal.Middleware {+	middlewares := make(map[string][]middleware)+	for _, c := range configs {+		middlewares[c.Tenant] = append(middlewares[c.Tenant], middleware{c.Matcher, httprate.NewRateLimiter(+			c.Limit,+			c.Window,+			nil,+		).Handler})+	}++	return combine(middlewares)+}++// WithSharedRateLimiter returns a middleware that controls amount of requests per tenant using external service.+func WithSharedRateLimiter(client gubernator.V1Client, configs ...Config) internal.Middleware {+	middlewares := make(map[string][]middleware)+	for _, c := range configs {+		middlewares[c.Tenant] = append(middlewares[c.Tenant], middleware{c.Matcher, rateLimiter{client, &gubernator.RateLimitReq{+			Name:      requestName,+			UniqueKey: fmt.Sprintf("%s:%s", c.Tenant, c.Matcher.String()),+			Hits:      1,+			Limit:     int64(c.Limit),+			Duration:  c.Window.Microseconds(),+			Algorithm: gubernator.Algorithm_LEAKY_BUCKET,+		}}.Handler})+	}++	return combine(middlewares)+}++func combine(middlewares map[string][]middleware) func(next http.Handler) http.Handler {+	return func(next http.Handler) http.Handler {+		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+			tenant, ok := authentication.GetTenant(r.Context())+			if !ok {+				// This shouldn't have happened.+				http.Error(w, "error finding tenant", http.StatusUnauthorized)+				return+			}++			tms, ok := middlewares[tenant]+			if !ok {+				// No rate limits configured for this tenant.+				next.ServeHTTP(w, r)+				return+			}++			for _, m := range tms {+				if m.matcher.MatchString(r.URL.Path) {+					m.handler(next).ServeHTTP(w, r)+					return+				}+			}++			// No rate limits configured for this endpoint.+			next.ServeHTTP(w, r)+		})+	}+}++type rateLimiter struct {+	client gubernator.V1Client++	req *gubernator.RateLimitReq+}++func (l rateLimiter) Handler(next http.Handler) http.Handler {+	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+		ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)+		defer cancel()++		resp, err := l.client.GetRateLimits(ctx, &gubernator.GetRateLimitsReq{+			Requests: []*gubernator.RateLimitReq{l.req},+		})+		if err != nil {+			// TODO(kakkoyun): Should we add metric and fail gracefully gracefully?

I guess an error is only returned if the underlying service has an actual problem or there was some network issue, right? An expected error from the services should be part of the resp payload?! In that case, I'd say failing hard is the preferred way.

kakkoyun

comment created time in 12 days

PullRequestReviewEvent

Pull request review commentobservatorium/observatorium

Add rate limiting per tenant

+package ratelimit++import (+	"context"+	"fmt"+	"net/http"+	"regexp"+	"time"++	"github.com/go-chi/httprate"++	"github.com/observatorium/observatorium/internal"+	"github.com/observatorium/observatorium/internal/authentication"+	"github.com/observatorium/observatorium/internal/ratelimit/gubernator"+)++const (+	requestName    = "observatorium:tenant_per_endpoint"+	requestTimeout = time.Millisecond * 500+)++// Config configures a rate limiter per endpoint, per tenant.+type Config struct {+	Tenant  string+	Matcher *regexp.Regexp+	Limit   int+	Window  time.Duration+}++type middleware struct {+	matcher *regexp.Regexp+	handler internal.Middleware+}++// WithLocalRateLimiter returns a middleware that controls amount of requests per tenant using in-memory store.+func WithLocalRateLimiter(configs ...Config) internal.Middleware {+	middlewares := make(map[string][]middleware)+	for _, c := range configs {+		middlewares[c.Tenant] = append(middlewares[c.Tenant], middleware{c.Matcher, httprate.NewRateLimiter(+			c.Limit,+			c.Window,+			nil,+		).Handler})+	}++	return combine(middlewares)+}++// WithSharedRateLimiter returns a middleware that controls amount of requests per tenant using external service.+func WithSharedRateLimiter(client gubernator.V1Client, configs ...Config) internal.Middleware {+	middlewares := make(map[string][]middleware)+	for _, c := range configs {+		middlewares[c.Tenant] = append(middlewares[c.Tenant], middleware{c.Matcher, rateLimiter{client, &gubernator.RateLimitReq{+			Name:      requestName,+			UniqueKey: fmt.Sprintf("%s:%s", c.Tenant, c.Matcher.String()),+			Hits:      1,+			Limit:     int64(c.Limit),+			Duration:  c.Window.Microseconds(),+			Algorithm: gubernator.Algorithm_LEAKY_BUCKET,+		}}.Handler})+	}++	return combine(middlewares)+}++func combine(middlewares map[string][]middleware) func(next http.Handler) http.Handler {+	return func(next http.Handler) http.Handler {+		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+			tenant, ok := authentication.GetTenant(r.Context())+			if !ok {+				// This shouldn't have happened.+				http.Error(w, "error finding tenant", http.StatusUnauthorized)+				return+			}++			tms, ok := middlewares[tenant]+			if !ok {+				// No rate limits configured for this tenant.+				next.ServeHTTP(w, r)+				return+			}++			for _, m := range tms {+				if m.matcher.MatchString(r.URL.Path) {+					m.handler(next).ServeHTTP(w, r)+					return+				}+			}++			// No rate limits configured for this endpoint.+			next.ServeHTTP(w, r)+		})+	}+}++type rateLimiter struct {+	client gubernator.V1Client++	req *gubernator.RateLimitReq+}++func (l rateLimiter) Handler(next http.Handler) http.Handler {+	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+		ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
		ctx, cancel := context.WithTimeout(r.Context(), requestTimeout)
kakkoyun

comment created time in 12 days

PullRequestReviewEvent

pull request commentobservatorium/observatorium

Add rate limiting per tenant

Two broader things to change before I go into more detail with this PR.

  1. Can we leave the flags being parsed in the main.go file? We kept it there on purpose. It should be as easy to find as possible as this is the entry point most people look for when beginning to read through the code. :)
  2. Maybe we can move these proto files into a more meaningful package. protoc/google and protoc/gubernator don't mean that much. Personally, I'd say we should just have those (at least the gubernator ones) in the same package as the rest of the middleware files.
kakkoyun

comment created time in 13 days

delete branch metalmatze/conprof

delete branch : thanos-conprof

delete time in 14 days

push eventconprof/conprof

Matthias Loibl

commit sha dae952b9fea547b7f407dc0c81d17bc5342077f6

Replace thanos with conprof in Makefile

view details

Matthias Loibl

commit sha 9b0c2dffabdbfeb1de2443a9dd181a49c29add4a

Merge pull request #90 from metalmatze/thanos-conprof Replace thanos with conprof in Makefile

view details

push time in 14 days

PR merged conprof/conprof

Replace thanos with conprof in Makefile

Just saw this :shrug:

+2 -2

0 comment

1 changed file

metalmatze

pr closed time in 14 days

delete branch monitoring-mixins/mixtool

delete branch : update-jsonnet

delete time in 14 days

push eventmonitoring-mixins/mixtool

Tom Wilkie

commit sha 86599ae9b4357dee008b230efc8e3b9d10b526e3

Update jsonnet to 0.16 (#23) * Update jsonnet to 0.16 Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com> * Add anonymous import of github.com/gobuffalo/packr/v2. So 'go mod tidy' doesn't remove it. Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com> * Add license header. Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>

view details

push time in 14 days

PR merged monitoring-mixins/mixtool

Reviewers
Update jsonnet to 0.16

Signed-off-by: Tom Wilkie tom.wilkie@gmail.com

+27 -1

3 comments

3 changed files

tomwilkie

pr closed time in 14 days

pull request commentmonitoring-mixins/mixtool

Update jsonnet to 0.16

Nice!

tomwilkie

comment created time in 14 days

PR merged monitoring-mixins/mixtool

Reviewers
Remove vendor folder

Closes #21 Unblocks #23

+0 -635191

0 comment

1480 changed files

metalmatze

pr closed time in 14 days

delete branch monitoring-mixins/mixtool

delete branch : vendor-vacuum

delete time in 14 days

push eventmonitoring-mixins/mixtool

Matthias Loibl

commit sha 220799b43061dcccc09b82810e44f2e1d57f46a3

Remove vendor folder (#26) * Remove vendor/ from mixtool * go mod tidy

view details

push time in 14 days

issue closedmonitoring-mixins/mixtool

Remove vendor

go.mod should provide sufficient stability guarantees for not keeping vendor around. We don't have a vendor folder on Grafana Tanka and did not run into any issues.

Not having vendor benefits pull requests, because it keeps them smaller and eaiser to review.

Thoughts?

closed time in 14 days

sh0rez

PR opened monitoring-mixins/mixtool

Reviewers
Remove vendor folder

Closes #21 Unblocks #23

+0 -635191

0 comment

1480 changed files

pr created time in 14 days

create barnchmonitoring-mixins/mixtool

branch : vendor-vacuum

created branch time in 14 days

pull request commentmonitoring-mixins/mixtool

Update jsonnet to 0.16

Maybe let's remove vendor/ first and then update? :)

tomwilkie

comment created time in 14 days

Pull request review commentmonitoring-mixins/mixtool

cmd/mixtool/server.go: Add server command

+// Copyright 2018 mixtool authors+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+//     http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++package main++import (+	"bufio"+	"bytes"+	"context"+	"fmt"+	"io"+	"io/ioutil"+	"net/http"+	"os"++	"github.com/pkg/errors"+	"github.com/urfave/cli"+)++func serverCommand() cli.Command {+	return cli.Command{+		Name:        "server",+		Usage:       "Start a server to provision Prometheus rule file(s) with.",+		Description: "Start a server to provision Prometheus rule file(s) with.",+		Flags: []cli.Flag{+			cli.StringFlag{+				Name:  "bind-address",+				Usage: "Address to bind HTTP server to.",+			},+			cli.StringFlag{+				Name:  "prometheus-reload-url",+				Value: "http://127.0.0.1:9090/-/reload",+				Usage: "Prometheus address to reload after provisioning the rule file(s).",+			},+			cli.StringFlag{+				Name:  "rule-file",+				Usage: "File to provision rules into.",+			},+		},+		Action: serverAction,+	}+}++func serverAction(c *cli.Context) error {+	bindAddress := c.String("bind-address")+	http.Handle("/api/v1/rules", &ruleProvisioningHandler{+		ruleProvisioner: &ruleProvisioner{+			ruleFile: c.String("rule-file"),+		},+		prometheusReloader: &prometheusReloader{+			prometheusReloadURL: c.String("prometheus-reload-url"),+		},+	})+	return http.ListenAndServe(bindAddress, nil)+}++type ruleProvisioningHandler struct {+	ruleProvisioner    *ruleProvisioner+	prometheusReloader *prometheusReloader+}++func (h *ruleProvisioningHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {+	ctx := r.Context()+	if r.Method != "PUT" {+		http.Error(w, "Bad request: only PUT requests supported", http.StatusBadRequest)+		return+	}++	reloadNecessary, err := h.ruleProvisioner.provision(r.Body)+	if err != nil {+		http.Error(w, fmt.Sprintf("Internal Server Error: %v", err), http.StatusInternalServerError)+		return+	}++	if reloadNecessary {+		if err := h.prometheusReloader.trigger(ctx); err != nil {+			http.Error(w, fmt.Sprintf("Internal Server Error: %v", err), http.StatusInternalServerError)+			return+		}+	}+}++type ruleProvisioner struct {+	ruleFile string+}++// provision attempts to provision the rule files read from r, and if identical+// to existing, does not provision them. It returns whether Prometheus should+// be reloaded and if an error has occurred.+func (p *ruleProvisioner) provision(r io.Reader) (bool, error) {+	b := bytes.NewBuffer(nil)+	tr := io.TeeReader(r, b)++	f, err := os.Open(p.ruleFile)+	if err != nil && !os.IsNotExist(err) {+		return false, err+	}+	if os.IsNotExist(err) {+		f, err = os.Create(p.ruleFile)+		if err != nil {+			return false, err+		}+	}++	equal, err := readersEqual(tr, f)+	if err != nil {+		return false, err+	}+	if equal {+		return false, nil+	}++	if err := f.Truncate(0); err != nil {+		return false, err+	}++	if _, err := io.Copy(f, b); err != nil {+		return false, err+	}++	return true, nil+}++func readersEqual(r1, r2 io.Reader) (bool, error) {+	buf1 := bufio.NewReader(r1)+	buf2 := bufio.NewReader(r2)+	for {+		b1, err1 := buf1.ReadByte()+		b2, err2 := buf2.ReadByte()+		if err1 != nil && err1 != io.EOF {+			return false, err1+		}+		if err2 != nil && err2 != io.EOF {+			return false, err2+		}+		if err1 == io.EOF || err2 == io.EOF {+			return err1 == err2, nil+		}+		if b1 != b2 {+			return false, nil+		}+	}+}++type prometheusReloader struct {+	prometheusReloadURL string+}++func (r *prometheusReloader) trigger(ctx context.Context) error {+	req, err := http.NewRequest("POST", r.prometheusReloadURL, nil)+	if err != nil {+		return errors.Wrap(err, "create request")+	}+	req = req.WithContext(ctx)++	resp, err := http.DefaultClient.Do(req)+	if err != nil {+		return errors.Wrap(err, "reload request failed")+	}++	if _, err := io.Copy(ioutil.Discard, resp.Body); err != nil {+		return errors.Wrap(err, "exhausting request body failed")+	}

I might be mistaken, but if the body isn't read in any way, can't we ignore it here too?

brancz

comment created time in 14 days

more