Compare commits

...

910 commits

Author SHA1 Message Date
Matthias Rampke 58769c7b4d
Release 0.26.1
maintenance release, rolling up all the version updates.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2024-03-22 16:04:13 +00:00
Matthias Rampke 9c4dfce4e0
Merge pull request #550 from prometheus/mr/shorten-readme
Remove `--help` output from README
2024-03-22 15:57:54 +00:00
Matthias Rampke 29c77f407c
Remove --help output from README
I have no idea if it is even up to date. The README file was too large to fit
Docker Hub's limitations; this removal brings us just under the [25KB
limit](https://github.com/docker/hub-feedback/issues/238).

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2024-03-22 15:52:23 +00:00
Matthias Rampke 233d74d0f7
Merge pull request #549 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2024-03-22 15:41:43 +00:00
prombot 3f985fa9ac Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2024-03-22 15:28:27 +00:00
Matthias Rampke 479379a908
Merge pull request #548 from prometheus/dependabot/go_modules/google.golang.org/protobuf-1.33.0
Bump google.golang.org/protobuf from 1.32.0 to 1.33.0
2024-03-22 15:20:11 +00:00
Matthias Rampke 6e02dfcaae
Merge pull request #547 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2024-03-22 15:12:42 +00:00
dependabot[bot] 2c4ffa9620
Bump google.golang.org/protobuf from 1.32.0 to 1.33.0
Bumps google.golang.org/protobuf from 1.32.0 to 1.33.0.

---
updated-dependencies:
- dependency-name: google.golang.org/protobuf
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-13 23:37:16 +00:00
prombot ac0ef06e65 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2024-03-04 17:48:01 +00:00
Matthias Rampke 337849188c
Merge pull request #545 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2024-03-03 22:03:49 +01:00
prombot 4b21c8e662 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2024-03-03 17:47:54 +00:00
Matthias Rampke 91ccdb962a
Merge pull request #543 from prometheus/dependabot/go_modules/github.com/prometheus/client_golang-1.19.0
Bump github.com/prometheus/client_golang from 1.18.0 to 1.19.0
2024-03-03 14:57:34 +00:00
dependabot[bot] d93cb36b75
Bump github.com/prometheus/client_golang from 1.18.0 to 1.19.0
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.18.0 to 1.19.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/v1.19.0/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.18.0...v1.19.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-03 14:55:12 +00:00
Matthias Rampke 6483ce0ffe
Merge pull request #542 from prometheus/dependabot/go_modules/github.com/prometheus/client_model-0.6.0
Bump github.com/prometheus/client_model from 0.5.0 to 0.6.0
2024-03-03 14:53:30 +00:00
Matthias Rampke d5473a0f96
Merge pull request #540 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2024-03-03 14:53:17 +00:00
dependabot[bot] b9ee6639ce
Bump github.com/prometheus/client_model from 0.5.0 to 0.6.0
Bumps [github.com/prometheus/client_model](https://github.com/prometheus/client_model) from 0.5.0 to 0.6.0.
- [Release notes](https://github.com/prometheus/client_model/releases)
- [Commits](https://github.com/prometheus/client_model/compare/v0.5.0...v0.6.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_model
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-01 10:58:30 +00:00
prombot 80810d614e Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2024-02-23 17:47:48 +00:00
Ben Kochie cae614397a
Merge pull request #534 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2024-02-22 22:47:33 +01:00
Ben Kochie e729f64ef3
Merge pull request #537 from prometheus/dependabot/go_modules/github.com/prometheus/common-0.46.0
Bump github.com/prometheus/common from 0.45.0 to 0.46.0
2024-02-22 22:47:16 +01:00
dependabot[bot] adeacdd760
Bump github.com/prometheus/common from 0.45.0 to 0.46.0
Bumps [github.com/prometheus/common](https://github.com/prometheus/common) from 0.45.0 to 0.46.0.
- [Release notes](https://github.com/prometheus/common/releases)
- [Commits](https://github.com/prometheus/common/compare/v0.45.0...v0.46.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/common
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-01 10:15:22 +00:00
prombot a19a729111 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2024-01-16 17:47:57 +00:00
Ben Kochie 4c268bcdf7
Merge pull request #529 from prometheus/dependabot/go_modules/github.com/prometheus/exporter-toolkit-0.11.0
Bump github.com/prometheus/exporter-toolkit from 0.10.0 to 0.11.0
2024-01-16 15:41:46 +01:00
dependabot[bot] 8ec3225483
Bump github.com/prometheus/exporter-toolkit from 0.10.0 to 0.11.0
Bumps [github.com/prometheus/exporter-toolkit](https://github.com/prometheus/exporter-toolkit) from 0.10.0 to 0.11.0.
- [Release notes](https://github.com/prometheus/exporter-toolkit/releases)
- [Changelog](https://github.com/prometheus/exporter-toolkit/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prometheus/exporter-toolkit/compare/v0.10.0...v0.11.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/exporter-toolkit
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-15 22:03:46 +00:00
Ben Kochie 7d28d2145f
Merge pull request #527 from prometheus/dependabot/go_modules/golang.org/x/crypto-0.17.0
Bump golang.org/x/crypto from 0.14.0 to 0.17.0
2024-01-15 23:02:23 +01:00
dependabot[bot] 48b0038897
Bump golang.org/x/crypto from 0.14.0 to 0.17.0
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.17.0.
- [Commits](https://github.com/golang/crypto/compare/v0.14.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-15 21:53:36 +00:00
Matthias Rampke abc3a1f95c
Merge pull request #533 from prometheus/mr/issue-523/test-existing
Add more tests for gauge increment/decrement
2024-01-15 22:52:05 +01:00
Ben Kochie 4a0e88e27b
Merge pull request #528 from prometheus/dependabot/go_modules/github.com/prometheus/client_golang-1.18.0
Bump github.com/prometheus/client_golang from 1.17.0 to 1.18.0
2024-01-15 22:51:07 +01:00
Matthias Rampke 7188ed4292
Add more tests for gauge increment/decrement
Validate the behavior for relative gauge events as per [the statsd type metric type documentatoin](https://github.com/statsd/statsd/blob/master/docs/metric_types.md#gauges).

Reaffirms #523.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2024-01-15 22:44:07 +01:00
dependabot[bot] c48fa1bfa7
Bump github.com/prometheus/client_golang from 1.17.0 to 1.18.0
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.17.0 to 1.18.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.17.0...v1.18.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-15 21:35:46 +00:00
Ben Kochie 5d3e63295a
Merge pull request #526 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2024-01-15 22:35:30 +01:00
Matthias Rampke 8fdc626bfc
Merge pull request #532 from prometheus/superq/update_build
Update build
2024-01-15 21:25:53 +01:00
SuperQ 8adea73c00
Update build
* Update Go to 1.21.
* Cleanup unecessary build flags.
* Update minimum Go version to 1.20.

Fixes: https://github.com/prometheus/statsd_exporter/issues/531

Signed-off-by: SuperQ <superq@gmail.com>
2024-01-09 21:07:42 +01:00
prombot a853c2b0b2 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2023-12-07 17:47:56 +00:00
Matthias Rampke 2c7fd1edd4
Release 0.26.0
with documentation for #521 and changelog.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2023-12-06 09:52:31 +00:00
Matthias Rampke 1e89c26ad6
Merge pull request #521 from rabenhorst/mapping-honor-labels
Add configuration for keeping original labels in mappings
2023-12-06 09:44:26 +00:00
Matthias Rampke 413f482751
Merge pull request #520 from prometheus/dependabot/go_modules/github.com/prometheus/common-0.45.0
Bump github.com/prometheus/common from 0.44.0 to 0.45.0
2023-12-06 09:42:32 +00:00
Matthias Rampke f9d238dbdd
Merge pull request #524 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2023-12-06 09:42:19 +00:00
Matthias Rampke ef104085db
Merge pull request #525 from prometheus/dependabot/go_modules/github.com/alecthomas/kingpin/v2-2.4.0
Bump github.com/alecthomas/kingpin/v2 from 2.3.2 to 2.4.0
2023-12-06 09:42:06 +00:00
dependabot[bot] 0750ae0346
Bump github.com/alecthomas/kingpin/v2 from 2.3.2 to 2.4.0
Bumps [github.com/alecthomas/kingpin/v2](https://github.com/alecthomas/kingpin) from 2.3.2 to 2.4.0.
- [Release notes](https://github.com/alecthomas/kingpin/releases)
- [Commits](https://github.com/alecthomas/kingpin/compare/v2.3.2...v2.4.0)

---
updated-dependencies:
- dependency-name: github.com/alecthomas/kingpin/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-01 10:51:20 +00:00
prombot 51cc8e4659 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2023-11-20 17:48:20 +00:00
dependabot[bot] a9b63f9e5f
Bump github.com/prometheus/common from 0.44.0 to 0.45.0
Bumps [github.com/prometheus/common](https://github.com/prometheus/common) from 0.44.0 to 0.45.0.
- [Release notes](https://github.com/prometheus/common/releases)
- [Commits](https://github.com/prometheus/common/compare/v0.44.0...v0.45.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/common
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-20 09:03:36 +00:00
Matthias Rampke 736b8b676b
Merge pull request #522 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2023-11-20 09:03:00 +00:00
Matthias Rampke 5b8dfc866d
Merge pull request #519 from prometheus/dependabot/go_modules/github.com/prometheus/client_model-0.5.0
Bump github.com/prometheus/client_model from 0.4.1-0.20230718164431-9a2bf3000d16 to 0.5.0
2023-11-20 09:02:17 +00:00
prombot 3c4f1af3ff Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2023-11-03 17:48:57 +00:00
Sebastian Rabenhorst 4392beadc3
Added config to honor labels in mappings
Signed-off-by: Sebastian Rabenhorst <sebastian.rabenhorst@shopify.com>
2023-11-02 14:15:07 +01:00
dependabot[bot] 22381d60c5
Bump github.com/prometheus/client_model
Bumps [github.com/prometheus/client_model](https://github.com/prometheus/client_model) from 0.4.1-0.20230718164431-9a2bf3000d16 to 0.5.0.
- [Release notes](https://github.com/prometheus/client_model/releases)
- [Commits](https://github.com/prometheus/client_model/commits/v0.5.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_model
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-01 10:13:09 +00:00
Matthias Rampke 56fe4f51cd
Fix up changelog for 0.25.0
- thank the contributors
- fix typo

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2023-10-24 08:18:11 +00:00
Matthias Rampke 3855b3e8c9
Merge pull request #518 from prometheus/mr/release-0.25.0
Release 0.25.0
2023-10-23 18:29:35 +02:00
Matthias Rampke 3ea12e444f
Release 0.25.0
with changelog. Call out that the monitoring for dropped events needs to
adapt to continue to be useful.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2023-10-23 16:25:08 +00:00
Matthias Rampke fb1a02cf4a
Merge pull request #513 from prometheus/dependabot/go_modules/github.com/prometheus/client_golang-1.17.0
Bump github.com/prometheus/client_golang from 1.16.0 to 1.17.0
2023-10-23 18:19:55 +02:00
dependabot[bot] 8373cb382e
Bump github.com/prometheus/client_golang from 1.16.0 to 1.17.0
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.16.0 to 1.17.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.16.0...v1.17.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-23 16:06:10 +00:00
Matthias Rampke 3d8cac0b30
Merge pull request #514 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2023-10-23 18:05:47 +02:00
Matthias Rampke 2337d38124
Merge pull request #516 from prometheus/dependabot/go_modules/golang.org/x/net-0.17.0
Bump golang.org/x/net from 0.10.0 to 0.17.0
2023-10-23 18:04:27 +02:00
Matthias Rampke 12d14bb1d8
Merge pull request #511 from kullanici0606/master
Performance improvement - process udp packets in separate goroutine in order to minimize packet drops
2023-10-23 18:04:04 +02:00
kullanici0606 04ed8c69a9
fix typo
Co-authored-by: Matthias Rampke <matthias.rampke@googlemail.com>
Signed-off-by: kullanici0606 <35795498+kullanici0606@users.noreply.github.com>
2023-10-23 10:08:22 +03:00
kullanici0606 c246633aec add counter for dropped UDP packets. Remove unnecessary and misleading comment
Signed-off-by: kullanici0606 <yakup.turgut@btk.gov.tr>
2023-10-23 10:01:52 +03:00
dependabot[bot] 8e326ef3f3
Bump golang.org/x/net from 0.10.0 to 0.17.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.10.0 to 0.17.0.
- [Commits](https://github.com/golang/net/compare/v0.10.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-11 22:30:37 +00:00
prombot b98a84c3f6 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2023-10-02 17:48:56 +00:00
Matthias Rampke 5a947bd1a3
Merge pull request #512 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2023-09-26 20:51:09 +02:00
prombot ee8b05b646 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2023-09-25 17:49:17 +00:00
Matthias Rampke 3dcff5fed5
Merge pull request #509 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2023-09-25 15:50:54 +02:00
kullanici0606 aaaf26c074 avoid making copies of slices since we need to minimize the time spent in packet read in order not to drop packets
Signed-off-by: kullanici0606 <yakup.turgut@btk.gov.tr>
2023-09-20 10:37:53 +03:00
kullanici0606 b0c6d983e1 fix udp metrics increment
Signed-off-by: kullanici0606 <yakup.turgut@btk.gov.tr>
2023-09-20 10:37:53 +03:00
kullanici0606 ccb3eb6277 remove unnecessary log
Signed-off-by: kullanici0606 <yakup.turgut@btk.gov.tr>
2023-09-20 10:37:53 +03:00
kullanici0606 03255bf218 process udp packets in a separate goroutine so that udp packets are not dropped
Signed-off-by: kullanici0606 <yakup.turgut@btk.gov.tr>
2023-09-20 10:37:53 +03:00
Matthias Rampke 871e2d8df1
Merge pull request #510 from sumeshpremraj/spremraj/improve-network-debug-logging
Convert line payloads to string for debug logging
2023-07-10 22:39:30 +02:00
Sumesh Premraj 5123a1caa6 Convert line payload debug logs to string
Signed-off-by: Sumesh Premraj <sumeshpremraj@gmail.com>
2023-07-10 11:26:39 +02:00
prombot 3f8b98f180 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2023-07-07 17:48:32 +00:00
Matthias Rampke 886c18f947
Merge pull request #508 from prometheus/dependabot/go_modules/github.com/prometheus/client_golang-1.16.0
Bump github.com/prometheus/client_golang from 1.15.1 to 1.16.0
2023-07-07 15:42:49 +02:00
Matthias Rampke c76a152291
Merge pull request #507 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2023-07-07 15:42:13 +02:00
dependabot[bot] 69bc83fc47
Bump github.com/prometheus/client_golang from 1.15.1 to 1.16.0
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.15.1 to 1.16.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.15.1...v1.16.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-01 10:07:32 +00:00
prombot b1094b9061 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2023-06-27 17:49:01 +00:00
Matthias Rampke 8ffcdb3d5e
Merge pull request #506 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2023-06-19 06:56:45 +00:00
prombot 029cd6bca5 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2023-06-17 17:48:56 +00:00
Matthias Rampke e91ce201d5
Release 0.24.0
with changelogs for #504 and #499

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2023-06-02 07:49:36 +00:00
Matthias Rampke ddf7e0d31d
Merge pull request #504 from prometheus/superq/landing-page
Use exporter-toolkit landing page
2023-06-02 09:47:26 +02:00
Matthias Rampke 80e119a781
Merge pull request #499 from ebracho/master
Add `scale` field to mapping config
2023-06-02 09:46:01 +02:00
Matthias Rampke 191b07124c
Bump to 0.23.3
Accidentally based 0.23.2 off an older commit. Trying again.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2023-06-02 07:43:20 +00:00
Matthias Rampke f73cc98fd7
Release 0.23.2
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2023-06-02 07:39:14 +00:00
SuperQ 7f5125abdd
Use exporter-toolkit landing page
Use the exporter-toolkit to render the exporter homepage.
* Also allow metricsEndpoint to be on `/`.

Signed-off-by: SuperQ <superq@gmail.com>
2023-06-02 08:43:57 +02:00
Eddie Bracho 61f201130e document scale parameter
Signed-off-by: Eddie Bracho <eddiebracho@gmail.com>
2023-06-01 16:35:05 -07:00
Matthias Rampke 2813a69578
Merge pull request #501 from prometheus/dependabot/go_modules/github.com/prometheus/common-0.44.0
Bump github.com/prometheus/common from 0.42.0 to 0.44.0
2023-06-01 19:39:18 +00:00
dependabot[bot] 2a8dab9248
Bump github.com/prometheus/common from 0.42.0 to 0.44.0
Bumps [github.com/prometheus/common](https://github.com/prometheus/common) from 0.42.0 to 0.44.0.
- [Release notes](https://github.com/prometheus/common/releases)
- [Commits](https://github.com/prometheus/common/compare/v0.42.0...v0.44.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/common
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-01 19:22:13 +00:00
Matthias Rampke 5daeef52d8
Merge pull request #502 from prometheus/dependabot/go_modules/github.com/prometheus/client_model-0.4.0
Bump github.com/prometheus/client_model from 0.3.0 to 0.4.0
2023-06-01 19:21:24 +00:00
dependabot[bot] c87a7ac5eb
Bump github.com/prometheus/client_model from 0.3.0 to 0.4.0
Bumps [github.com/prometheus/client_model](https://github.com/prometheus/client_model) from 0.3.0 to 0.4.0.
- [Release notes](https://github.com/prometheus/client_model/releases)
- [Commits](https://github.com/prometheus/client_model/compare/v0.3.0...v0.4.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_model
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-01 19:06:52 +00:00
Matthias Rampke d747c05579
Merge pull request #503 from prometheus/dependabot/go_modules/github.com/prometheus/client_golang-1.15.1
Bump github.com/prometheus/client_golang from 1.14.0 to 1.15.1
2023-06-01 19:04:35 +00:00
Matthias Rampke 08c4bccb64
Update maintainer email
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2023-06-01 18:54:30 +00:00
dependabot[bot] a0f4bcff5c
Bump github.com/prometheus/client_golang from 1.14.0 to 1.15.1
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.14.0 to 1.15.1.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.14.0...v1.15.1)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-01 10:59:29 +00:00
Eddie Bracho fdc8b5f852 Add scale field to mapping config
This field allows configuring unit conversions in mappings. For example:

mappings:
- match: foo.latency_ms
  name: foo_latency_seconds
  scale: 0.001
- match: bar.processed_kb
  name: bar_processed_bytes
  scale: 1024

Signed-off-by: Eddie Bracho <eddiebracho@gmail.com>
2023-05-29 19:54:43 -07:00
Matthias Rampke c3752cf30f
Merge pull request #493 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2023-04-17 12:43:09 +00:00
prombot a5b0ed182c Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2023-03-21 17:49:21 +00:00
Matthias Rampke 972cb24750
Merge pull request #491 from grafana/gaantunes/mapperConfigDefaults-public
Making mapperConfigDefaults public
2023-03-16 17:56:08 +00:00
Gabriel Antunes 24e2fc9980 Making mapperConfigDefaults and metricObjective public, so that Grafana Agent can instantiate MetricMapper without using InitFromYAMLString directly.
Signed-off-by: Gabriel Antunes <g.amaral.antunes@gmail.com>
2023-03-15 16:34:31 -06:00
Matthias Rampke aa341da7c4
Merge pull request #492 from prometheus/dependabot/go_modules/google.golang.org/protobuf-1.29.1
Bump google.golang.org/protobuf from 1.29.0 to 1.29.1
2023-03-15 19:58:33 +00:00
dependabot[bot] fb5d639dbf
Bump google.golang.org/protobuf from 1.29.0 to 1.29.1
Bumps [google.golang.org/protobuf](https://github.com/protocolbuffers/protobuf-go) from 1.29.0 to 1.29.1.
- [Release notes](https://github.com/protocolbuffers/protobuf-go/releases)
- [Changelog](https://github.com/protocolbuffers/protobuf-go/blob/master/release.bash)
- [Commits](https://github.com/protocolbuffers/protobuf-go/compare/v1.29.0...v1.29.1)

---
updated-dependencies:
- dependency-name: google.golang.org/protobuf
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-14 23:06:26 +00:00
Matthias Rampke 14d18d8e70
Release 0.23.1
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2023-03-08 18:50:23 +00:00
Matthias Rampke bbba726e66
Merge pull request #490 from prometheus/mr/update-orb
Update Prometheus common orb
2023-03-08 18:47:59 +00:00
Matthias Rampke f0e9a8e2f8
Merge pull request #489 from prometheus/mr/update-kingpin
Update Go module dependencies
2023-03-08 18:47:48 +00:00
Matthias Rampke 0bdeac2162
Update Prometheus common orb
to fix issues with binfmt after the CircleCI infrastructure migration

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2023-03-08 18:21:13 +00:00
Matthias Rampke 9a980af22f
Update Go module dependencies
and switch to github.com/alecthomas/kingpin/v2 matching the changes in
prometheus/common

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2023-03-08 18:13:33 +00:00
Matthias Rampke 052676c42d
Merge pull request #485 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2023-02-20 22:27:47 +01:00
prombot 21a1763baf Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2023-02-20 17:48:46 +00:00
Matthias Rampke 832c5a5316
Merge pull request #484 from attenuation/master
Fix signalfx tag doc link
2023-01-27 14:53:50 +00:00
Jun Ouyang e22a86f5f9 fix 4040 link
Signed-off-by: Jun Ouyang <ouyangjun1999@gmail.com>
2023-01-27 20:18:43 +08:00
Matthias Rampke d73608eb14
Merge pull request #483 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2023-01-26 09:33:59 +00:00
prombot 9303da56a3 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2023-01-20 17:48:32 +00:00
Matthias Rampke 2caee689db
Merge pull request #478 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2023-01-05 09:11:02 +00:00
Matthias Rampke 07cf2fa0b1
Merge pull request #479 from prometheus/dependabot/go_modules/github.com/prometheus/common-0.39.0
Bump github.com/prometheus/common from 0.37.0 to 0.39.0
2023-01-05 09:10:47 +00:00
dependabot[bot] f6b2a21fbd
Bump github.com/prometheus/common from 0.37.0 to 0.39.0
Bumps [github.com/prometheus/common](https://github.com/prometheus/common) from 0.37.0 to 0.39.0.
- [Release notes](https://github.com/prometheus/common/releases)
- [Commits](https://github.com/prometheus/common/compare/v0.37.0...v0.39.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/common
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-01 10:02:07 +00:00
prombot c2447be23b Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2022-12-22 17:48:49 +00:00
Matthias Rampke b8ace4ae2c
Merge pull request #477 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2022-12-17 09:07:23 +00:00
prombot fea420de84 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2022-12-12 17:48:43 +00:00
Matthias Rampke 9c6e245521
Changelog for #474 & release
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2022-12-07 10:07:56 +00:00
Matthias Rampke f6ab38f75e
Merge pull request #474 from pedro-stanaka/feat/update-golang-prom-client-native-histograms
Update client_golang to enable native histograms
2022-12-07 09:59:01 +00:00
Pedro Tanaka 559fc9c1af
Fixing error in example YAML
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
2022-12-06 09:51:45 +01:00
Pedro Tanaka 507b0a20dd
Adding docs for new options
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
2022-12-06 09:49:25 +01:00
Pedro Tanaka f77011fd34
Allow creation of native histograms
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
2022-12-06 09:49:24 +01:00
Ben Kochie fbfa209c87
Merge pull request #476 from prometheus/superq/bump_go
Update Go
2022-11-29 07:28:08 -08:00
SuperQ fc1d834d59
Update Go
* Update to Go 1.19.
* Update some Go modules.

Signed-off-by: SuperQ <superq@gmail.com>
2022-11-29 15:33:57 +01:00
Matthias Rampke 81884eb3d8
Merge pull request #473 from prometheus/dependabot/go_modules/github.com/prometheus/client_model-0.3.0
Bump github.com/prometheus/client_model from 0.2.0 to 0.3.0
2022-11-07 18:00:07 +01:00
dependabot[bot] f231009802
Bump github.com/prometheus/client_model from 0.2.0 to 0.3.0
Bumps [github.com/prometheus/client_model](https://github.com/prometheus/client_model) from 0.2.0 to 0.3.0.
- [Release notes](https://github.com/prometheus/client_model/releases)
- [Commits](https://github.com/prometheus/client_model/compare/v0.2.0...v0.3.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_model
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-01 10:17:54 +00:00
Matthias Rampke dbdf4d9349
Merge pull request #468 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2022-09-22 23:26:45 +01:00
Matthias Rampke c74db12eaf
Merge pull request #470 from prometheus/matthiasr-patch-1
Changelog for #469
2022-09-22 23:26:16 +01:00
Matthias Rampke fd4ea19c21
Update VERSION
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2022-09-22 23:25:53 +01:00
Matthias Rampke 1bcb9d1a97
Changelog for #469
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2022-09-22 23:24:44 +01:00
Matthias Rampke a92aa4556e
Merge pull request #469 from don-philipe/Print-version-to-stdout
Print version, help etc to stdout
2022-09-22 23:22:24 +01:00
don-philipe 00d82daaf2
Print version, help etc to stdout
The default behavior of kingpin lib is to print stuff to stderr. This is now changed by using the os.Stdout writer. Now information like version and help text will be printed to stdout.

Signed-off-by: don-philipe <don_philipe@gmx.de>
2022-09-21 23:05:42 +02:00
prombot 65e7877ab3 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2022-09-21 17:54:26 +00:00
Matthias Rampke aecad1a2fa
Release 0.22.8
with changelog for #461 & #463

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2022-09-13 14:48:04 +00:00
Matthias Rampke 5d28e6d898
Merge pull request #463 from prometheus/dependabot/go_modules/github.com/prometheus/client_golang-1.13.0
Bump github.com/prometheus/client_golang from 1.12.2 to 1.13.0
2022-09-13 14:44:33 +00:00
Matthias Rampke edaa33860e
Merge pull request #461 from pedro-stanaka/fix/histogram-and-counters-clash
Counter with histogram suffix will clash with histogram
2022-09-13 14:43:11 +00:00
dependabot[bot] 89e7668d8d
Bump github.com/prometheus/client_golang from 1.12.2 to 1.13.0
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.12.2 to 1.13.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.12.2...v1.13.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-09-01 10:15:29 +00:00
Pedro Tanaka da06fabcb6
Use same error message
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
2022-08-29 08:53:50 +02:00
Pedro Tanaka 83cec219c8
Checking conflict for gauges as well and refactoring into function
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
2022-08-29 08:51:09 +02:00
Pedro Tanaka 31b05ef232
Fixing typo
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
2022-08-26 11:58:41 +02:00
Pedro Tanaka c41fa101f5
Bring back test cases after rebase problem
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
2022-08-26 11:57:57 +02:00
Pedro Tanaka 7afa060ce4
Fixing clash problem when counter clashes with previous registered histogram
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
2022-08-26 11:40:22 +02:00
Pedro Tanaka 30c3e31574
Improving isolation of metric conflict test
Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com>
2022-08-26 11:40:18 +02:00
Matthias Rampke e85098da3f
Merge pull request #455 from prometheus/dependabot/go_modules/github.com/prometheus/common-0.37.0
Bump github.com/prometheus/common from 0.35.0 to 0.37.0
2022-08-06 13:17:18 +00:00
dependabot[bot] d0585ec62b
Bump github.com/prometheus/common from 0.35.0 to 0.37.0
Bumps [github.com/prometheus/common](https://github.com/prometheus/common) from 0.35.0 to 0.37.0.
- [Release notes](https://github.com/prometheus/common/releases)
- [Commits](https://github.com/prometheus/common/compare/v0.35.0...v0.37.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/common
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-01 10:11:13 +00:00
Matthias Rampke af84364004
Merge pull request #453 from prometheus/mr/guard-logger-fsm
mapper: Make sure we have a logger before backtracking check
2022-07-29 15:06:37 +00:00
Matthias Rampke 1e801bc499
Merge pull request #454 from inosato/replace-ioutil
Remove ioutil
2022-07-29 15:06:24 +00:00
inosato b43a60e9c8 Remove ioutil
Signed-off-by: inosato <si17_21@yahoo.co.jp>
2022-07-29 23:39:29 +09:00
Matthias Rampke bc43c5606d
mapper: Make sure we have a logger before backtracking check
The FSM backtracking detection issues a log line. Make sure there is a
non-nil logger before doing that.

Avoids the crash in prometheus/graphite_exporter#197.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2022-07-29 11:46:57 +00:00
Matthias Rampke c2505cf91e
Release 0.22.7
more housekeeping!

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2022-07-08 13:39:38 +00:00
Matthias Rampke 8f351a5577
Merge pull request #450 from prometheus/superq/update_build
Update build
2022-07-08 13:36:27 +00:00
SuperQ b1068d058a
Update build
* Update Go to 1.18.
* Update Go modules to 1.17 format.
* Enable dependabot.
* Add yamllint config.

Signed-off-by: SuperQ <superq@gmail.com>
2022-07-08 15:25:18 +02:00
Matthias Rampke 3b9ef1fef5
Update changelog & release 0.22.6
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2022-07-08 12:51:22 +00:00
Matthias Rampke 9d4eeda5b1
Merge pull request #449 from prometheus/mr/dependency-update
housekeeping: update dependencies
2022-07-08 12:48:37 +00:00
Matthias Rampke c2c1af12ab
housekeeping: update dependencies
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2022-07-08 12:41:14 +00:00
Matthias Rampke 9115f0fa39
Merge pull request #447 from pedro-stanaka/feat/doc-special-regex-match
Adding documentation about special regex match group
2022-07-08 10:59:00 +00:00
Pedro Tanaka 6ef0b3b4e8 Changing issue number for tracking support for globbling
Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com>
2022-06-29 10:23:33 +02:00
Pedro Tanaka 1a148215de Adding note about behavior of .+ regex
Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com>
2022-06-29 10:22:12 +02:00
Pedro Tanaka f935a9c869 Adding documentation about special regex match group
Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com>
2022-06-29 10:22:12 +02:00
Matthias Rampke 3a63a4b86c
Merge pull request #445 from SandroJijavadze/fix-443-flaky-test
fix flaky test gosched hack
2022-06-28 20:18:13 +02:00
Sandro Jijavadze 2ab624a917 fix flaky test gosched hack
Signed-off-by: Sandro Jijavadze <sandrojijavadze@protonmail.com>
2022-06-22 15:31:41 +04:00
Matthias Rampke 848212e028
Merge pull request #440 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2022-06-18 11:58:53 +02:00
Matthias Rampke d90c8ff92d
Merge pull request #441 from pedro-stanaka/fix/benchmarks-mapper
Fixing broken benchmark for mapper
2022-06-18 10:17:07 +02:00
Pedro Tanaka 6e341dd805
Fixing broken benchmark for mapper
Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com>
2022-06-17 12:14:29 +02:00
prombot c753dfaf76 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2022-06-14 19:50:38 +00:00
Augustin Husson 0d22f85f04
Merge pull request #436 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2022-06-14 00:27:42 +02:00
prombot b8504edbe4 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2022-06-02 19:50:41 +00:00
Matthias Rampke c714dcdf2e
Add #434 to release notes
just in time for 0.22.5 :)

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2022-05-06 12:01:02 +00:00
Matthias Rampke dcddbc4234
Merge pull request #434 from pedro-stanaka/relay-new-line-count-metric
New metric for relayed lines
2022-05-06 11:56:27 +00:00
Matthias Rampke d46243aa66
Update Year 2022-05-06 11:56:04 +00:00
Matthias Rampke 4d07e28b7c
Release 0.22.5
no material changes, only a maintenance release.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2022-05-06 11:50:40 +00:00
Matthias Rampke ada7248ccb
Merge pull request #432 from prometheus/mr/go-image
Switch to cimg/go for build+test
2022-05-06 11:35:00 +00:00
Pedro Tanaka 0de518d3d5
Adding new metric to keep track of total relayed lines
* Adding new simple test to relay package
* Adding metric testing on relay
* Adding new metric to relay
* Adding new test section to check on metrics
* Fixing linting problems on new code
* Adding license headers on file

Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
2022-05-06 13:06:46 +02:00
Matthias Rampke 3427e36d50
Switch to cimg/go for build+test
To get off the [deprecated] circleci/golang.

Fixes #424.

[deprecated]: https://discuss.circleci.com/t/legacy-convenience-image-deprecation/41034

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2022-05-06 10:52:24 +00:00
Matthias Rampke 99a94fa8b4
Merge pull request #433 from prometheus/revert-429-relay-new-line-count-metric
Revert "New metric for total lines relayed"
2022-05-06 10:52:03 +00:00
Matthias Rampke 4b6983811e
Revert "New metric for total lines relayed"
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2022-05-06 10:50:13 +00:00
Matthias Rampke e416ec14d3
Merge pull request #429 from pedro-stanaka/relay-new-line-count-metric
New metric for total lines relayed
2022-05-06 10:43:17 +00:00
Ben Kochie f8fc001bba
Merge pull request #431 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2022-05-05 22:24:34 +02:00
prombot 542ee7cfa9 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2022-05-05 19:50:36 +00:00
Ben Kochie 0cb34c771d
Merge pull request #430 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2022-05-03 22:17:13 +02:00
prombot 549a96a54c Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2022-05-03 19:50:38 +00:00
Pedro Tanaka fbf7837387
Fixing linting problems on new code
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
2022-04-26 21:07:02 +02:00
Pedro Tanaka d015cda365
Adding new test section to check on metrics
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
2022-04-22 14:58:21 +02:00
Pedro Tanaka 2d339b0853
Adding new metric to relay
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
2022-04-21 11:47:19 +02:00
Pedro Tanaka 60742e1bd6
Adding metric testing on relay
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
2022-04-21 11:43:58 +02:00
Pedro Tanaka 78dcd3b7b2
Adding new simple test to relay package
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
2022-04-21 08:27:16 +02:00
Matthias Rampke 4ad11fcafa
Merge pull request #426 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2022-03-31 22:12:52 +02:00
prombot 2f5add464e Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2022-03-31 19:50:48 +00:00
Matthias Rampke 4a086bc25b
Merge pull request #423 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2022-03-14 21:20:08 +01:00
prombot 55e536bc15 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2022-03-14 19:50:37 +00:00
Matthias Rampke 161f982ae2
Merge pull request #422 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2022-03-12 21:58:56 +01:00
prombot 5654505569 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2022-03-10 19:50:26 +00:00
Matthias Rampke 1a1dd2d8a3
Merge pull request #421 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2022-03-09 09:38:18 +01:00
prombot b8462d09ec Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2022-03-08 19:50:28 +00:00
Matthias Rampke c481b95155
Merge pull request #419 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2022-03-08 09:45:11 +01:00
prombot b1222831b6 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2022-03-03 19:50:41 +00:00
Matthias Rampke db4a4f2fbe
Merge pull request #415 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2021-12-19 12:03:11 +01:00
prombot 83180ae37f Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2021-12-15 00:01:52 +00:00
Matthias Rampke 5c6c8a28d0
Merge pull request #412 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2021-11-27 10:02:07 +01:00
prombot a32a9da527 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2021-11-27 00:01:51 +00:00
Matthias Rampke 7e2fe6c2e6
Bump version & add changelog for #409 #410
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-11-26 10:32:37 +00:00
Matthias Rampke 7ba3f6a841
Merge pull request #409 from aleksandr-vin/aleksandr-vin-patch-1
Set numeric user to comply runAsNonRoot k8s policy
2021-11-26 11:22:06 +01:00
Matthias Rampke 6a5a089597
Merge pull request #410 from mattdurham/use_instance_registry
Use the instance registry instead of the prometheus.registry
2021-11-26 11:20:40 +01:00
Matthias Rampke 6564725760
Merge pull request #411 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2021-11-26 11:13:56 +01:00
prombot bfdf4ddee0 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2021-11-26 00:01:50 +00:00
Matt Durham aadb43ed02 Use the instance registry instead of the prometheus.registry
Signed-off-by: Matt Durham <mattdurham@ppog.org>
2021-11-17 11:37:39 -05:00
Aleksandr Vinokurov 258c8c0b2c
Set numeric user to comply runAsNonRoot k8s policy
When in k8s, container has `runAsNonRoot` policy and image has non-numeric user (nobody), then the deployment will fail as it cannot verify user is non-root.

Closes #406

Signed-off-by: Aleksandr Vinokurov <aleksandr.vin@gmail.com>
2021-11-16 17:48:56 +01:00
Matthias Rampke fae515f739
Merge pull request #405 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2021-11-12 16:57:43 +01:00
prombot 339c8efb33 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2021-11-09 00:01:47 +00:00
Matthias Rampke 16d4f317a5
Release 0.22.3
with changelog for #402

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-10-26 11:24:33 +00:00
Matthias Rampke 6c0283942c
Merge pull request #402 from agneum/389-allow-multiple-dashes
feat: handle multiple dashes in unmapped metrics (#389)
2021-10-26 13:13:52 +02:00
Matthias Rampke d0d948ee05
Merge pull request #404 from agneum/364-enable-more-linters
feat: enable more linters and fix warnings (#364)
2021-10-26 13:12:42 +02:00
Matthias Rampke 69b17ee390
Merge pull request #403 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2021-10-26 13:09:38 +02:00
akartasov 697eb33e2c
fix: remove vendor and disable-all options, disable the errcheck linter
Signed-off-by: akartasov <agneum@gmail.com>
2021-10-25 09:13:44 +07:00
akartasov b60989291b
feat: enable more linters and fix warnings (#364)
Signed-off-by: akartasov <agneum@gmail.com>
2021-10-24 21:27:31 +07:00
prombot f699c4ae94 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2021-10-24 00:01:42 +00:00
akartasov b6fc5ded9f
fix linter warnings: goimports, wsl
Signed-off-by: akartasov <agneum@gmail.com>
2021-10-24 00:13:53 +07:00
akartasov 2ab2c442cf
feat: handle double dashes in unmapped metrics (#389)
Signed-off-by: akartasov <agneum@gmail.com>
2021-10-23 23:53:47 +07:00
Ben Kochie 95d34445ed
Merge pull request #401 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2021-10-23 10:25:49 +02:00
prombot 83513ab186 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2021-10-23 00:01:50 +00:00
Matthias Rampke 5c8622abc1
Merge pull request #400 from prometheus/beorn7/deprecation
Add deprecation note to pkg directory
2021-10-14 13:22:22 +02:00
beorn7 4946fc865c Add deprecation note to pkg directory
Signed-off-by: beorn7 <beorn@grafana.com>
2021-10-13 14:40:09 +02:00
Ben Kochie d4e89cd38c
Merge pull request #398 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2021-09-12 12:46:18 +02:00
prombot f0c6a23b8c Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2021-09-12 00:02:12 +00:00
Ben Kochie f7894137b8
Merge pull request #395 from prometheus/superq/release_0.22.2
Release 0.22.2
2021-09-10 12:06:29 +02:00
SuperQ 9200507034
Release 0.22.2
* [ENHANCEMENT] Add metrics to relay ([#393](https://github.com/prometheus/statsd_exporter/pull/393))

Signed-off-by: SuperQ <superq@gmail.com>
2021-09-10 10:31:53 +02:00
Ben Kochie 884a8c0a21
Merge pull request #393 from prometheus/superq/relay_metrics
Add metrics to relay
2021-09-10 10:26:42 +02:00
SuperQ ae26c506f5
Add metrics to relay
Add some metrics to the statsd relay.
* The number of StatsD packets relayed.
* The number lines that were too long to relay.

Also convert main.go to use promauto for metric registration.

Signed-off-by: SuperQ <superq@gmail.com>
2021-09-02 11:57:39 +02:00
Matthias Rampke f39c9c3645
Merge pull request #392 from prometheus/mr/update-scenarios
Update transition scenarios
2021-09-01 17:51:24 +02:00
Matthias Rampke f5c6a55c0d
Update transition scenarios
Recommend running the exporter as a sidecar, now that the relay feature
makes this easy.

Re-order the overview section to put the final state first, then explain
transition and try-out options.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-09-01 15:59:07 +02:00
Matthias Rampke 9b31bb8533
Add changelog entry for #390 & #388
fix ordering, and prepare to release today

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-09-01 15:20:47 +02:00
Matthias Rampke e86e67a7cf
Merge pull request #388 from prometheus/superq/relay
Add statsd relay
2021-09-01 15:17:44 +02:00
SuperQ 0b84893d4a
Add statsd relay
Add a simple statsd packet output relay that buffers and forwards raw
statsd lines.
* Only supports UDP output.
* Has a hard-coded buffering timeout of 1 second.

Closes: https://github.com/prometheus/statsd_exporter/issues/95

Signed-off-by: SuperQ <superq@gmail.com>
2021-09-01 15:14:01 +02:00
Matthias Rampke b04eba273a
Merge pull request #391 from prometheus/superq/go1.17
Update build for Go 1.17
2021-09-01 15:12:12 +02:00
Matthias Rampke 6c43ebbc79
Merge pull request #390 from royeo/feature/replace-level-pkg
refactor: replace level pkg
2021-09-01 15:08:40 +02:00
SuperQ 37da8dd118
Update build for Go 1.17
* Update to Go 1.17.
* Update Go mods.

Signed-off-by: SuperQ <superq@gmail.com>
2021-09-01 14:29:08 +02:00
davinlu 6329577a6b refactor: replace level pkg
Signed-off-by: davinlu <davinlu@tencent.com>
2021-09-01 18:55:45 +08:00
Matthias Rampke d57c8b11f3
Changelog for #381
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-08-31 17:56:35 +02:00
Matthias Rampke a9c883a298
Merge pull request #381 from evandam/allow-multi-dash
allow multiple dashes in StatsD metric names
2021-08-31 17:55:00 +02:00
Matthias Rampke f9fea18a92
Skip version 0.22.0
it failed the license check.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-08-31 17:49:20 +02:00
Matthias Rampke e84990974b
Merge pull request #382 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2021-08-31 17:34:33 +02:00
Matthias Rampke 42158f5cca
Manually sync Makefile.common
to unstick the repo-sync PR

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-08-31 12:51:32 +02:00
prombot 1f53a743c7
Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2021-08-31 12:42:35 +02:00
Matthias Rampke eea2c0f734
Back out of release 0.22.0
the main change (#385) is missing license headers

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-08-31 12:41:32 +02:00
Matthias Rampke 828d50cea5
Merge pull request #387 from prometheus/revert-385-master
Revert "replace level pkg"
2021-08-31 12:40:34 +02:00
Matthias Rampke c4f435e140
Revert "replace level pkg" 2021-08-31 12:39:34 +02:00
Matthias Rampke efdf11343c
Release 0.22.0
with changelog for #385 #386

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-08-31 12:24:24 +02:00
Matthias Rampke e395798230
Merge pull request #386 from royeo/feature/pprof
use http.DefaultServeMux to support pprof
2021-08-31 12:05:55 +02:00
Matthias Rampke 4c8028e865
Merge pull request #385 from royeo/master
replace level pkg
2021-08-31 12:05:27 +02:00
royeo c3a818ef62 replace level pkg
Signed-off-by: royeo <ljn6176@gmail.com>
2021-08-17 23:27:27 +08:00
davinlu f4fe58dcf2 use http.DefaultServeMux to support pprof
Signed-off-by: davinlu <davinlu@tencent.com>
2021-08-16 22:24:08 +08:00
Evan Van Dam abb7ec0afb allow multiple dashes in StatsD metric names
Signed-off-by: Evan Van Dam <evan.vandam@wonolo.com>
2021-06-17 09:43:40 -07:00
Matthias Rampke ef6627b9f0
Changelog & version bump for #379
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-06-10 07:23:17 +00:00
Matthias Rampke 5ea682c01f
Merge pull request #379 from sagikazarmark/update-prom-libs
Update prom libs
2021-06-09 19:05:31 +02:00
Márk Sági-Kazár 04bc13d73c
refactor: use structured logging
Co-authored-by: Ben Kochie <superq@gmail.com>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-06-09 14:44:55 +02:00
Mark Sagi-Kazar 2852aa2a5b
chore(deps): update common package
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-06-07 16:34:48 +02:00
Mark Sagi-Kazar 278a862099
refactor: use go-kit logger instead of deprecated common log package
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-06-07 16:00:08 +02:00
Mark Sagi-Kazar 5f419f96dd
chore(deps): update client_golang
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-06-07 15:39:54 +02:00
Matthias Rampke 2d1face4e0
Changelog for #378 & release 0.20.3
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-06-04 08:02:05 +00:00
Matthias Rampke 7e3a7a5068
Merge pull request #378 from howardjohn/go-kit-log
Update dependencies and drop large go-kit update
2021-06-04 09:57:29 +02:00
John Howard c5113b732c Update dependencies and drop large go-kit update
Pulling in the same changes as done in
https://github.com/prometheus/common/issues/255

Signed-off-by: John Howard <howardjohn@google.com>
2021-06-03 08:00:27 -07:00
Matthias Rampke 1a86938882
Merge pull request #374 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2021-05-06 11:52:31 +02:00
Matthias Rampke cd27e25711
Merge pull request #376 from royeo/master
Fix comment
2021-05-06 11:51:57 +02:00
royeo 393b4ca495 Fix comment
Signed-off-by: royeo <ljn6176@gmail.com>
2021-05-06 16:08:29 +08:00
Matthias Rampke ea25c7a114
Release 0.20.2
with changelog for #375

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-05-03 15:25:02 +00:00
Matthias Rampke 2a6bbd7827
Merge pull request #375 from bakins/lru-cache
Use groupcache for LRU cache
2021-05-03 17:19:39 +02:00
Brian Akins a8f8067315 Use groupcache for LRU cache
Signed-off-by: Brian Akins <205350+bakins@users.noreply.github.com>
2021-04-28 12:15:19 -04:00
prombot c552b8b84b Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2021-04-14 00:01:41 +00:00
Matthias Rampke ce538cbae2
Merge pull request #373 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2021-04-01 08:31:59 +02:00
prombot b8d1fde4e4 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2021-03-31 00:01:37 +00:00
Matthias Rampke 2b5239a67f
Changelog for #365, cut bugfix release
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-03-26 17:23:09 +00:00
Matthias Rampke a8c09aaa97
Merge pull request #365 from glightfoot/segment-numbers
Support metric name segments starting with numbers
2021-03-26 18:20:30 +01:00
Matthias Rampke 5793e05795
Add additional tests for #365
testing more edge cases.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-03-26 16:54:29 +00:00
Matthias Rampke 5f7d52f795 Changelog for #363 & version bump 2021-03-26 09:12:50 +00:00
Matthias Rampke 84e68332f3
Merge pull request #366 from prometheus/matthiasr/gitpod-setup
Add configuration for Gitpod
2021-03-26 10:02:24 +01:00
Matthias Rampke 12281a972e
Merge pull request #363 from glightfoot/cache-interface
Better mapper cache interface
2021-03-26 10:00:30 +01:00
Matthias Rampke 8b496dfab5
Merge pull request #372 from matthiasr/mr/fix-yaml-backslash-quoting
Escape backslashes in regex examples
2021-03-23 18:30:24 +01:00
Matthias Rampke da69d725d0 Escape backslashes in regex examples
In double-quoted strings, the backslash is [special to YAML](http://blogs.perl.org/users/tinita/2018/03/strings-in-yaml---to-quote-or-not-to-quote.html).
Make sure that the examples do this correctly.
Fixes the wonky rendering on github.com.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2021-03-23 17:05:56 +00:00
Matthias Rampke e462a256b1
Merge pull request #370 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2021-03-23 07:12:54 +01:00
prombot ad8d919409 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2021-03-22 00:02:18 +00:00
Matthias Rampke 0151d93b46
Merge pull request #369 from prometheus/superq/vendor
Update build
2021-03-18 15:08:04 +01:00
Ben Kochie 8e28d7acca
Update build
* Drop /vendor.
* Bump Go modules.
* Bump build orb.

Signed-off-by: Ben Kochie <superq@gmail.com>
2021-03-18 11:18:02 +01:00
Ben Kochie ad0c3a62e1
Merge pull request #368 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2021-03-18 11:12:46 +01:00
Ben Kochie 094f3cd9e5
Bump Go to 1.16.
Signed-off-by: Ben Kochie <superq@gmail.com>
2021-03-18 10:47:05 +01:00
prombot 4962fd01ae Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2021-03-18 00:02:33 +00:00
Matthias Rampke b3aafad8f0
Merge pull request #367 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2021-03-17 23:09:41 +01:00
prombot b1045e33ac Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2021-03-17 00:02:33 +00:00
Matthias Rampke f1ca904c98 Fully automate dev setup with Gitpod
This commit implements a fully-automated development setup using Gitpod.io, an
online IDE for GitLab, GitHub, and Bitbucket that enables Dev-Environments-As-Code.
This makes it easy for anyone to get a ready-to-code workspace for any branch,
issue or pull request almost instantly with a single click.

Similar to prometheus/prometheus#7749.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2021-03-09 21:38:17 +00:00
glightfoot a197834f64 Add comments about thread-safety
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2021-02-19 14:13:03 -05:00
glightfoot 8b306c8c76 remove noop cache, add helper function for tests
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2021-02-19 14:08:53 -05:00
glightfoot 0c4a66e6a1 rework metricLineRE to support matching segments that start with a number
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2021-02-07 11:21:48 -05:00
glightfoot aa529c8884 rename mapper_cache to mappercache
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2021-02-06 23:27:11 -05:00
glightfoot 940e653ea6 cleanup
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2021-02-06 23:21:49 -05:00
glightfoot 32c612d5e8 add license
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2021-02-06 23:03:46 -05:00
glightfoot de9a51c863 fix TestMultipleMatches mapping indent
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2021-02-06 23:00:06 -05:00
glightfoot 0099df7f71 move lru and rr mapper caches to their own package and make mapper_cache a better an interface for implementing externally`
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2021-02-06 22:50:17 -05:00
Matthias Rampke fbcadbf71b
Changelog for #361 & release 0.20.0
add extra note about the deprecated attributes, eventually I want to
get rid of them.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-02-05 16:53:35 +00:00
Matthias Rampke eeeedce405
Merge pull request #361 from glightfoot/defaults2
Allow setting defaults for histogram and summary options
2021-02-05 16:32:22 +00:00
Matthias Rampke 8115b37bd9
Changelog for #360 & patch release
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-01-29 10:25:04 +00:00
Matthias Rampke 799943cb47
Merge pull request #360 from glightfoot/quit
Don't return empty responses to lifecycle api requests
2021-01-29 10:08:05 +00:00
glightfoot ee3b81b864 use a quit channel and log exit messages
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2021-01-28 15:23:46 -05:00
glightfoot f8bba00868 format and clarify alias type comment
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2021-01-28 14:24:41 -05:00
glightfoot 66a63a8c1f use summary options defaults in registry
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2021-01-28 14:16:40 -05:00
glightfoot 58aed41ff2 remove deprecated fields from mapper defaults config
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2021-01-28 13:59:42 -05:00
glightfoot 06411336c7 add support for setting histogram_options and summary_options in defaults
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2021-01-28 13:58:52 -05:00
glightfoot 6a9749cd42 don't return empty responses to lifecycle api requests
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2021-01-26 13:33:35 -05:00
Matthias Rampke 64dd103e3f
Merge pull request #354 from prometheus/mr/glob-regex-documentation
Reorder and rework glob vs. regex documentation
2021-01-22 12:58:01 +00:00
Matthias Rampke bade06f775
Clarify ordering more
Instead of saying what users should not do, provide a positive
recommendation.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-01-22 12:55:37 +00:00
Matthias Rampke 4171ba0c9b
Add changelog entry for #357
bring entries into the correct order and prepare to release today

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2021-01-22 12:40:09 +00:00
Matthias Rampke eef7922de8
Merge pull request #357 from alexanderritola/reorder-checkconfig
Refactor startup order to not grab ports when checkConfig is true
2021-01-22 12:37:16 +00:00
alexanderritola 175e9a6728 Refactor startup order to not grab ports when checkConfig is true
Signed-off-by: alexanderritola <alexanderritola@users.noreply.github.com>
2021-01-20 11:37:58 -08:00
Matthias Rampke cafe6c75b8
Merge pull request #356 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2021-01-18 08:30:29 +00:00
prombot 7e8ab9bad7 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2021-01-18 00:05:00 +00:00
Matthias Rampke 64c79eea8b
Reorder and rework glob vs. regex documentation
Note that regular expression matches are only evaluated after glob
matches. Add headings and introductory sentences to each glob type.

Remove the technical reasoning for choosing glob vs. regex; instead
explain the performance implications and gotchas of each type in turn.

Closes #349.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2020-12-18 09:24:47 +00:00
Matthias Rampke 5a7d7fe3d0
Merge pull request #352 from bakins/parser-interface
Use a Parser interface to allow alternate implementations
2020-12-18 09:50:43 +01:00
bakins 709c0da81b Use a Parser interface to allow alternate implementations
Signed-off-by: bakins <brian@akins.org>
2020-12-10 13:17:46 -05:00
Matthias Rampke 8b2b4c1a2b
Changelog for #347 2020-11-24 08:20:27 +00:00
Matthias Rampke 8772c03c0f
Merge pull request #347 from grafana/custom-registry
Pass around custom registry for registering exporter metrics
2020-11-24 09:18:10 +01:00
Robert Fratto b5deeda251 Pass around custom registry for registering exporter metrics
Importers of pkg/exporter may not want for series to be imported into
the default registry. This commit makes it possible to provide a custom
registry for metrics registration.

Signed-off-by: Robert Fratto <robertfratto@gmail.com>
2020-11-20 14:14:14 -05:00
Matthias Rampke dcd95d01df
Merge pull request #345 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2020-11-04 17:57:22 +00:00
prombot dc1f856da1 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2020-11-04 00:10:00 +00:00
Matthias Rampke 7c792fba66
Merge pull request #344 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2020-10-23 09:46:37 +02:00
Matthias Rampke 45b616fe8c
Merge pull request #343 from bakins/registry-interface
Use an interface for Registry so we may have alternate implementations
2020-10-23 09:37:19 +02:00
prombot ede356f65e Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2020-10-23 00:10:05 +00:00
bakins 4acb05aa89 Use an interface for Registry so we may have multiple implementations
Signed-off-by: bakins <brian@akins.org>
2020-10-22 10:08:57 -04:00
Matthias Rampke 420dc651d8
Version bump + changelog for #339
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2020-10-15 07:03:16 +00:00
Matthias Rampke cba4a0783a
Merge pull request #339 from yaron-idan/add-health-endpoint
add healthcheck endpoint
2020-10-15 07:01:42 +00:00
Yaron Idan f5e400962a remove flag and add ready endpoint
Signed-off-by: Yaron Idan <yaronidan@gmail.com>
2020-10-13 14:15:04 +03:00
Matthias Rampke 3ed211ec7a
Merge pull request #341 from dsabsay/cleanup-docs
Minor documentation improvements
2020-10-05 09:41:04 +00:00
Matthias Rampke e7b26d48bc
Merge pull request #340 from roidelapluie/115go
Bump go to 1.15
2020-10-05 09:39:58 +00:00
Daniel Sabsay 07c754c759 Minor documentation fixes
* Fix CLI help for --statsd.event-flush-interval
* Move verbiage regarding default histogram bucket values to proper
  section

Signed-off-by: Daniel Sabsay <sabsay@adobe.com>
2020-09-28 10:42:44 -07:00
Julien Pivotto a94056e060 Bump go to 1.15
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2020-09-14 18:46:06 +02:00
Yaron Idan f0c7abebb1 add healthcheck endpoint
Signed-off-by: Yaron Idan <yaronidan@gmail.com>
2020-09-12 17:24:50 +03:00
Matthias Rampke da85f9d207
Merge pull request #335 from shmsr/dup-init-vars
Avoid double initialization of variables
2020-09-07 09:38:12 +02:00
Matthias Rampke 477d566101
Merge pull request #334 from shmsr/error-small-case
Error strings shouldn't be capitalized
2020-09-07 09:34:11 +02:00
subham sarkar 4c0e26bfa1 Avoid unnecessary initialization of variables
This commit fixes the case when the metric is not present in rm (registered metric) then LastRegisteredAt and TTL are initialized twice. Firstly, LastRegisteredAt is initialized with the time.Time's zero value and then with clock.Now(). Plus, TTL is initialized with the same value twice.

Signed-off-by: subham sarkar <subham.sarkar@guavus.com>
2020-09-06 16:49:25 +05:30
subham sarkar 2c4cda7fb3 Change casing of error messages
Error messages shouldn't be capitalized.

Signed-off-by: subham sarkar <subham.sarkar@guavus.com>
2020-09-06 16:33:18 +05:30
Matthias Rampke 424d4781ca
Merge pull request #333 from shmsr/gauge-interface
Use prometheus.Gauge interface instead of prometheus.Counter
2020-09-04 17:08:20 +02:00
subham sarkar d93907009c Use prometheus.Gauge interface instead of prometheus.Counter
Signed-off-by: subham sarkar <subham.sarkar@guavus.com>
2020-09-04 20:14:32 +05:30
Matthias Rampke b19217a19b
Merge pull request #332 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2020-09-03 08:28:35 +02:00
prombot 96410eb4f5 Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2020-09-03 00:10:16 +00:00
Matthias Rampke bac6cbe8c5
Release 0.18.0
with changelog entries for #325 and #329.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2020-08-21 10:09:37 +00:00
Matthias Rampke a73707d102
Merge pull request #329 from glightfoot/reload-api
Add lifecycle api
2020-08-21 12:02:18 +02:00
Matthias Rampke e0a39974e2
Merge pull request #325 from glightfoot/disable-tags
Optionally disable tag parsing
2020-08-21 11:42:33 +02:00
glightfoot c162b349b7 add parsing flags to README
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-08-10 14:55:57 -04:00
glightfoot 1293a24b59 add lifecycle api
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-08-10 14:46:44 -04:00
glightfoot afa40f4ada rename cli flags for parsing and add docs to README
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-08-10 12:56:23 -04:00
glightfoot 6942b5a4f3 move to line parser struct and option functions
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-08-10 12:44:23 -04:00
glightfoot db25b1d658 add line tests for disabling individual tag formats
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-07-28 13:30:34 -04:00
glightfoot 3f3ab23359 add globals for disabling individual tag parsing formats
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-07-28 13:29:06 -04:00
Matthias Rampke da4a2950a7
Merge pull request #323 from glightfoot/improve-benchmarks
break out line benchmarks by format
2020-07-20 07:24:18 +00:00
glightfoot 2bea72dd37 use named sub-benchmarks
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-07-09 19:10:08 -04:00
glightfoot 9763353a54 Merge branch 'master' of github.com:prometheus/statsd_exporter into improve-benchmarks 2020-07-08 15:07:05 -04:00
glightfoot baa976dc6e break out line benchmarks by format
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-07-08 13:23:13 -04:00
Matthias Rampke e43831c078
Merge pull request #321 from glightfoot/improve-benchmarks
improve benchmark validity by not measuring startup costs
2020-07-02 22:19:44 +02:00
glightfoot 8c97daddee improve benchmark validity by not measuring startup costs
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-07-02 15:25:25 -04:00
Matthias Rampke b162bd047a
Release 0.17.0
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2020-06-26 15:19:16 +00:00
Matthias Rampke cc709f242c
Update changelog and readme for #315: SignalFX extension
Declare the behavior with mixed tagging as undefined, we don't want to
promise anything in that case, not even negatively.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2020-06-26 15:18:04 +00:00
Matthias Rampke 36de8c9e12
Merge pull request #315 from glightfoot/signalfx
[268] Support SignalFx Tags
2020-06-26 17:08:49 +02:00
Matthias Rampke 7cbd9525d2
Merge pull request #320 from prometheus/repo_sync
Synchronize common files from prometheus/prometheus
2020-06-25 20:47:52 +02:00
Matthias Rampke a991a4ba57
Merge pull request #318 from glightfoot/fix-event
rename events for consistency
2020-06-23 13:30:32 +02:00
prombot fb382a2fea Update common Prometheus files
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2020-06-23 00:11:03 +00:00
glightfoot 15eece3cf8 rename events for consistency
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-22 14:53:52 -04:00
glightfoot 9faa4898de abort parsing tags if malformed signalfx format, add tests
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-19 14:40:26 -04:00
glightfoot 5b863848dd adding more tests for malformed signalfx tags
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-19 09:10:19 -04:00
glightfoot 4f7abe5226 Merge branch 'master' of github.com:prometheus/statsd_exporter into signalfx 2020-06-19 09:05:10 -04:00
Matthias Rampke f1de97dbdd
Add changelog for #309
and fix ordering and naming of the entries

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2020-06-19 12:18:07 +00:00
Matthias Rampke ab73924e53
Merge pull request #317 from prometheus/mr/document-314
Changelog and documentation update for #314
2020-06-19 14:15:24 +02:00
Matthias Rampke ed37775e02
Merge pull request #309 from prometheus/mr/issue-256
Allow single-letter components in metric names
2020-06-19 14:15:01 +02:00
Matthias Rampke b64e07c7d9
Changelog and documentation update for #314
Update the README to reflect #314. Add an entry to the changelog
with extended compatibility notes.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2020-06-19 11:56:55 +00:00
Matthias Rampke 7ba3550f8f
Merge pull request #314 from glightfoot/histogram-type
[307] Add support for histograms and distributions without unit conversion
2020-06-19 13:00:06 +02:00
glightfoot aa591e3e8e add test for signalfx/dogstatsd mixed tags
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-17 13:14:39 -04:00
glightfoot b4ce2913fa add signalfx tag parsing to main benchmark tests
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-16 17:18:41 -04:00
glightfoot 32f1677f81 add signalfx tag parsing
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-16 16:32:59 -04:00
glightfoot 38414f106a add benchmark for LineToEvents
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-16 16:32:01 -04:00
glightfoot 4a64979563 move mapping and mapper_defaults into their own files with their unmarshalers
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-16 07:46:53 -04:00
glightfoot 1444824911 fix yaml tags
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-15 18:47:17 -04:00
glightfoot bdd4a76348 add more tests for metric type
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-15 18:46:20 -04:00
glightfoot 77277a5150 support deprecated timer_type in configs
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-15 18:41:16 -04:00
glightfoot 32e9e58e32 Rename timer to observer in mapper
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-15 17:26:20 -04:00
glightfoot d95a53553e change metric labels to observer
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-15 10:14:11 -04:00
glightfoot 374d202daa rename TimerEvent to ObserverEvent
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-12 09:25:51 -04:00
glightfoot 01b19722d7 remove comments
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-12 08:37:06 -04:00
glightfoot 063112b138 fix benchmark test
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-11 10:56:36 -04:00
glightfoot 5c0b206f6e add support for histograms and distributions without unit conversion
Signed-off-by: glightfoot <glightfoot@rsglab.com>
2020-06-11 10:56:36 -04:00
Matthias Rampke 2fc2dcdff6
Version bump & changelog for #312
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2020-05-29 11:49:41 +00:00
Matthias Rampke b3520aabd4
Merge pull request #312 from prometheus/mr/check-config
Support checking configuration and exiting
2020-05-29 13:47:40 +02:00
Matthias Rampke c8b8ddc952
Support checking configuration and exiting
If desired, go through all the motions of setting up the exporter, but
then exit. This is not very elegant, as we actually open the ports,
which may not be what you want to do in a pipeline, but it is the
quickest way to implement this.

Fixes #263.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2020-05-29 08:51:41 +00:00
Matthias Rampke 3b3ff3c473
Merge pull request #310 from prometheus/mr/dependency-update
Update all dependencies to latest
2020-05-29 10:15:25 +02:00
Matthias Rampke 44ae8f557c
Allow single-letter components in metric names
They are valid. Fixes #256.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2020-05-29 08:09:46 +00:00
Matthias Rampke bb2fedc556
go mod tidy
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2020-05-29 08:00:39 +00:00
Matthias Rampke 7f7d5171c3
go mod vendor
Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2020-05-29 08:00:30 +00:00
Matthias Rampke 0201b4f71f
Update all dependencies to latest
using `go get -u -t`

Fixes #257, if it is not fixed already.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2020-05-29 07:50:13 +00:00
Matthias Rampke bd5e04d6e3
Release 0.16.0
add changelog entry for #305, cut a release

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
2020-05-29 06:58:48 +00:00
Matthias Rampke 3908609918
Merge pull request #305 from chai-nadig/chai/log-ingested-metrics
Log Ingested Lines
2020-05-29 08:57:26 +02:00
Matthias Rampke 3630398b17
Merge pull request #306 from chai-nadig/chai/set-flush-interval
Set Flush Interval on EventQueue
2020-05-29 08:43:41 +02:00
Matthias Rampke 588fde9fc1
Update CircleCI orb to 0.5.0
in an attempt to fix the build failure: https://app.circleci.com/pipelines/github/prometheus/statsd_exporter/432/workflows/b27f7966-f1f7-4abf-8ad8-355325f1a02f/jobs/1322
2020-05-26 06:41:58 +00:00
Ben Kochie 7b78f2c1cd
Merge pull request #308 from prometheus/makefile_common
Synchronize Makefile.common from prometheus/prometheus
2020-05-26 07:33:20 +02:00
prombot fbceeef47a makefile: update Makefile.common with newer version
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2020-05-19 00:09:49 +00:00
Chai Nadig d804941a18 Set Flush Interval on EventQueue
Signed-off-by: Chai Nadig <chaitanya.nadig@gmail.com>
2020-05-14 00:03:34 -07:00
Chai Nadig cc10478f61 reset event.go
Signed-off-by: Chai Nadig <chaitanya.nadig@gmail.com>
2020-05-13 23:58:24 -07:00
Chai Nadig 4eac64eb59 log proto with msg
Signed-off-by: Chai Nadig <chaitanya.nadig@gmail.com>
2020-05-13 23:58:24 -07:00
Chai Nadig a75e588cf0 Log Ingested Lines
Signed-off-by: Chai Nadig <chaitanya.nadig@gmail.com>
2020-05-13 23:58:24 -07:00
Matthias Rampke 2898eb8c0c
Merge pull request #303 from roidelapluie/go114
Bump go version to 1.14
2020-05-03 14:05:45 +02:00
Julien Pivotto eb3997b287 Bump go version to 1.14
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2020-05-01 16:37:16 +02:00
Matthias Rampke bf8af64f5e
Merge pull request #301 from prometheus/mr/readme-library
Add notes about library usage to the README
2020-04-20 09:44:16 +02:00
Matthias Rampke f6384291a6
Add notes about library usage to the README
specifically, deny compatibility guarantees, but do note that we
recognize the packages as reusable.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2020-04-17 12:02:15 +00:00
Matthias Rampke 682bc92b45
Add changelog entry & bump version for #298
this deserves a call-out to surface any issues.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2020-04-17 12:01:20 +00:00
Matthias Rampke 1f3adf69c6
Merge pull request #298 from davidsonff/issue-234
:Issue 234: Split into reusable packages.
2020-04-17 13:43:30 +02:00
Frank Davidson c75b6091b8 Added metrics to unixgram listener.
Signed-off-by: Frank Davidson <frank_davidson@manulife.com>
2020-04-16 12:43:27 -04:00
Matthias Rampke f0a46c4ec9
Merge pull request #300 from epeay/patch
Fixed typo
2020-04-12 10:08:14 +02:00
Elliott Peay 828e12c345 Fixed typo
Signed-off-by: Elliott Peay <elliott.peay@gmail.com>
2020-04-11 16:14:11 -07:00
Frank Davidson 5ec58a32c2 squash! Updated structs and tests.
squash! Updated structs and tests.

Updated structs and tests.

Signed-off-by: Frank Davidson <davidfr@americas.manulife.net>
Signed-off-by: Frank Davidson <ffdavidson@gmail.com>
Signed-off-by: Frank Davidson <frank_davidson@manulife.com>
2020-04-09 11:44:13 -04:00
Frank Davidson 4b3b9ba207 Added license.
Signed-off-by: Frank Davidson <davidfr@americas.manulife.net>
Signed-off-by: Frank Davidson <ffdavidson@gmail.com>
2020-04-08 15:30:01 -04:00
Frank Davidson 390e862252 Removed redundant files.
Signed-off-by: Frank Davidson <davidfr@americas.manulife.net>
Signed-off-by: Frank Davidson <ffdavidson@gmail.com>
2020-04-08 15:30:01 -04:00
Frank Davidson 44d4daf599 Removed .exe
Signed-off-by: Frank Davidson <davidfr@americas.manulife.net>
Signed-off-by: Frank Davidson <ffdavidson@gmail.com>
2020-04-08 15:30:01 -04:00
Frank Davidson 16b6f95c96 removed ~
Signed-off-by: Frank Davidson <davidfr@americas.manulife.net>
Signed-off-by: Frank Davidson <ffdavidson@gmail.com>
2020-04-08 15:29:55 -04:00
Frank Davidson a455a8ad64 hopefully now linux
Signed-off-by: Frank Davidson <davidfr@americas.manulife.net>
Signed-off-by: Frank Davidson <ffdavidson@gmail.com>
2020-04-08 15:29:54 -04:00
Frank Davidson 77e8e78a88 eol update
Signed-off-by: Frank Davidson <davidfr@americas.manulife.net>
Signed-off-by: Frank Davidson <ffdavidson@gmail.com>
2020-04-08 15:29:49 -04:00
Frank Davidson 3207ad13ea eol
Signed-off-by: Frank Davidson <davidfr@americas.manulife.net>
Signed-off-by: Frank Davidson <ffdavidson@gmail.com>
2020-04-08 15:29:49 -04:00
Frank Davidson 6079c91345 eol=lf
Signed-off-by: Frank Davidson <davidfr@americas.manulife.net>
Signed-off-by: Frank Davidson <ffdavidson@gmail.com>
2020-04-08 15:29:49 -04:00
Frank Davidson b00162470f Adding gitattributes file for managing line ending conversions.
Signed-off-by: Frank Davidson <davidfr@americas.manulife.net>
Signed-off-by: Frank Davidson <ffdavidson@gmail.com>
2020-04-08 15:29:49 -04:00
Frank Davidson d55b42eabb :Issue 234: Split into reusable packages.
Signed-off-by: Frank Davidson <frank_davidson@manulife.com>
Signed-off-by: Frank Davidson <ffdavidson@gmail.com>
2020-04-08 15:29:49 -04:00
Aykut Farsak cb516fa69a Fix Docker Hub URL
Signed-off-by: Aykut Farsak <aykutfarsak@gmail.com>
Signed-off-by: Frank Davidson <ffdavidson@gmail.com>
2020-04-08 15:29:42 -04:00
Matthias Rampke 37e54d0f47
Merge pull request #294 from aykutfarsak/patch-1
Fix Docker Hub URL
2020-03-05 10:56:57 +01:00
Matthias Rampke 5179715a82
Release 0.15.0
feature release!

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2020-03-05 09:36:11 +00:00
Matthias Rampke 2ad8989cd2
Add changelog & readme entries for #281
explain the tradeoffs for the cache strategies based on this comment:

https://github.com/prometheus/statsd_exporter/pull/281#issuecomment-573103251

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2020-03-05 09:35:37 +00:00
Matthias Rampke 60fbaf5e27
Merge pull request #281 from bakins/random-replacement
Add random replacement mapper cache
2020-03-05 10:25:15 +01:00
Aykut Farsak 9778828863 Fix Docker Hub URL
Signed-off-by: Aykut Farsak <aykutfarsak@gmail.com>
2020-03-05 08:35:15 +03:00
bakins 90e247b091 Add random replacement cache
Signed-off-by: bakins <brian@akins.org>
2020-03-04 12:26:59 -05:00
Matthias Rampke 7b027d00a6
Merge pull request #292 from prometheus/makefile_common
Synchronize Makefile.common from prometheus/prometheus
2020-02-25 10:40:47 +01:00
prombot 7c8c2b571f makefile: update Makefile.common with newer version
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2020-02-25 00:09:27 +00:00
Matthias Rampke 6cef4dadac
Add changelog entry for #290
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2020-02-20 15:46:21 +00:00
Matthias Rampke b4e9e95cf2
Merge pull request #290 from tgummerer/tg/allow-setting-max-age
allow setting granularity for summary metrics
2020-02-20 13:25:40 +01:00
Thomas Gummerer dae5d782a6 allow setting granularity for summary metrics
The Go client for prometheus aggregates summary metrics over 10
minutes by default, in 5 buckets.  This is not always the behaviour we
want.

Allow tweaking those settings in `statsd_exporter`, so we can
aggregate summary metrics over more or less time, with more or fewer
buckets, and set the cap for the bucket as well.

Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
2020-02-18 18:04:38 +00:00
Thomas Gummerer 80b77513a6 create sub-hierarchies for summary and histogram options
Currently the Buckets and Quantiles settings are top level settings per metric
in the yaml.  In a subsequent commit we're going to allow adding more such
options for summaries, at which point having them all at the top level gets
confusing.

Split the options out into separate hierarchies to allow adding more options,
without adding confusion.  We preserve backwards compatibility by still
accepting the old option, but warning when it is present.

Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
2020-02-18 18:04:27 +00:00
Matthias Rampke c9c23a4f9e
Merge pull request #289 from bakins/escape-to-mapper
Move escapeMetricName to mapper
2020-01-16 16:55:09 +00:00
bakins e60f77df30 Move escapeMetricName to mapper
Signed-off-by: bakins <brian@akins.org>
2020-01-16 11:20:37 -05:00
Matthias Rampke 5aae305b35
Release 0.14.1
Add changelog entry for #286, #287, bump version

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2020-01-13 10:07:06 +00:00
Matthias Rampke d7f22028aa
Merge pull request #287 from prometheus/mr/fix-udp-logger
Pass logger to UDP listener
2020-01-13 10:05:07 +00:00
Matthias Rampke 3a88bd3ddb
Merge pull request #286 from bakins/273-fsm-cache
Use correct name when multiple names match same FSM match
2020-01-13 09:58:44 +00:00
Matthias Rampke fa2159f8e8
Pass logger to UDP listener
We were already passing it to the TCP and Unixgram listener, but
somehow left it out of the UDP listener setup.

Fixes #285.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2020-01-13 09:55:07 +00:00
Brian Akins b234e1dd4e Use correct name when multiple names match same FSM match
Signed-off-by: Brian Akins <brian@akins.org>
2020-01-11 07:05:20 -05:00
Matthias Rampke 20006621cc
Release v0.14.0
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2020-01-10 17:01:22 +00:00
Matthias Rampke 512c53c703
Update changelog for #283
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2020-01-10 14:51:42 +00:00
Matthias Rampke 8a309f2e6e
Merge pull request #284 from prometheus/mr/rename-mapping-cache-metrics
Make mapper cache metric names more specific
2020-01-10 14:47:46 +00:00
Matthias Rampke 4f82807b38
Merge pull request #283 from prometheus/mr/pr-272
PR #272 continued
2020-01-10 14:34:35 +00:00
Matthias Rampke 7e6d394af0
Make mapper cache metric names more specific
cf. https://github.com/prometheus/statsd_exporter/pull/282#issuecomment-573031514

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2020-01-10 14:32:16 +00:00
Matthias Rampke 53f732d480
Log error and exit instead of panicking
Following the lead of prometheus/prometheus, we prefer to log-and-exit
instead of an unstructured panic.

cf. https://github.com/prometheus/prometheus/pull/3061/files#diff-4a3ccbb3ebdcd530af96f0105fe833c2R182

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2020-01-10 14:02:59 +00:00
Matthias Rampke 0d72309324
make common-unused
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2020-01-10 13:19:14 +00:00
Matthias Rampke 6f6d036307
Changelog & version bump for #280 & #282
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2020-01-10 13:15:10 +00:00
Matthias Rampke a4a9f26e16
Merge pull request #282 from prometheus/mr/rename-mapping-cache-lengt-metrics
Rename mapping cache length metric
2020-01-10 13:12:32 +00:00
Matthias Rampke ac3e901f19
Rename mapping cache length metric
The mapper package can be used outside the statsd exporter, so it is
better to use generic names here.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2020-01-10 13:10:03 +00:00
Matthias Rampke 9d0ea80917
Merge pull request #280 from bakins/cache-metrics
mapper cache: Add cache metrics for total gets and hits
2020-01-10 13:08:21 +00:00
bakins 4b69da2d03 mapper cache: Add cache metrics for total gets and hits
Add metrics to record mapper cache hits and total gets.

Signed-off-by: bakins <brian@akins.org>
2020-01-03 16:46:58 -05:00
Matthias Rampke 2e3d3ab962
Merge pull request #279 from bakins/format-key-optimization
mapper cache: Use string concatenation rather than Sprintf for formatKey
2020-01-01 09:55:02 +01:00
bakins e60a0b6d00 Use string concatenation rather than Sprintf
Signed-off-by: bakins <brian@akins.org>
2019-12-31 16:40:33 -05:00
Matthias Rampke d888f25cb6
Merge pull request #275 from ergo/patch-1
Fix format for dogstatsd tags
2019-12-09 12:47:00 +01:00
Marcin Lulek a1c201d821 Fix format for dogstatsd tags
Only key:value format for dogstatsd is accepted by latest version of statsd exporter.
I've tried both official client and bash scripts to send the data:

    echo "newpure.test:1|c|@0.5|#country:china" | nc -w 1 -u 127.0.0.1 9125` - will work
    echo "newpure.test:1|c|@0.5|#country=china" | nc -w 1 -u 127.0.0.1 9125 - will not work

Signed-off-by: Marcin Lulek <info@webreactor.eu>
2019-12-09 12:34:03 +01:00
Matthias Rampke eeaefea1e2
Remove v from changelog entries
to conform with the format that promu expects.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-12-06 16:11:16 +00:00
Matthias Rampke 600423ad61
Release version 0.13.0
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-12-06 15:35:00 +00:00
Matthias Rampke 4f60ae856b
Merge pull request #278 from abbasalizaidi/master
Typo correction
2019-12-02 10:47:01 +01:00
abbasalizaidi 8ebffcfb93 Corrected spellings of the word policy
Signed-off-by: Abbas Ali Zaidi <abbasali.zaidi@fireeye.com>
2019-12-02 12:05:37 +05:30
Matthias Rampke 18a3c26447
Merge pull request #277 from xocasdashdash/updated-docs
Updated docs and added good/bad example yaml
2019-11-26 18:20:07 +01:00
Joaquín Fernández Campo 1aa5127349 Fixed changelog per request.
Signed-off-by: Joaquin Fernandez Campo <jfcampo@gmail.com>
2019-11-26 10:32:19 +01:00
Joaquín Fernández Campo 84657e85ec Updated docs and added good/bad example yaml
Signed-off-by: Joaquin Fernandez Campo <jfcampo@gmail.com>
2019-11-26 10:01:29 +01:00
mhartenbower 5f4f780e16 Add noplogger to tests
Signed-off-by: mhartenbower <matt.hartenbower@gmail.com>
2019-10-13 16:44:16 -05:00
mhartenbower c710b851c7 Switch to go-kit logging
Fixes #270

Signed-off-by: mhartenbower <matt.hartenbower@gmail.com>
2019-10-13 13:19:28 -05:00
Matthias Rampke 7d2a901b6c
Update changelog for #267 2019-09-20 07:26:18 +00:00
Matthias Rampke c1db8ba02d
Merge pull request #267 from twooster/add-librato-tag-support
Add librato tag support
2019-09-20 09:19:46 +02:00
Tony Wooster df740e7778 Minor fixups
Signed-off-by: Tony Wooster <twooster@gmail.com>
2019-09-19 18:31:10 +02:00
Tony Wooster a4b92689bc DRY up tag-parsing code
Signed-off-by: Tony Wooster <twooster@gmail.com>
2019-09-18 15:33:23 +02:00
Tony Wooster 0e000fe833 Drop metrics with mixed tagging styles
Signed-off-by: Tony Wooster <twooster@gmail.com>
2019-09-18 15:33:23 +02:00
Tony Wooster e01507a57c Remove "Librato" from tag error messages
Signed-off-by: Tony Wooster <twooster@gmail.com>
2019-09-17 17:35:57 +02:00
Tony Wooster 22619bb8a9 Update README
Signed-off-by: Tony Wooster <twooster@gmail.com>
2019-09-17 17:01:34 +02:00
Tony Wooster 5537c504cc Add support for InfluxDB style tagging
Signed-off-by: Tony Wooster <twooster@gmail.com>
2019-09-17 17:01:34 +02:00
Matthias Rampke 84889bd5ea
Merge pull request #266 from simonpasquier/bump-golang-1.13
Bump golang 1.13
2019-09-16 17:53:59 +02:00
Tony Wooster 2933dd8ad0 Add support for Librato-style tags
Signed-off-by: Tony Wooster <twooster@gmail.com>
2019-09-14 17:14:03 +02:00
Matthias Rampke a35d17c160
Update changelog for #264 2019-09-13 07:32:37 +00:00
Matthias Rampke 1865ea1be3
Merge pull request #264 from amitsaha/issue-250
Support sampling factor for all statsd metric types
2019-09-13 09:30:55 +02:00
Amit Saha 5b44b372d1 Add test for gauge with sample rate
Signed-off-by: Amit Saha <amitsaha.in@gmail.com>
2019-09-13 14:30:52 +10:00
Amit Saha 1bddef857d Add test
Signed-off-by: Amit Saha <amitsaha.in@gmail.com>
2019-09-13 14:27:48 +10:00
Amit Saha d64c674394 Fix test
Signed-off-by: Amit Saha <amitsaha.in@gmail.com>
2019-09-13 13:07:12 +10:00
Simon Pasquier 9d822d4196 Fix go.mod and vendor/
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-09-12 17:45:39 +02:00
Simon Pasquier 91cc64da62 *: bump Go version to 1.13
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-09-12 17:36:35 +02:00
Matthias Rampke b6e4b2a82e
Merge pull request #265 from prometheus/makefile_common
Synchronize Makefile.common from prometheus/prometheus
2019-09-11 10:05:07 +02:00
prombot 54359d3b06 makefile: update Makefile.common with newer version
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2019-09-11 00:09:20 +00:00
Amit Saha 028531e953 Fix for issue #250
Signed-off-by: Amit Saha <amitsaha.in@gmail.com>
2019-09-09 17:25:19 +10:00
Matthias Rampke a1f8bae0a3
Merge pull request #262 from amitsaha/master
README - Add a note regarding unit conversions for timers
2019-09-06 08:49:12 +02:00
Amit Saha 8479e3d7a3 README - Add a note regarding unit conversions for timers
Signed-off-by: Amit Saha <amitsaha.in@gmail.com>
2019-09-06 09:46:17 +10:00
Matthias Rampke 8fa4613e74
Merge pull request #261 from amitsaha/master
Update use_ms note for dogstatsd client
2019-09-05 15:20:44 +02:00
Amit Saha 4d518de467 Update use_ms note for dogstatsd client
Signed-off-by: Amit Saha <amitsaha.in@gmail.com>
2019-09-04 03:06:59 +10:00
Matthias Rampke 74a561fbed
Merge pull request #259 from prometheus/makefile_common
Synchronize Makefile.common from prometheus/prometheus
2019-08-30 14:37:04 +02:00
prombot 95fb214d16 makefile: update Makefile.common with newer version
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2019-08-30 00:09:17 +00:00
Matthias Rampke 085643f486
Merge pull request #254 from raags/add-dogstatsd-use-ms-note
Add note about DogStatsD `use_ms` option
2019-08-26 11:29:16 +02:00
Raghu Siddarth Udiyar d49afad05c Link to API documentation instead
Co-Authored-By: Matthias Rampke <mr@soundcloud.com>
Signed-off-by: Raghu Udiyar <raghusiddarth@gmail.com>
2019-08-02 14:55:01 +05:30
Raghu Udiyar b0a54e1d65 Add note about DogStatsD use_ms option
DogStatsD by default emits timer metric in seconds, while the exporter
assumes milliseconds; which is the default for statsd. The `use_ms` option
fixes this, and will be useful for dogstatsd users to know.

Signed-off-by: Raghu Udiyar <raghusiddarth@gmail.com>
2019-08-01 15:55:46 +05:30
Matthias Rampke d308796e97
Add changelog for #252, #253 & release
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-07-25 13:13:44 +00:00
Matthias Rampke 074fc349b0
Merge pull request #252 from mohag/master
Add event handler for Unixgram
2019-07-25 15:11:43 +02:00
Matthias Rampke 353b38c80b
Merge pull request #253 from tcolgate/eventrace
Event queue processes and filling race.
2019-07-25 15:11:02 +02:00
Tristan Colgate 49296e321e Event queue processes and filling race.
We send the slice off to be process, but potentially start overwriting
the previous content straight away. Just start again with a fresh slice.

Fixes #247

Signed-off-by: Tristan Colgate <tristan@qubit.com>
2019-07-25 13:41:05 +01:00
Gert van den Berg b555158e53 Add event handler for Unixgram
Signed-off-by: Gert van den Berg <gert.vandenberg@iotnxt.com>
2019-07-23 16:00:00 +02:00
Matthias Rampke e60f2f147b
Merge pull request #249 from prometheus/makefile_common
Synchronize Makefile.common from prometheus/prometheus
2019-07-22 10:57:34 +02:00
prombot 2d44e85fdc makefile: update Makefile.common with newer version
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2019-07-20 00:02:44 +00:00
Matthias Rampke 6635ea71e8
Update changelog & release 0.12.1
Merge with 0.12.0 which I didn't finish releasing

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-07-08 08:53:54 +00:00
Matthias Rampke 802aa8a9e7
Merge pull request #246 from cdnhaese/master
Fix TTL bug
2019-07-08 10:51:33 +02:00
Cedric Den Haese ccd86002cf
Fix TTL bug
lastRegistredAt element was only set at creation of a time series.
Now it is updated every time a new event is seen for that time series.

Signed-off-by: Cedric Den Haese <cedric.den.haese@gmail.com>
2019-07-08 09:32:34 +01:00
Matthias Rampke d56b864f83
Update changelog for #243 & release 0.12.0
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-07-08 07:59:39 +00:00
Matthias Rampke 878609a8e8
Merge pull request #240 from prometheus/makefile_common
Synchronize Makefile.common from prometheus/prometheus
2019-07-05 16:30:21 +02:00
Matthias Rampke f7c7db0b8d
Update logrus for AIX support
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-07-05 14:29:03 +00:00
prombot bdfa130554
makefile: update Makefile.common with newer version
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2019-07-05 14:29:03 +00:00
Matthias Rampke f6e6e6d122
Merge pull request #245 from prometheus/mr/remove-travis
Remove Travis CI
2019-07-05 16:28:26 +02:00
Matthias Rampke f72f25f8ce
Merge pull request #244 from prometheus/mr/quote-yaml
Quote all matchers in YAML examples
2019-07-05 16:28:18 +02:00
Matthias Rampke d59f306cd9
Merge pull request #243 from prometheus/mr/remove-inotify
Reload on SIGHUP instead of watching the file
2019-07-05 16:28:02 +02:00
Matthias Rampke 193e4c9be4
Remove Travis CI
it doesn't test anything that CircleCI doesn't.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-07-05 13:34:35 +00:00
Matthias Rampke 64a51731f7
Quote all matchers in YAML examples
They can start with a * which makes YAML barf if not quoted. Instead of
figuring out individually what does and does not need to be quoted,
always quote.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-07-05 13:32:22 +00:00
Matthias Rampke 23ef5daeac
Reload on SIGHUP instead of watching the file
This is more portable (works on any system that has UNIX signals) and
removes the dependency on fsnotify, which doesn't compile on AIX. It
also reduces the probability of failed reloads due to partial writes.

Fixes #241.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-07-05 13:30:31 +00:00
Simon Pasquier eb51631f33
Build ARM container images (#242)
It also updates the Circle CI configuration to use the
Prometheus orb.

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-07-02 14:09:42 +02:00
Matthias Rampke 611dd8c60a
Merge pull request #239 from prometheus/makefile_common
Synchronize Makefile.common from prometheus/prometheus
2019-06-24 11:07:18 +02:00
prombot 3494db2a67 makefile: update Makefile.common with newer version
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2019-06-23 00:01:27 +00:00
Björn Rabenstein f2d3b9eb79
Merge pull request #237 from prometheus/beorn7/modules
Update prometheus/client_golang to v1.0.0
2019-06-21 15:01:10 +02:00
beorn7 ef5212ce06 Update prometheus/client_golang to v1.0.0
Signed-off-by: beorn7 <beorn@grafana.com>
2019-06-17 18:34:56 +02:00
Matthias Rampke 511836b7ff
Release 0.11.2
* Update changelog for #235
* Release 0.11.2
2019-06-14 15:32:48 +02:00
Matthias Rampke bb448be4f4
Merge pull request #235 from seruman/master
add missing eventHandler to StatsDTCPListener
2019-06-14 15:29:29 +02:00
Selman Kayrancioglu bb88165d52 add missing eventHandler to StatsDTCPListener
Signed-off-by: Selman Kayrancioglu <selman@peak.com>
2019-06-14 15:42:21 +03:00
Matthias Rampke a276bacac9
Release 0.11.1
no changes, 0.11.0 had test issues.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-06-14 08:19:50 +00:00
Matthias Rampke 4653781f9b
Update Makefile.common for prometheus/prometheus#5658
should fix the build

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-06-13 13:33:29 +00:00
Matthias Rampke 70c227522f
Release 0.11.0
and add the missing changelog entry for #227

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-06-13 08:42:18 +00:00
Matthias Rampke c3dc7b4b96
Merge pull request #231 from SpencerMalone/match_metric_type_tests
Add test for multiple explicit metric types.
2019-06-12 18:04:57 +02:00
Matthias Rampke 6f7cb49280
Merge pull request #232 from golopot/patch-1
Update links for DogStatsD in README.md
2019-06-12 11:52:42 +02:00
Matthias Rampke 38d62c39a6
Add #233 / #80 to changelog 2019-06-12 09:23:09 +00:00
Matthias Rampke 4f9843ad0d
Merge pull request #233 from cdambo/master
Use promhttp instead of http
2019-06-12 11:18:21 +02:00
golopot 5cea0077e4 Update links for DogStatsD in README.md
Signed-off-by: Chiawen Chen <golopot@gmail.com>
2019-06-11 19:22:43 +08:00
Chanan Damboritz 8f7676eaa9 Use promhttp instead of http
Signed-off-by: Chanan Damboritz <chanan@hiredscore.com>
Signed-off-by: Chanan Damboritz <cdambo@gmail.com>
2019-06-11 13:54:20 +03:00
SpencerMalone 7035e5e075 Add test for multiple explicit metric types.
Signed-off-by: SpencerMalone <malone.spencer@gmail.com>
2019-06-07 20:11:32 -04:00
Matthias Rampke 5832aa9bcf
Merge pull request #227 from claytono/event-queuing
Add internal event queuing and flushing
2019-06-07 15:50:25 +02:00
Clayton O'Neill 091bf99641
Update event queue metric name to be more descriptive.
Co-Authored-By: Matthias Rampke <mr@soundcloud.com>
Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-06-07 09:01:20 -04:00
Matthias Rampke 2e5c38204a
Release 0.10.6
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-06-07 08:58:01 +00:00
Matthias Rampke 95e376a40b
Merge pull request #230 from prometheus/makefile_common
Synchronize Makefile.common from prometheus/prometheus
2019-06-07 08:49:14 +02:00
prombot 1d21cdcc1e makefile: update Makefile.common with newer version
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2019-06-07 00:02:26 +00:00
Matthias Rampke 59056c097a
update changelog for #229 2019-06-06 12:34:05 +00:00
Matthias Rampke 8551a65827
Merge pull request #229 from andy-paine/make-mapper-cache-respect-metric-type
Make mapper cache respect metric type
2019-06-06 14:31:58 +02:00
Andy Paine 0135b40c08 Make mapper cache respect metric type
- Statsd allows users to provide a metric with the same name but
  differing types (counter, gauge, timer)
- The exporter allows this by letting users specify a
  "match_metric_type" in the mapping config
- However the mapper cache does not look at the metric type so it would
  return a MetricMapperCacheResult for the type of the first metric with
that name that the exporter saw
- Add MetricType to the signature for the cache and format the metric
  name with the type to provide unique keys for a metric with the same
name but differing type

Signed-off-by: Andy Paine <andy.paine@digital.cabinet-office.gov.uk>
2019-06-06 11:33:58 +01:00
Clayton O'Neill c7e76967c8
Add internal event queuing and flushing
At high traffic levels, the locking around sending on channels can cause
a large amount of blocking and CPU usage.  These adds an event queue
mechanism so that events are queued for short period of time, and
flushed in batches to the main exporter goroutine periodically.

The default is is to flush every 1000 events, or every 200ms, whichever
happens first.

Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-06-04 06:57:48 -04:00
Matthias Rampke 50d5932124
Merge pull request #223 from claytono/rework-registry
Rework metric registration and tracking
2019-06-04 10:34:13 +02:00
Clayton O'Neill f6f1d7f071
Remove redundant code in counter inc test
Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-31 08:38:16 -04:00
Clayton O'Neill a241eb0b69
Remove vector cleanup from registry
This was attempting to clean up any vectors that no longer have metrics
associated with them.  Unfortunately this isn't really possible because
the prometheus client registry allows the second registration of the
same metric, and then throws an error when gathering the metrics.

Another options would be to unregister the metric with the client
library, but that's not implemented for unchecked collectors.

Unfortunately this means that if we have a lot of metrics with differing
label sets appearing and disappearing, that we'll leak some amount of
memory for vectors that are never used again, but this is the way the
old metric tracking code worked also.

Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-31 08:38:16 -04:00
Clayton O'Neill 680eb0e826
Add additional tests
This adds two tests.

The first test is to validate that two successive counter events will
increment a counter.  This is more about ensuring we can look up the
same metric twice in a row than checking increment functionality.

The second test verifies that the hashLabels function returns different
results when labels are changed.

Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-31 08:38:16 -04:00
Clayton O'Neill f6c0dd965b
Remove dead code
This removes all the code that the new registry code replaces.

Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-31 08:38:16 -04:00
Clayton O'Neill 7c30120dbc
Rework metric registration and tracking
This reworks/rewrites the way that metric registration and tracking is
handled across all of statsd_exporter.  The goal here is to reduce
memory and cpu usage, but also to reduce complexity by unifying metric
registration with the ttl tracking for expiration.

Some high level notes:

* Previously metric names and labels were being hashed three times for
every event accepted: in the container code, the save label set code and
again in the prometheus client libraries.  This unifies the first two
and caches the results of `GetMetricWith` to avoid the third.

* This optimizes the label hashing to reduce cpu overhead and memory
allocations.  The label hashing code previously showed up high on all
profiling done for both CPU and memory allocations

Using the BenchmarkExporterListener benchmark, the improvement looks
like this.

Before:
cpu: 11,341,797 ns/op
memory allocated: 1,731,119 B/op
memory allocations: 58,028 allocs/op

After:
cpu: 7,084,651 ns/op
memory allocated: 906,556 B/op
memory allocations: 42,026 allocs/op

Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-31 08:38:15 -04:00
Clayton O'Neill 7a107f899f
Add benchmark for exporter listener
Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-31 08:38:15 -04:00
Matthias Rampke d74922e0fd
Merge pull request #226 from simonpasquier/use-org-context
Use Circle CI's org context
2019-05-31 08:47:05 +00:00
Simon Pasquier 83cd28067a Use Circle CI's org context
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-05-29 18:00:06 +02:00
Matthias Rampke bfa30a94b2
Merge pull request #225 from jeamland/add_label_test
Add a test for adding labels from mapper configuration.
2019-05-28 08:26:08 +00:00
Benno Rice f12451ee5b Add a test for adding labels from mapper configuration.
Signed-off-by: Benno Rice <benno@jeamland.net>
2019-05-28 10:06:17 +10:00
Matthias Rampke 09c2603f4b
Update changelog for #224, release 0.10.5
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-05-27 09:09:59 +00:00
Matthias Rampke 56a091a693
Merge pull request #224 from ptqa/master
Fix inconsistent label cardinality error
2019-05-27 09:06:29 +00:00
Tony Nyurkin 7d6244987a Fix inconsistent label cardinality error
Signed-off-by: Tony Nyurkin <ptqa@users.noreply.github.com>
2019-05-24 14:26:17 +03:00
Matthias Rampke b333ecaacc
Add changelog for #221 and release 0.10.4
Reverting #218 due to race condition issue #220

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-05-20 08:35:36 +00:00
Matthias Rampke 3abf21e053
Merge pull request #221 from prometheus/revert-218-handlepacket-optimization
Revert "Reduce memory allocations in handlePacket"
2019-05-20 08:34:09 +00:00
Matthias Rampke 26e9d482db
Revert "Reduce memory allocations in handlePacket" 2019-05-20 08:20:19 +00:00
Matthias Rampke 471b28dc21
Update changelog for #217, #218, #219 and release
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-05-17 13:51:13 +00:00
Matthias Rampke c9004f8f3f
Merge pull request #219 from claytono/optimize-label-handling
Optimize label sorting
2019-05-17 13:47:03 +00:00
Matthias Rampke 4e64da2a41
Merge pull request #218 from claytono/handlepacket-optimization
Reduce memory allocations in handlePacket
2019-05-17 13:38:56 +00:00
Matthias Rampke 27d9273107
Merge pull request #217 from claytono/emn-optimization
Convert escapeMetricName to use strings.Builder
2019-05-17 13:38:09 +00:00
Matthias Rampke cf4290bf7e
Update CircleCI config for prometheus/prometheus#5031
multi-arch \m/

Release 0.10.2 with this. Hopefully.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-05-17 08:39:50 +00:00
Matthias Rampke df81d15e84
Bump to 0.10.1
I never finished releasing 0.10.0 because the build was broken, but I
don't want to re-use that tag.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-05-17 08:04:55 +00:00
Clayton O'Neill d143398343
Optimize label sorting
Previously we were sorting labels in every container to build a map key,
but also when generating the hash key by calling the `LabelsToSignature`
method.  This moves the sorting to be done early in the event processing
then passes the sorted label array around.

Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-16 17:17:09 -04:00
Clayton O'Neill 732be39b4b
Add benchmark for hashNameAndLabels
Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-16 17:17:09 -04:00
Clayton O'Neill 4cf6f74dc3
Reduce memory allocations in handlePacket
This converts the byte buffer to a string by casting and parses the
string by looping over it instead of calling Split.

This usage of unsafe is taken from the strings.Builder package here:
cb5c82bc3d/src/strings/builder.go (L47)

Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-16 16:35:32 -04:00
Clayton O'Neill 98da6f7057
Convert escapeMetricName to use strings.Builder
This converts escapeMetricName to use strings.Builder instead of
allocating a byte array, filling it and then converting it to a string.
This also optimizes for the case where the metricName is already valid,
and in that case, it just returns the original string.

This reduces memory allocations from 2 per call to 1 per call in the
case when the string does need to be escaped, and reduces it to zero
memory allocations when the string is already valid.

Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-16 09:28:35 -04:00
Matthias Rampke a294491e0b
Resolve merge conflicts of #198 with #212 and #213
In #198 the signature for setting up the exporter changed slightly, a
change that #212 and #213 didn't have. This doesn't change anything
substantial.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-05-15 13:21:04 +00:00
Matthias Rampke f502171bdc
Merge pull request #216 from claytono/conflicting-histogram-fix
Check for histogram conflict on main name
2019-05-15 13:20:11 +00:00
Matthias Rampke 8cc291f419
Release v0.10.0
* [CHANGE] Do not run as root in the Docker container by default ([#202](https://github.com/prometheus/statsd_exporter/pull/202))
* [FEATURE] Add metric for count of events by action ([#193](https://github.com/prometheus/statsd_exporter/pull/193))
* [FEATURE] Add metric for count of distinct metric names ([#200](https://github.com/prometheus/statsd_exporter/pull/200))
* [FEATURE] Add UNIX socket listener support ([#199](https://github.com/prometheus/statsd_exporter/pull/199))
* [FEATURE] Accept Datadog [distributions](https://docs.datadoghq.com/graphing/metrics/distributions/) ([#211](https://github.com/prometheus/statsd_exporter/pull/211))
* [ENHANCEMENT] Add a health check to the Docker container ([#182](https://github.com/prometheus/statsd_exporter/pull/182))
* [ENHANCEMENT] Allow inconsistent label sets ([#194](https://github.com/prometheus/statsd_exporter/pull/194))
* [ENHANCEMENT] Speed up sanitization of metric names ([#197](https://github.com/prometheus/statsd_exporter/pull/197))
* [ENHANCEMENT] Enable pprof endpoints ([#205](https://github.com/prometheus/statsd_exporter/pull/205))
* [ENHANCEMENT] DogStatsD tag parsing is faster ([#210](https://github.com/prometheus/statsd_exporter/pull/210))
* [ENHANCEMENT] Cache mapped metrics ([#198](https://github.com/prometheus/statsd_exporter/pull/198))
* [BUGFIX] Fix panic if a mapping resulted in an empty name ([#192](https://github.com/prometheus/statsd_exporter/pull/192))
* [BUGFIX] Ensure that there are always default quantiles if using summaries ([#212](https://github.com/prometheus/statsd_exporter/pull/212))
* [BUGFIX] Prevent ingesting conflicting metric types that would make scraping fail ([#213](https://github.com/prometheus/statsd_exporter/pull/213))

With #192, the count of events rejected because of negative counter increments has moved into the `statsd_exporter_events_error_total` metric, instead of being lumped in with the different kinds of successful events.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-05-15 13:09:41 +00:00
Matthias Rampke 228a969b1a
Add changelog entry for #198
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-05-15 13:06:04 +00:00
Matthias Rampke 698bcdf8c3
Merge pull request #198 from SpencerMalone/mapping-cache
Adding mapping cache
2019-05-15 13:05:00 +00:00
Clayton O'Neill cce95f6980
Check for histogram conflict on main name
While it doesn't report it as a metric, when collecting, the registry
considers the base metric name to below to the histogram that's
registered.  This means that we need to prevent other metrics from
registering anything under this name, in addition to checking for the
bucket, sum and count suffixes.

Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-15 09:04:19 -04:00
Matthias Rampke a42de85289
Add changelog entry for #213
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-05-15 11:22:17 +00:00
Matthias Rampke 04b7b71a2a
Merge pull request #213 from claytono/conflicting-metrics-test
Add checking for conflicting metrics
2019-05-15 11:20:56 +00:00
Clayton O'Neill 3dcad090b3
Add test cases for conflicting metrics with labels
Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-15 06:46:11 -04:00
Matthias Rampke 24e288a3a4
Merge pull request #214 from prometheus/makefile_common
Synchronize Makefile.common from prometheus/prometheus
2019-05-15 07:40:06 +00:00
Ben Kochie 0eadae3ca7
Remove obsolete release tool.
Signed-off-by: Ben Kochie <superq@gmail.com>
2019-05-15 02:07:49 +02:00
prombot 7514e37e5b makefile: update Makefile.common with newer version
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2019-05-15 00:01:34 +00:00
Clayton O'Neill 9f1c6b81a5
Add checking for conflicting metrics
This adds sanity checking before registering a metric to ensure that the
metric isn't already registered under an existing name.  This prevents
the exporter from getting into a state where it has accepted and
registered conflicting metrics, and then cannot report the metrics it
has collected.

Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-14 18:33:49 -04:00
Matthias Rampke f08bf14965
Update changelog for #210, #211, #212
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-05-14 16:24:33 +00:00
Matthias Rampke bee73cbb9e
Merge pull request #211 from claytono/add-distributions
Add support for Datadog distribution type
2019-05-14 16:23:07 +00:00
Matthias Rampke d7eb1edeed
Merge pull request #210 from claytono/tag-parsing-optimizations
Tag parsing optimizations
2019-05-14 16:18:37 +00:00
Matthias Rampke f1c0052ce7
Merge pull request #212 from vsakhart/quantile_fix
Add default quantiles for summaries if no mapping file exists
2019-05-14 16:14:15 +00:00
Vitaliy Sakhartchouk cddeb87405 Add default quantiles for summaries if no mapping file exists
Signed-off-by: Vitaliy Sakhartchouk <vsakhart@github.com>
2019-05-13 17:14:42 -07:00
Clayton O'Neill 04bba78d61
Add support for Datadog distribution type
This adds the ability to accept Datadog's distribution type and treat it
like a histogram/summary.

Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-13 14:59:21 -04:00
Clayton O'Neill a4faae262b
Replace Split with special purpose implementation
This improves performance from 3169ns/op to 2836 ns/op and drops one
allocation per op.

Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-13 13:32:25 -04:00
Clayton O'Neill e3cdd85a09
Extract individual tag parsing into new function
Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-13 12:46:50 -04:00
Clayton O'Neill a441eac07a
Replace SplitN w/special purpose implementation
This improves performance per call in the a-z case from around 5533
ns/op to 3169ns/op.  It also drops allocations per call from 57 to 31
in the a-z case.

Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-13 12:46:50 -04:00
Clayton O'Neill 052beaa3ac
Replace TrimPrefix w/special purpose implementation
On the a-z benchmark, this brings the ns/op down from 5658 to 5533.

Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-13 12:46:50 -04:00
Clayton O'Neill 9cd711ed3e
Add benchmark for tag parsing
Signed-off-by: Clayton O'Neill <claytono@github.com>
2019-05-13 12:46:49 -04:00
Matthias Rampke 4d0cb1992d
Merge pull request #208 from prometheus/makefile_common
Synchronize Makefile.common from prometheus/prometheus
2019-05-06 09:19:31 +00:00
prombot e82cf2444b makefile: update Makefile.common with newer version
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2019-05-04 00:01:58 +00:00
SpencerMalone 35d1a99592 Adding mapping cache
Signed-off-by: SpencerMalone <malone.spencer@gmail.com>
2019-04-26 18:00:39 -04:00
Matthias Rampke 54cf241044
Merge pull request #207 from simonpasquier/bump-golang-1.12
Bump Go version to 1.12
2019-04-26 09:43:27 +00:00
Simon Pasquier 7631485b0b *: bump Go version to 1.12
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-04-26 10:55:07 +02:00
Matthias Rampke abb2ab04fb
Merge pull request #206 from prometheus/makefile_common
Synchronize Makefile.common from prometheus/prometheus
2019-04-25 09:03:15 +00:00
Simon Pasquier 6fd7690961 Add .golangci.yml
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-04-25 09:58:12 +02:00
prombot f1de314e14 makefile: update Makefile.common with newer version
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2019-04-25 00:01:46 +00:00
Matthias Rampke 0bd90aee34
Update changelog for #205
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-04-23 09:12:24 +00:00
Matthias Rampke 9963806a62
Merge pull request #205 from claytono/add-pprof
Add pprof for profiling
2019-04-23 09:01:09 +00:00
Matthias Rampke ee653990e6
Update changelog and README for #199
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-04-23 08:47:32 +00:00
Matthias Rampke e3d6050616
Merge pull request #199 from Kong/feat/unixgram-socket
Implement listener for Unixgram sockets
2019-04-23 08:44:11 +00:00
Wangchong Zhou 47b5ef9be0
Buffer signals channel
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2019-04-22 16:35:28 -07:00
Wangchong Zhou 383ee9bd3b
Add a signal handler to allow clean up of unixgram socket file
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2019-04-22 16:33:22 -07:00
Clayton O'Neill 024f9dc0aa
Add pprof for profiling
Signed-off-by: Clayton O'Neill <clayton@oneill.net>
2019-04-22 08:07:43 -04:00
Matthias Rampke ece8a26a79
Merge pull request #203 from prometheus/makefile_common
Synchronize Makefile.common from prometheus/prometheus
2019-04-18 10:26:33 +00:00
Matthias Rampke 485b28a9ff
Add missing license header
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-04-18 10:12:50 +00:00
prombot 88a12bc9b9 makefile: update Makefile.common with newer version
Signed-off-by: prombot <prometheus-team@googlegroups.com>
2019-04-18 00:00:40 +00:00
Matthias Rampke c3eb636525
Add changelog for #202
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-04-17 15:25:44 +00:00
Matthias Rampke 0766e70e43
Merge pull request #202 from prometheus/superq/docker_user
Don't run docker container as root
2019-04-17 15:24:37 +00:00
Ben Kochie 38df95f440
Don't run docker container as root
Run statsd_exporter as `nobody`.

Signed-off-by: Ben Kochie <superq@gmail.com>
2019-04-17 17:04:19 +02:00
Matthias Rampke f0feef950b
Add changelog entry for #200
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-04-16 13:17:11 +00:00
Matthias Rampke 526a81b445
Merge pull request #200 from bakins/metrics-count
Add metric to track unique metric names the exporter is tracking
2019-04-16 13:15:33 +00:00
Brian Akins 45402964a4 use label for metric type and decrement
Signed-off-by: Brian Akins <brian@akins.org>
2019-04-15 08:16:00 -04:00
Brian Akins 92957ce080 Add metric to track unique metric names the exporter is tracking
Signed-off-by: Brian Akins <brian@akins.org>
2019-04-10 12:23:07 -04:00
Matthias Rampke 468c70df7d
Add #197 to changelog
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-04-10 08:49:07 +00:00
Matthias Rampke ece9385f22
Merge pull request #197 from bakins/escapeMetricName-performance
Increase escapeMetricName performance
2019-04-10 08:47:49 +00:00
Matthias Rampke 9ed6d59151
Correct to use name socket mode instead of mask
Co-Authored-By: fffonion <fffonion@gmail.com>
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2019-04-09 11:20:11 -07:00
Brian Akins cfcf3c9ba5 Add comments explaining escapeMetricName
Signed-off-by: Brian Akins <brian@akins.org>
2019-04-09 14:10:26 -04:00
Brian Akins 7f70979120 Add Benchmarks for escapeMetricName
Signed-off-by: Brian Akins <brian@akins.org>
2019-04-09 11:58:18 -04:00
Brian Akins e6bdf13407 Add comments explaining escapeMetricName
Signed-off-by: Brian Akins <brian@akins.org>
2019-04-09 11:58:18 -04:00
Brian Akins d371436f01 Replace regex in escapeMetricName with loop over runes
Signed-off-by: Brian Akins <brian@akins.org>
2019-04-09 11:58:18 -04:00
Matthias Rampke 3955c6ef1b
Update changelog for #193 #194
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-04-09 12:15:25 +00:00
Matthias Rampke 178d130388
Merge pull request #193 from bakins/statsd_exporter_events_total
Add metric for count of events by action
2019-04-09 12:13:17 +00:00
Matthias Rampke 43cef6ce6a
Merge pull request #194 from vsakhart/register_inconsistent_metrics
Allow support for inconsistent label sets by marking metrics registered as unchecked collectors
2019-04-09 12:08:33 +00:00
Wangchong Zhou 05bca84294
Implement listener for Unixgram sockets
As requested in #189

Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2019-04-05 16:45:34 -07:00
Brian Akins 1cbc5a9b27 Add metric for count of events by action
Signed-off-by: Brian Akins <brian@akins.org>
2019-04-02 15:20:50 -04:00
Vitaliy Sakhartchouk 2fc89536f4 Break out mapkey generation into function
Signed-off-by: Vitaliy Sakhartchouk <vsakhart@github.com>
2019-03-29 13:25:46 -07:00
Vitaliy Sakhartchouk 2025b47cb1 Allow support for inconsistent label sets by marking metrics
registered as unchecked collectors

Signed-off-by: Vitaliy Sakhartchouk <vsakhart@github.com>
2019-03-29 13:18:31 -07:00
Matthias Rampke 71df5a3198
Update changelog for #192
add note about the metric change.
2019-03-26 12:11:17 +00:00
Matthias Rampke 035a309552
Merge pull request #192 from ivanizag/master
Fixes #191: crash on empty metric name
2019-03-26 12:08:35 +00:00
Ivan Izaguirre 51e735c878 Fix test error message
Signed-off-by: Ivan Izaguirre <ivanizag@gmail.com>
2019-03-26 01:02:38 +01:00
Ivan Izaguirre c9e5e94ed2 Adds a separate counter for events discarded due to errors
Signed-off-by: Ivan Izaguirre <ivanizag@gmail.com>
2019-03-26 00:44:17 +01:00
Ivan Izaguirre c477c7703f Fix format to comply with go1.11 rules
Signed-off-by: Ivan Izaguirre <ivanizag@gmail.com>
2019-03-23 19:47:25 +01:00
Ivan Izaguirre 1c71191aaf Fixes #191: crash on empty metric name
Signed-off-by: Ivan Izaguirre <ivanizag@gmail.com>
2019-03-23 19:38:27 +01:00
Matthias Rampke 1036439f69
Add changelog entry for #182
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-03-13 13:23:37 +00:00
Matthias Rampke 680afe25f1
Merge pull request #182 from vaibhavkhurana2018/adds_health_check
Adds healthcheck for checking the status of the container
2019-03-13 13:07:38 +00:00
Vaibhav Khurana 88af8dcd24 Fixing healthcheck
Signed-off-by: Vaibhav Khurana <vaibhav.khurana@razorpay.com>
2019-03-13 16:48:06 +05:30
Matthias Rampke eeab36e63f
Release v0.9.0
update version and changelog.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-03-11 08:33:21 +00:00
Vaibhav Khurana 7830fea9ae Adds healthcheck for checking the status of the container
Signed-off-by: Vaibhav Khurana <vaibhav.khurana@razorpay.com>
2019-01-29 13:12:44 +05:30
Matthias Rampke d5b22a2993
Merge pull request #181 from prometheus/superq/reloaddoc
Mention automatic reloading in the README.
2019-01-24 09:16:10 +00:00
Ben Kochie 5ff2356e36
Mention automatic reloading in the README.
Signed-off-by: Ben Kochie <superq@gmail.com>
2019-01-24 08:26:45 +01:00
Matthias Rampke 671c01aa7f
Update changelog for #178, increment release candidate
No 0.9.0 release candidate was ever published because of CI issues, so
we can still add this change before the release.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2019-01-09 17:58:21 +00:00
Matthias Rampke a566da3f87
Merge pull request #178 from SpencerMalone/patch-1
Scale summaries from milliseconds to seconds.
2019-01-09 17:54:18 +00:00
SpencerMalone c73a7b2c9a Scale summaries from milliseconds to seconds.
Fixes #177

Updating exporter tests for new summary unit scaling behavior

Signed-off-by: Spencer Malone <malone.spencer@gmail.com>
2019-01-09 12:37:38 -05:00
Matthias Rampke 2d35b097ae
Merge pull request #175 from simonpasquier/add-staticcheck
Travis CI: add staticcheck target
2019-01-04 15:52:12 +00:00
Simon Pasquier 8f56cc811d *: add staticcheck target back
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-01-04 15:26:57 +01:00
Matthias Rampke 65070524c3
Merge pull request #174 from dongwenjuan/master
fix the format of code-block in README
2018-12-27 14:49:50 +00:00
dongwenjuan d655643a58 fix the format of code-block in README
Signed-off-by: dongwenjuan <dong.wenjuan@zte.com.cn>
2018-12-27 11:35:02 +08:00
Matthias Rampke ad36bba13d
Release 0.9.0-rc2
rc1 failed to build because of CircleCI/Quay issues. Let's try this
again …

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-12-21 09:48:44 +00:00
Matthias Rampke 4d0c8ab2c2
bump to 0.9.0-rc1
since build issues prevented rc0 from being built through the normal
process, make a new release.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-12-20 17:37:27 +00:00
Matthias Rampke f13069832d
Actually cut out staticcheck
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-12-20 17:33:24 +00:00
Matthias Rampke d712534c13
Try working around staticcheck issues
by not running staticcheck. meh.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-12-20 17:31:40 +00:00
Matthias Rampke 15e0f4c963
Release candidate for 0.9.0
both the client library update and the TTLs may have unexpected
consequences. cut a pre-release so that they can be test driven.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-12-20 16:50:45 +00:00
Matthias Rampke 141e366e22
Add CHANGELOG entry for #164
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-12-20 16:49:50 +00:00
Matthias Rampke cd3a546179
Clarify TTLs configuration remark
I realized that "TTLs are applied" is ambiguous. Metrics don't only
expire on receiving a sample, so mention that this is about the
configuration.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-12-20 16:47:22 +00:00
Matthias Rampke 7364c6fe44
Merge pull request #164 from flant/remove_stale_metrics
Remove stale metrics
2018-12-20 16:45:49 +00:00
Ivan Mikheykin 699c11ca11 Rework tests to not depend on actual wall clocks
Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
2018-12-19 08:24:25 +03:00
Ivan Mikheykin 331d2a56d0 Language fixes in README, reduce map lookups in saveLabelValues.
Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
2018-12-19 08:24:17 +03:00
Ivan Mikheykin e550f061f6 Use updated ttl value from mapping in saveLabelValues
Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
2018-12-18 09:46:10 +03:00
Ivan Mikheykin d1b2dd47a8 TTL expiration tests, README update
Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
2018-12-18 09:46:05 +03:00
Ivan Mikheykin 57495db281 rename labelsNames to labelNames
Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
2018-12-18 08:39:23 +03:00
Ivan Mikheykin e1a3a5fc32 Configured ttl value for stale metrics
Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
2018-12-18 08:39:23 +03:00
Ivan Mikheykin b4e29c5f18 Remove stale timeseries
- ttl is hardcoded — should be in mapping.yaml
- works with metrics without labels

Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
2018-12-18 08:39:23 +03:00
Ivan Mikheykin b638b9d808 Replace Metrics with Collectors
- use MetricVec family instead of Metric
- dynamic label values instead of ConstLabels
- use dto.Metric to gain histrogram value in exporter_test
- remove hash calculations

Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
2018-12-18 08:39:23 +03:00
Matthias Rampke ef5d2c8a79
Add basic release note for #171
I'd like to add more detail, but I'm not sure I understand the
implications just yet, and they will probably change with #164.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-12-17 19:47:16 +00:00
Matthias Rampke a133af8ffb
Merge pull request #171 from simonpasquier/bump-client_golang
Bump prometheus/client_golang to v0.9.2
2018-12-17 18:57:41 +00:00
Simon Pasquier a856251d79 Bump prometheus/client_golang to v0.9.2
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2018-12-17 13:42:24 +01:00
Matthias Rampke b3bf4d1f8b
Release 0.8.1
and add changelog for #169

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-12-05 21:54:40 +00:00
Matthias Rampke e019c01fb5
Merge pull request #169 from Kong/fix-backtracking-captures-being-overwritten
fix: don't let captured fields being overwritten by backtracking
2018-12-05 21:48:52 +00:00
Wangchong Zhou d0ad532fa1
fix: don't let captured fields being overwritten by backtracking
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-12-05 11:42:34 -08:00
Matthias Rampke 275559585e
Remove false Docker name override
and the unused QUAY_IMAGE_NAME variable altogether.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-11-30 16:12:19 +00:00
Matthias Rampke b27cfd9c36
Merge pull request #166 from simonpasquier/go-modules
*: support Go modules
2018-11-30 15:39:51 +00:00
Simon Pasquier 8a4f87d19e *: support Go modules
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2018-11-29 11:14:28 +01:00
Matthias Rampke 71ec03e5b3
Merge pull request #165 from simonpasquier/circleci-2.1
circleci: switch to 2.1 config
2018-11-26 16:16:37 +00:00
Simon Pasquier c8cf42ca4e circleci: switch to 2.1 config
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2018-11-26 17:02:28 +01:00
Matthias Rampke 040760ec22
Merge pull request #162 from prometheus/grobie/reduce-indentation
Break out event handling into its own function
2018-11-05 09:56:57 +00:00
Matthias Rampke 397fd90e94
Add changelog entry for #161 2018-11-05 09:55:21 +00:00
Matthias Rampke a51c9be791
Merge pull request #161 from filippog/unmapped-fix
Register eventsUnmapped counter
2018-11-05 09:54:09 +00:00
Filippo Giunchedi 9b44d79582 Register eventsUnmapped counter
See also the related discussion at #160

Signed-off-by: Filippo Giunchedi <filippo@wikimedia.org>
2018-11-03 13:07:27 +01:00
Tobias Schmidt ab844a3f63
Break out event handling into its own function
It's idiomatic in go to keep code indentation due to nested loops to a
minimum. Decoupling the events handling function into its own function
makes it easier to read the code and test the behavior in isolation of
the channel handling. It's now also easily possible to process events
in parallel without having to touch actual business code.

Signed-off-by: Tobias Schmidt <tobidt@gmail.com>
2018-11-02 18:28:18 +01:00
Matthias Rampke 3b846b33a8
Consistently use v prefix in changelog
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-10-12 08:33:27 +00:00
Matthias Rampke 555cd98958
Release 0.8.0
I've been running the RC in production without issues.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-10-12 08:30:58 +00:00
Matthias Rampke 877630c2b7
Release RC for version 0.8.0
the FSM change is quite deep, I want to have a set of binaries to test
with.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-10-10 22:03:04 +00:00
Matthias Rampke 00e2c3ff26
Merge pull request #157 from Kong/feat/fsm-matcher
Faster glob matching using a finite state machine
2018-10-11 00:02:06 +02:00
Matthias Rampke 4e53440316
Move bench target out of common Makefile
we should not change the vendored Makefile.common here.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-10-10 21:37:26 +00:00
Matthias Rampke e5734e34e9
Copy edit comments in fsm/formatter
Fixing a typo and language.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-10-10 21:31:51 +00:00
Matthias Rampke 97f71db21b
Put in-line image on its own paragraph
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-10-10 21:24:08 +00:00
Matthias Rampke 9fc976d906
Copy edits in FSM README
Format quote as such, capitalize FSM.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-10-10 21:22:53 +00:00
Matthias Rampke 761e64df10
Copy-edits in README
straightening out some wording, and fixing unquoted `*`.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-10-10 21:18:00 +00:00
Wangchong Zhou 4d9ce8c70a
add readmes
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-10-04 10:55:33 -07:00
Wangchong Zhou c10e80c44b
optimizations
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-10-03 16:31:00 -07:00
Wangchong Zhou 699fa13c8c
add benchmark test to ci
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-28 14:42:09 -07:00
Wangchong Zhou fcf11f02e5
promote formatLabels to mapper package
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-28 14:03:19 -07:00
Wangchong Zhou 5262b2904c
tidy up and use go benchmark
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-28 12:58:25 -07:00
Wangchong Zhou 6d709d52c1
gofmt
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-24 16:46:16 -07:00
Wangchong Zhou a0681a0cd2
more perf test
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-24 16:08:08 -07:00
Wangchong Zhou a8dcc589e5
add more perf test
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-24 13:36:43 -07:00
Wangchong Zhou f387766cc2
cleanup and add comments
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-24 13:36:08 -07:00
Wangchong Zhou 668e31e5f1
license header
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-21 18:13:23 -07:00
Wangchong Zhou 5e1df60d22
abstract dumpFsm
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-21 18:11:00 -07:00
Wangchong Zhou e634997791
move fsm to sepeare pkg
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-21 18:10:51 -07:00
Wangchong Zhou a751c0c091
cleanup
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-13 12:23:59 -07:00
Wangchong Zhou 9ebab25dfa
ordering
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-13 12:12:41 -07:00
Wangchong Zhou c2742aa299
implement backtrack
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-12 18:18:12 -07:00
Wangchong Zhou dad04e9c8b
detect backtracking
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-12 14:44:07 -07:00
Wangchong Zhou bfe23298aa
replace glob matching
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-11 17:34:19 -07:00
Wangchong Zhou 825b734b3e
Implement "fsm" match type
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
2018-09-10 12:04:44 -07:00
Matthias Rampke 26846b86b3
Merge pull request #156 from gbahrani/doc_fix_docker_run_command
Fixed docker run command
2018-09-07 13:55:06 +02:00
gaurav 3ba10e2cb5 Fixed docker run command for:
1. Configuration file extension changed from .conf to .yml
2. Added missing dash (-) in statsd-exporter inputs

Signed-off-by: gaurav <gbahrani@gmail.com>
2018-09-07 11:44:28 +00:00
Matthias Rampke 9480025e61
Merge pull request #150 from prometheus/mr/maintainer-label
Use maintainer label in Dockerfile
2018-08-30 10:38:56 +02:00
Matthias Rampke 90b6066252
Use maintainer label in Dockerfile
fixes #149.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-08-30 08:24:49 +00:00
Matthias Rampke 95d60eed01
Add a note about flag conventions
this note can be removed in half a year or so.

Fixes #147.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-08-28 08:08:46 +00:00
Matthias Rampke 0ad6f7e7cb
Merge pull request #145 from prometheus/mr/improvement-enhancement
Changelog: use ENHANCEMENT
2018-08-22 11:10:51 +02:00
Matthias Rampke 3c74b10043
Changelog: use ENHANCEMENT
to be in line with the Prometheus release guidelines:

https://github.com/prometheus/prometheus/wiki/HOWTO-cut-a-new-release#prepare-your-release

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-08-22 08:18:23 +00:00
Matthias Rampke 1870cbb30c
Fix changelog entry formatting
one was missing the parenthesis around the PR number.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-08-22 08:09:39 +00:00
Matthias Rampke 82f75d3b9a
Release v0.7.0
Fixes #144

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-08-22 07:49:02 +00:00
Matthias Rampke 3a6b6ce5d5
Update the README for #141
it has a copy of the usage

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-08-21 08:57:44 +00:00
Matthias Rampke e1693708d4
Add changelog entry for #141
with a note about the breaking change.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-08-21 08:56:28 +00:00
Matthias Rampke 88a7eef426
Merge pull request #141 from negz/master
Switch to kingpin for flag handling
2018-08-21 10:50:29 +02:00
Nic Cope fcc398a032 Switch to kingpin for flag handling
This commit also removs the deprecated -statsd.listen-address flag. Switching
to kingpin is a breaking change in that flags now start with two hyphens (e.g.
--statsd.listen-udp), and thus a good time to remove deprecated flags.

Signed-off-by: Nic Cope <negz@planet.com>
2018-08-20 13:18:59 -07:00
Matthias Rampke 84f1ef33d4
Merge pull request #140 from prometheus/mr/mapper-package
Move mapper to a package
2018-08-15 08:13:32 +02:00
Matthias Rampke d9f305b6f2
Inject the mappings count metric into the library package
so that it can be initialized with an exporter-specific name.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-08-14 09:31:38 +00:00
Matthias Rampke 40a13e604f
Move mapper -> pkg/mapper
to make clear that this is meant to be used elsewhere

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-08-14 09:20:00 +00:00
Matthias Rampke 124c5b88d0
Move mapper to a package
This allows the mapping logic and configuration format to be re-used by
the graphite exporter.

Enables prometheus/graphite_exporter#37, cf. https://github.com/prometheus/graphite_exporter/pull/52#issuecomment-412324849

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-08-12 11:14:18 +00:00
Matthias Rampke 419e27d284
Merge pull request #139 from prometheus/mr/changelog-links
Make all the PR references in CHANGELOG links
2018-08-09 14:33:26 +02:00
Matthias Rampke 8dbd5e7770
Make all the PR references in CHANGELOG links
for clickability.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-08-09 10:11:23 +00:00
Matthias Rampke e32ce67fd9
Add #135 to the changelog
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-08-09 10:09:01 +00:00
Matthias Rampke b7657e8399
Merge pull request #135 from hbagdi/feat/summary-quantiles
feat: configurable quantiles for Summaries
2018-08-09 11:40:26 +02:00
Matthias Rampke 8d1a9e0330
Break the quantile documentation into a summary-specific paragraph
to untangle the summary and histogram configuration, give an explicit
example of a summary match.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-08-09 08:18:39 +00:00
Harry Bagdi a144b1f9f7 feat: configurable quantiles for Summaries
* Quantile values for a Summary are now configurable.

* The default quantiles (DefObjectives) in the prometheus Go client library is
deprecated. This commit removes the reliance on it.

Signed-off-by: Harry Bagdi <harrybagdi@gmail.com>
2018-08-08 19:41:41 -07:00
Matthias Rampke 0ffa3f9865
Add notable unreleased changes to log
so it's easier to put together the next release.

Signed-off-by: Matthias Rampke <mr@soundcloud.com>
2018-07-04 10:28:11 +00:00
Ben Kochie c4fb3768ac
Merge pull request #137 from prometheus/bjk/circle
Update CircleCI to 2.0
2018-07-03 09:46:52 +02:00
Ben Kochie 778ca7f991 Update CircleCI to 2.0
Signed-off-by: Ben Kochie <superq@gmail.com>
2018-07-03 09:19:40 +02:00
Matthias Rampke 09e16e7aa9
Merge pull request #136 from westphahl/match-metric-type
Allow mapping match on metric type
2018-07-02 15:22:54 +00:00
Ben Kochie 8971b30a76
Merge pull request #134 from simonpasquier/use-makefile-common
Use Makefile.common from Prometheus
2018-06-18 14:35:33 +02:00
Simon Pasquier 79fa36fe39 Sync Makefile.common from prometheus
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2018-06-18 14:05:04 +02:00
Simon Westphahl d7357a2173 Adapt mapper test to changed signature
Co-authored-by: Simon Westphahl <westphahl@gmail.com>
Signed-off-by: Simon Westphahl <simon.westphahl@bmw.de>
2018-06-15 19:41:13 +02:00
Simon Westphahl b2423c56a5 Update readme regarding metric type matching
Co-authored-by: Simon Westphahl <westphahl@gmail.com>
Signed-off-by: Simon Westphahl <simon.westphahl@bmw.de>
2018-06-15 14:26:47 +02:00
Simon Westphahl 568f744f2e Tests for metric type mapping config
Co-authored-by: Simon Westphahl <westphahl@gmail.com>
Signed-off-by: Simon Westphahl <simon.westphahl@bmw.de>
2018-06-15 11:36:23 +02:00
Simon Westphahl b6c7e863d3 Allow mappings to match on metric types
Co-authored-by: Simon Westphahl <westphahl@gmail.com>
Signed-off-by: Simon Westphahl <simon.westphahl@bmw.de>
2018-06-15 11:36:12 +02:00
Simon Pasquier 4a9cde8cef travis: switch to Go 1.10.x and 1.x
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2018-05-23 14:04:34 +02:00
Simon Pasquier 27f07a6516 Use Makefile.common from Prometheus
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2018-05-23 12:49:57 +02:00
Matthias Rampke 16865d75b7
Merge pull request #126 from yuiofthesun/avoid-regex-panic
Avoid regex panic
2018-02-23 09:31:02 +01:00
Katharina Dankert 7e86bcaa92 Avoid panic from compiling user supplied regex
If an invalid regex is supplied mustCompile would panic during
configuration reload. Return an error instead that can be handled.
2018-02-22 23:50:25 +01:00
Katharina Dankert d1f7ca4239 Fix the test for bad regexes
This test did not fail because the regex was bad, it failed because yaml
parsing failed.

This fixes the yaml which uncovers a panic in initFromYAMLString.
2018-02-22 23:46:19 +01:00
Matthias Rampke 745e53700f
Merge pull request #121 from prometheus/brian-brazil-patch-1
Update a few Bridges we missed to Exporter
2018-01-30 21:19:25 +01:00
Brian Brazil fbbd6452c6
Update a few Bridges we missed to Exporter 2018-01-30 20:01:29 +00:00
Matthias Rampke 76f5f422b4
Merge pull request #118 from prometheus/grobie/readme-metrics-naming
Use _total suffix for counters
2018-01-18 09:12:20 +01:00
Tobias Schmidt c11d1e9cf2 Use _total suffix for counters
According to the project's naming best practices[0], the suffix to
indicate a counter type is called `_total`.

[0]: https://prometheus.io/docs/practices/naming/
2018-01-18 00:48:42 +01:00
Matthias Rampke 3fd85c92fc
Actually update the version
of course I forgot a step.
2018-01-17 17:43:26 +00:00
Matthias Rampke 17524907f7
Release v0.6.0
There have been no reports of issues with the drop action, and
@erickpintor has been running the metric name change already. Let's go!
2018-01-17 17:25:55 +00:00
Matthias Rampke 9f409ad982
Add changelog entry for #117 2018-01-17 17:09:51 +00:00
Matthias Rampke 8608d9db40
Fix double-plural 2018-01-17 17:09:16 +00:00
Matthias Rampke 9180cd3afd
Merge pull request #117 from erickpintor/dynamic-metric-name
Allow for dynamic metric name
2018-01-17 18:09:07 +01:00
Erick Pintor f058f3aa33 document metric name and labels names unique set 2018-01-17 14:34:33 -02:00
Erick Pintor 515ae0ee89 document metric name templating for regex matches 2018-01-17 14:30:40 -02:00
Erick Pintor 27ee4050c4 allow for dynamic metric name 2018-01-16 18:45:55 -02:00
Matthias Rampke d96145e47f
Start changelog for next version
and add #115, which is the only change that affects the released binary
so far.
2018-01-08 18:36:31 +00:00
Matthias Rampke 25c9946cf3
Merge pull request #115 from bakins/bakins/match-actions
Add drop action for matches
2018-01-08 18:32:44 +00:00
Brian Akins 6738c909a5 Add drop action for matches 2018-01-02 17:21:50 -05:00
Matthias Rampke a794d58413
Fix incorrect --help output in README
This removes the not actually available log flags from the README. We
should really have those (#111), but at least it's less confusing this
way.

Fixes #110.
2017-11-29 14:20:24 +00:00
Matthias Rampke 3523ac00b8
Update Changelog title 2017-11-16 15:25:42 +00:00
Matthias Rampke 1fa2dff843
Preparation for v0.5.0 release (#108)
Update version, and add changelog entry including upgrade instructions.
2017-11-16 16:22:02 +01:00
Brian Akins 50a5c3e5f7 Formatting and typo fixes 2017-11-16 08:18:16 -05:00
Brian Akins a4c9927b89 Add example for config file. Rearrange list of changes 2017-11-15 07:03:40 -05:00
Matthias Rampke d9db83b9be
Merge pull request #106 from prometheus/mr/rework-sample-counters
Break out the telemetry during sample processing
2017-11-15 09:42:46 +01:00
Brian Akins 143a588871 Preperation for v0.5.0 release 2017-11-14 11:04:52 -05:00
Matthias Rampke 520e51e6ff
Merge pull request #101 from bakins/bakins/metric-name
Allow using name in mapping rather than 'name' label
2017-11-13 14:24:54 +01:00
Brian Akins e58bf8e1ca Set name in mapping, rather than from special label with key 'name' 2017-11-13 07:23:14 -05:00
Matthias Rampke 0ceac67bc6
Merge pull request #107 from prometheus/mr/fix-and-test-readme
Fix and test examples in the README
2017-11-11 00:17:54 +01:00
Matthias Rampke 0ac908603a Update documentation of metric name escaping.
The escaping changed in 728bdc52ae, before
0.1.0. Add a test for the escape function, and test various cases,
including those mentioned in the README.

This reveals that the README is inaccurate, adjust it to what has been
the reality for many years. Fixes #97.
2017-11-10 20:34:10 +00:00
Matthias Rampke 6c04ec1d89 Fix mapping example in the README
Strings with leading asterisks need to be escaped in YAML.

Add the same examples into the test suite to make sure they do what we
claim they do.

Fixes #102.
2017-11-10 20:19:41 +00:00
Matthias Rampke 45d22f2add Add examples for quoting matches that start with *.
The YAML parser chokes on strings starting with asterisks. Add a
scenario to the spec that shows this, and that shows that quoting fixes
the issue.
2017-11-10 20:01:57 +00:00
Matthias Rampke e24888356f Add example for configuration without trailing newline.
Inspired by #102, illustrate and ensure that trailing newlines are not
necessary.
2017-11-10 20:01:15 +00:00
Matthias Rampke cdf79ba2f9 Break out the telemetry during sample processing
The "packets" metric had heavily overloaded meaning for different
"outcomes", and would often be incremented multiple times, sometimes
even with a single (per-line) increment in one outcome corresponding to
multiple increments in another.

This removes the broken metric, and replaces it with separate total and
error counters for each level of processing. This allows monitoring the
network traffic handled separately from the samples incurred by it.
2017-11-10 19:23:54 +00:00
Matthias Rampke d4d0b4a6a7
Merge pull request #105 from prometheus/mr/pr-96
Fix matching empty statsd metric components
2017-11-10 17:50:32 +01:00
Jens Bissinger 78de4b11db Fix matching empty statsd metric components 2017-11-10 15:29:24 +00:00
Matthias Rampke ff308119cf
Merge pull request #104 from prometheus/mr/fix-tests
Fix TravisCI tests: Force IPv4 for the mock TCP listener
2017-11-10 16:01:39 +01:00
Matthias Rampke ea77554dc4 Force IPv4 for the mock TCP listener.
Travis CI [does not have IPv6][0] in any environment. It could be
[enabled][1] if we ran the build in a VM, but that is much slower to
start. Instead, we just force the test connection to use IPv4.

[0]: https://blog.travis-ci.com/2015-11-27-moving-to-a-more-elastic-future#ipv6-no-longer-present
[1]: https://github.com/travis-ci/travis-ci/issues/5200#issuecomment-162539556
2017-11-10 14:21:38 +00:00
Julius Volz 92702b80fd
Merge pull request #103 from prometheus/grobie/new-maintainer
Change maintainership to Matthias
2017-11-09 17:45:00 +01:00
Tobias Schmidt 4f847ac004 Change maintainership to Matthias 2017-11-09 11:34:34 +01:00
Dave Rawks ab2a88c06f Allow help text to be customized (#87)
* Updated mappings to accept custom help text in YAML config
* Updated exporter to display configured help messages
* Update README to reflect aditional configurability
* Removed inaccurate comment

* Removed some cruft from a rebase
2017-10-04 18:11:58 +02:00
Ben Kochie 9accf494a9 Merge pull request #98 from drawks/remove_legacy_mapper
Removes support for legacy mapper config
2017-09-29 10:08:08 +02:00
Dave Rawks ec3cc120e2 Resolves #84 adds support for regex mappers (#85)
* Added `regex` match_type as valid config callout in both individual mappers
    and mapper defaults
  * Added test coverage for changes
  * Updated documentation to reflect usage of `match_type` parameter and
    provide example of a raw regex match rule
2017-09-29 09:57:17 +02:00
Tobias Schmidt bd0f2139af Merge pull request #99 from drawks/remove_add_suffix_flag
Removes `-statsd.add-suffix` option flag
2017-09-29 00:18:19 +02:00
Dave Rawks 0478c40ab0 Removes -statsd.add-suffix option flag
* Remove option flag
* Update NewExporter call signature to not take suffix boolean
* Update tests to reflect new behavior and signature
* Update documentation to reflect option flag removal
2017-09-28 11:30:17 -07:00
Dave Rawks 892b725faf Removes support for legacy mapper config
* Removed legacy mapper config parser
  * Removed logic to switch to YAML parsing based on mapping filename
  * Removed tests for legacy mapper config
  * Remove references to legacy mapper config format from `README.md`
2017-09-28 11:11:26 -07:00
Ben Kochie 2dfca9be7c Merge pull request #94 from prometheus/bjk/update_vendoring
Update vendoring
2017-08-31 17:36:54 +02:00
Ben Kochie f717018146 Update Go version in circle CI. 2017-08-30 18:00:52 +02:00
Ben Kochie 4b83af49b7 Update travis config. 2017-08-30 17:59:10 +02:00
Ben Kochie 19d90f1c21 Cleanup vendor github.com/Sirupsen/logrus
Use github.com/sirupsen/logrus@v1.0.3
2017-08-30 17:53:27 +02:00
Ben Kochie b14d0d6611 Update vendor gopkg.in/yaml.v2 2017-08-30 17:52:17 +02:00
Ben Kochie 072bc00f64 Update vendor golang.org/x/sys/unix 2017-08-30 17:50:06 +02:00
Ben Kochie 3f4f12eb1f Update vendor github.com/prometheus/procfs 2017-08-30 17:49:43 +02:00
Ben Kochie 115cb0e157 Update vendor github.com/prometheus/common/... 2017-08-30 17:48:19 +02:00
Ben Kochie fe0b1f55de Update vendor github.com/prometheus/client_model/go 2017-08-30 17:46:30 +02:00
Ben Kochie c7a2ae9b14 Update vendor github.com/beorn7/perks/quantile 2017-08-30 17:45:30 +02:00
Ben Kochie 22270c168d Update vendor github.com/golang/protobuf/proto 2017-08-30 17:44:51 +02:00
Ben Kochie 533a6fcb18 Update vendor github.com/matttproud/golang_protobuf_extensions/pbutil 2017-08-30 17:42:46 +02:00
Ben Kochie 65d2513fde Update vendor github.com/prometheus/client_golang 2017-08-30 17:39:31 +02:00
Tobias Schmidt 7e11f326ae Merge pull request #92 from drawks/log_levels
Resolves #81 - Reduce log levels
2017-08-26 12:25:26 +02:00
Tobias Schmidt d2ca0a8c0b Merge pull request #91 from drawks/issue-88
Resolves #88 - histograms use wrong units
2017-08-26 12:24:02 +02:00
Dave Rawks e493a9c766 Fixup per PR review:
* Added internal metric to track `illegal_negative_counter` events
2017-08-15 09:03:13 -07:00
Dave Rawks 06444ed5c0 Minor fix-ups per PR discussion
* Removed extraneous newline
  * Reformatted/ordered imports
  * Used hash function to derive index of `Elements` instead of
    hardcoding hash result
2017-08-15 08:51:13 -07:00
Dave Rawks 42e41f1a7e Resolves #81 - Reduce log levels
* Reduced all `log.Error*` events to `log.Debug*` in `exporter.go` where
  an existing internal metric tracks the event.
2017-08-14 16:04:57 -07:00
Dave Rawks b2082eda2b Added test for histogram unit conversion 2017-08-14 15:20:45 -07:00
Dave Rawks e37bee9bf2 Resolves #88 - histograms use wrong units 2017-08-14 11:23:14 -07:00
Julius Volz aeab2905ad Merge pull request #66 from bakins/extended-config
Allow histograms for timer metrics
2017-08-03 17:25:30 +02:00
Tobias Schmidt a31feb5365 Merge pull request #82 from jwfang/tcp-doc3
update README for tcp listener, fix #75
2017-08-02 15:09:12 +02:00
jwfang 1194e00dec Dockerfile export 9125/tcp 2017-08-02 13:31:33 +08:00
jwfang bbdbb9a050 update README for tcp listener, fix #75 2017-08-02 13:22:28 +08:00
Brian Akins 9bca336876 Simple YAML configuration docs 2017-08-01 07:26:44 -04:00
Brian Akins 9c1cde63be simplify metric label key validation 2017-08-01 07:07:44 -04:00
Brian Akins c339cc66ac Style fixes 2017-08-01 07:01:06 -04:00
jwfang 07543ac557 Add TCP StatsD listener support (#71)
* add TCP StatsD listener support

* add listen-tcp flag to control UDP/TCP mode on same port

* statsdListenUDP/statsdListenTCP as string, and alias listen-address to listen-udp

* add stats for tcp error/line_too_long

* add test for TCP listener
2017-08-01 12:21:00 +02:00
Brian Akins 93243f61a1 add test case for timer types 2017-07-27 17:01:12 -04:00
Brian Akins c9510f7f23 add simple YAML config tests 2017-07-27 16:58:10 -04:00
Brian Akins 2643f1550f cleanup debug statements 2017-07-26 18:40:56 -04:00
Brian Akins b467a537d5 Validate timer type while reading config 2017-07-26 14:50:29 -04:00
Brian Akins e8997f7cd9 Style: Yaml -> YAML 2017-07-26 14:04:27 -04:00
Brian Akins 74975b8411 merge with upstream master 2017-07-26 14:03:08 -04:00
Tobias Schmidt 8b40f781ef Merge pull request #72 from jacksontj/master
Fixes for crashes with conflicting metric values
2017-07-18 20:19:59 +02:00
Thomas Jackson bbd5227a1c Add metric for total number of conflicting events 2017-07-18 08:58:40 -07:00
Thomas Jackson c1791d7ecb Ensure we log errors every time there is a problem
Move addition of metric to "Elements" until after a successful registry
with prometheus, otherwise we'll continue to increment a metric which
isn't registered
2017-07-18 08:58:40 -07:00
Thomas Jackson d9aa6e2867 Don't crash on conflicting metric names
This patch simply moves the error message from a log.Fatalf() to a
log.Errorf() to continue on.

Fixes #63
2017-07-18 08:58:40 -07:00
Thomas Jackson 22520f4c7b Move value check before metric get
If someone is emitting negative counters we shouldn't even register the
metric for them
2017-07-18 08:58:40 -07:00
Tobias Schmidt 663b6a1e69 Merge pull request #28 from Kiliaro/master
Added support for sampling factor on timing events
2017-05-25 06:48:01 +02:00
Julius Volz 20becbc27b Merge pull request #70 from jasonmoo/master
Allow comments in mapping files
2017-05-24 09:49:45 +02:00
Jason Mooberry 5018c7415a Allow comments in mapping files 2017-05-23 18:12:17 -04:00
Andreas Andersen b5dfc9c9ce Added support for sampling factor on timing events 2017-05-15 15:57:31 +02:00
Ben Kochie 89e5e36b51 Fix v0.4.0 release entry. 2017-05-12 15:02:44 +02:00
Ben Kochie c15ffa2aa2 Merge pull request #69 from prometheus/v0.4.0
Release v0.4.0
2017-05-12 14:52:50 +02:00
Ben Kochie 4b0d773a6e Release v0.4.0
* [IMPROVEMENT] Add increment/decrement support to Gauges #65
* [BUGFIX] Tolerate more forms of broken lines from StatsD #48
* [BUGFIX] Skip metrics with invalid utf8 #50
* [BUGFIX] ListenAndServe now fails on exit #58
2017-05-12 14:36:27 +02:00
Tobias Schmidt 3039d12e3a Create sha256 checksums file during release 2017-04-15 12:51:43 -03:00
Brian Akins 641dc37b5d getMapping now returns 3 values 2017-03-13 08:15:43 -04:00
Brian Akins 1488f0f902 Allow overriding default timing type 2017-03-13 06:32:58 -04:00
Brian Akins 3048412df6 Add YAML config file and ability to set histograms 2017-03-12 21:11:05 -04:00
Brian Akins df926ae85a Add yaml dependency 2017-03-12 19:46:36 -04:00
Julius Volz 03335d91cf Merge pull request #65 from GentlemanJ/master
Added increment/decrement support to Gauges
2017-03-10 12:27:02 +01:00
Justin Reid 9cd4b974e4 consensed if/else statement 2017-03-09 17:39:20 -07:00
Justin Reid 3efcef6229 Simplified inc/dec logic based on PR feedback.
There is no need to add the string to all event types as only Gauge
is compatible with inc/dec functionality.  Removed valueStr from all
events and added a simple boolean to the Gauge event instead
2017-03-09 17:35:29 -07:00
Justin Reid 7fc8727306 Added increment/decrement support to Gauges
Now passing the value as a string (with operation prefix) through to build event so that Listen() can modify the gauge metric appropriately
2017-03-09 15:50:06 -07:00
Ville Törhönen 446b7e6d44 Handle invalid mapping config files (#61)
* When a terminating newline is missing from the metric mapping configuration file, the last definition is not parsed at all. After this change the last 'METRIC_DEFINITION' in the file is equivalent to a newline (either between definitions or as the terminating newline).

* Update mapping, if we are reading the last line of the file. Otherwise we will append the mapping and lose the last label. Since we are updating the mapping in two different places a 'updateMapping' function was introduced.

* Added mapper test for config files without a terminating newline.

* Added another test case where multiple definitions are given without a final terminating newline.

* As suggested by @grobie, we should give an error when a terminating newline is missing. Updated tests accordingly.
2017-02-24 11:48:05 -04:00
Julius Volz 0285d7b4a7 Merge pull request #60 from prometheus/beorn7/meta
Replace AUTHORS.md by an updated MAINTAINERS.md
2017-02-16 21:12:29 +01:00
beorn7 109b5ad053 Replace AUTHORS.md by an updated MAINTAINERS.md 2017-02-16 20:19:09 +01:00
Tobias Schmidt b1f3e6d7be Merge pull request #58 from nordicdyno/master
ListenAndServe now fails on exit
2017-02-11 17:23:29 -05:00
nordicdyno 6ac8203d40 http listener: log and fail on ListenAndServe error 2017-02-10 15:35:38 +03:00
Steve Durrheimer 5a9d2f996a Merge pull request #52 from prometheus/sdurrheimer-circle-use-base-image-for-tests
Use golang-builder base image for tests in CircleCI
2016-09-09 11:21:35 +02:00
Steve Durrheimer c1f2d12554
circle: add tag v-prefix 2016-09-09 08:40:28 +02:00
Steve Durrheimer 24eab4e35a
Use golang-builder base image for tests in CircleCI 2016-09-09 08:34:16 +02:00
Tobias Schmidt 022c10fe0c Merge pull request #51 from prometheus/sdurrheimer-use-promu-default-go-version
Use promu default go version + use 1.6 tag for cicleci tests
2016-08-31 12:02:09 +02:00
Steve Durrheimer 8bf751d4e3
Use promu default go version + use 1.6 tag for cicleci tests 2016-08-31 08:05:49 +02:00
Tobias Schmidt 35828e29e9 Merge pull request #50 from Jimdo/drop_invalid_utf8
Skip metrics with invalid utf8
2016-07-27 16:53:34 -04:00
Ilya Margolin 237499eced Add a benchmark for handlePacket 2016-07-22 17:19:00 +02:00
Ilya Margolin 1fbc392800 Remove unintended changes 2016-07-21 17:55:47 +02:00
Ilya Margolin bb4e42068f Skip metrics with invalid utf8 2016-07-20 20:27:23 +02:00
Tobias Schmidt 0c8b644ee1 Merge pull request #48 from haguenau/tolerate-broken-metrics
Tolerate more forms of broken lines from StatsD
2016-05-19 12:51:36 -04:00
David Haguenauer 56f65c4870 Don't panic on empty metric names or components
* Don't panic on empty metric names
* Don't panic on empty metric components
* Test tolerance the above kinds of broken StatsD lines
2016-05-19 12:43:35 -04:00
Steve Durrheimer 00f56b3809
Remove unused Makefile.COMMON file 2016-05-14 21:15:13 +02:00
Johannes 'fish' Ziemke e00d9e84aa Merge pull request #45 from prometheus/fish/release-0.3.0
Release 0.3.0
2016-05-05 10:23:59 -07:00
Johannes 'fish' Ziemke cc3025a1f9 Release 0.3.0 2016-05-05 19:23:31 +02:00
Ben Kochie dcb67944be Merge pull request #46 from prometheus/sdurrheimer/fix-circleci-flanky-go-get
Fix CircleCI flanky go get
2016-05-05 06:52:44 -07:00
Steve Durrheimer 7a76b03aa7
Change the test docker image tag to match promu golang version 2016-05-05 13:11:05 +02:00
Steve Durrheimer 246008307f
Fix CircleCI problems during go get promu 2016-05-05 13:10:57 +02:00
Johannes 'fish' Ziemke 1710048a70 Merge pull request #44 from prometheus/fish/use-version-package
Use common/version and common/log packages
2016-05-04 14:36:27 -07:00
Johannes 'fish' Ziemke 03fde8f3ba Use common/version and common/log packages 2016-05-04 23:12:18 +02:00
Johannes 'fish' Ziemke 4d22a721eb Fix parameter to NewExporter in test 2016-05-03 23:45:48 +02:00
Johannes 'fish' Ziemke 61f4c6e926 Merge pull request #42 from prometheus/fish/new-build
New build process
2016-05-03 14:24:03 -07:00
Johannes 'fish' Ziemke cdeb0c9743 Use promu/docker/circleci based release process 2016-05-03 23:08:02 +02:00
Johannes 'fish' Ziemke e26a5e4728 Add Version variable 2016-05-03 20:25:42 +02:00
Johannes 'fish' Ziemke 1f1c0f7030 Merge pull request #43 from prometheus/fish/vendor-all-the-things
Vendor dependencies
2016-05-03 11:25:23 -07:00
Johannes 'fish' Ziemke a78a6d2635 Vendor dependencies 2016-05-03 19:25:23 +02:00
Johannes 'fish' Ziemke dd0b68f2d8 Merge pull request #41 from prometheus/fish/fix-metric-suffix
Drop _count suffix for loaded_mappings metric
2016-05-03 09:54:20 -07:00
Johannes 'fish' Ziemke dacfb3f1be Drop _count suffix for loaded_mappings metric
This makes the naming consistent with our best pratices.
2016-05-03 18:51:16 +02:00
Johannes 'fish' Ziemke 8e43fc2654 Merge pull request #37 from prometheus/fish/remove-auto-suffixes
Make metric suffixes optional, expose unmapped events
2016-05-03 09:46:59 -07:00
Tobias Schmidt ba9c37eb20 Merge pull request #40 from Jimdo/dogstats-extensions-squashed
Dogstats extensions squashed
2016-05-03 12:42:38 -04:00
Johannes 'fish' Ziemke 3d0ccb9ed5 Count events for which no mapping was found 2016-05-03 18:39:57 +02:00
Ilya Margolin 0b792e0be6 DogStatsD: review changes 2016-05-03 18:28:33 +02:00
Daniel Bonkowski 8f36baf045 sanitize tag keys
- add tests for edge cases
 - fix typo
2016-05-03 18:27:42 +02:00
Johannes 'fish' Ziemke f031e30721 Add flag to disable metric type suffixes 2016-05-03 01:16:34 +02:00
Julius Volz 60dbb43e8a Merge pull request #36 from prometheus/increase-udp-buf
Increase receivable UDP datagram size to 65535 bytes.
2016-04-29 18:13:07 +02:00
Julius Volz c9baaf5ba1 Increase receivable UDP datagram size to 65535 bytes.
Fixes https://github.com/prometheus/statsd_exporter/issues/35
2016-04-29 17:39:55 +02:00
Julius Volz 121026ae3d Merge pull request #33 from klobucar/warn-on-negative
Don't panic when negative number counter is submitted.
2016-04-01 20:00:49 +02:00
Jonathon Klobucar 494cc38bf8 Don't panic when negative number counter is submitted.
Instead now we will send a warning message to the logs
and continue on with our day.

Also a guard has been added when we detect a channel has been
closed and the `Exporter.Listen` function will return out of
its loop vs always running. When a channel is closed there will
be no more data to consume, so this seems correct. It also allows
for a test to be written for the panic.
2016-04-01 10:53:20 -07:00
Ben Kochie 85384f7bc6 Merge pull request #32 from SuperQ/master
Update for 0.2.0 release
2016-03-21 14:42:17 +01:00
Ben Kochie 6a84b510c6 Release 0.2.0
* Update Makefile.
* Add CHANGELOG.md.
2016-03-20 10:52:31 +01:00
Ben Kochie b23cd0ab5b Update build
* Add `.gitignore`.
* Update Makefile.COMMON from prometheus/utils.
2016-03-20 09:40:05 +01:00
Peter Woodman ab7c27ee77 Support datadog extensions to statsd datagrams
Datadog's format extensions allow attaching labels and tags to statsd
metrics, and are documented at
http://docs.datadoghq.com/guides/dogstatsd/#datagram-format

Additionally changes compare method in tests to reflect.DeepEqual, as
the tag maps don't sort deterministically, corrects an inversion in
displaying test failure cases, and treats an invalid sample value as 1
instead of throwing out the sample.
2016-03-04 16:22:34 +01:00
Julius Volz e9eb193ff9 Merge pull request #31 from mmethner/master
fix documentation for docker udp port publishing
2016-02-01 17:48:33 +01:00
Mathias Methner dc0ab29c33 fix documentation for docker udp port publishing 2016-02-01 16:54:59 +01:00
Julius Volz e8f1e9c9c3 Update Julius's email address in AUTHORS.md 2015-10-26 02:25:54 +01:00
Julius Volz 3727277927 Merge pull request #26 from macb/exporter_rename
rename bridge to exporter
2015-10-17 15:50:01 +02:00
Julius Volz 3bf0889452 Merge pull request #25 from macb/root_endpoint
add root endpoint with redirect
2015-10-15 06:21:24 +02:00
Julius Volz 28d4020341 Merge pull request #24 from macb/allow_hyphen_hostname
allow metrics with dashes when mapping
2015-10-12 02:52:22 +02:00
Mac Browning ea7341a6c4 rename bridge -> exporter 2015-10-09 20:34:28 -04:00
Mac Browning c4ab11d05c add root endpoint with redirect 2015-10-09 20:26:05 -04:00
Mac Browning 411b071f1f allow metrics with dashes when mapping 2015-10-09 19:38:21 -04:00
Björn Rabenstein 4270a5ed7e Merge pull request #23 from prometheus/move-to-common
Move from client_golang/model to common/model
2015-09-17 14:38:16 +02:00
beorn7 6a1c44989b Move from client_golang/model to common/model 2015-09-17 13:14:18 +02:00
Julius Volz 6b318a471e Merge pull request #22 from Jimdo/config_udp_buffer
Allow configuration of UDP read buffer
2015-09-09 17:55:53 +02:00
Fabian Stehle 3d7b731cfd Allow configuration of UDP read buffer 2015-09-09 17:50:32 +02:00
Julius Volz b6210fc395 Merge pull request #17 from sdurrheimer/master
New Dockerfile using alpine-golang-make-onbuild base image
2015-07-13 12:17:32 +02:00
Steve Durrheimer 395c1422e5 Add Docker instructions to the README 2015-07-11 13:22:06 +02:00
Steve Durrheimer c2d70fe7dc New Dockerfile using alpine-golang-make-onbuild base image 2015-06-18 20:50:31 +02:00
Steve Durrheimer c8430495ae Update Makefile.COMMON from prometheus/utils 2015-06-18 20:50:31 +02:00
Julius Volz e0bf2be66a Merge pull request #16 from prometheus/document-no-statsd-case
Document use-case without any StatsD server.
2015-06-18 20:15:14 +02:00
Julius Volz 143288bf07 Document use-case without any StatsD server.
Fixes https://github.com/prometheus/statsd_bridge/issues/15
2015-06-18 14:24:46 +02:00
Julius Volz ce864c0131 Merge pull request #14 from prometheus/migrate-logging
Migrate logging to prometheus/log.
2015-05-29 14:22:36 +02:00
Julius Volz 1ee380cc39 Migrate logging to prometheus/log. 2015-05-29 13:45:11 +02:00
72 changed files with 13057 additions and 1012 deletions

48
.circleci/config.yml Normal file
View file

@ -0,0 +1,48 @@
version: 2.1
orbs:
prometheus: prometheus/prometheus@0.17.1
executors:
# Whenever the Go version is updated here, .promu.yml should also be updated.
golang:
docker:
- image: cimg/go:1.21
jobs:
test:
executor: golang
steps:
- prometheus/setup_environment
- run: make
- run: git diff --exit-code
- prometheus/store_artifact:
file: statsd_exporter
workflows:
version: 2
statsd_exporter:
jobs:
- test:
filters:
tags:
only: /.*/
- prometheus/build:
name: build
filters:
tags:
only: /.*/
- prometheus/publish_master:
context: org-context
requires:
- test
- build
filters:
branches:
only: master
- prometheus/publish_release:
context: org-context
requires:
- test
- build
filters:
tags:
only: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/
branches:
ignore: /.*/

6
.dockerignore Normal file
View file

@ -0,0 +1,6 @@
.build/
.tarballs/
!.build/linux-amd64
!.build/linux-armv7
!.build/linux-arm64

4
.gitattributes vendored Normal file
View file

@ -0,0 +1,4 @@
# Managing line ending conversions
# See http://git-scm.com/docs/gitattributes#_end-of-line_conversion
* text=auto
* eol=lf

6
.github/dependabot.yml vendored Normal file
View file

@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "monthly"

View file

@ -0,0 +1,52 @@
---
name: Push README to Docker Hub
on:
push:
paths:
- "README.md"
- ".github/workflows/container_description.yml"
branches: [ main, master ]
permissions:
contents: read
jobs:
PushDockerHubReadme:
runs-on: ubuntu-latest
name: Push README to Docker Hub
if: github.repository_owner == 'prometheus' || github.repository_owner == 'prometheus-community' # Don't run this workflow on forks.
steps:
- name: git checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set docker hub repo name
run: echo "DOCKER_REPO_NAME=$(make docker-repo-name)" >> $GITHUB_ENV
- name: Push README to Dockerhub
uses: christian-korneck/update-container-description-action@d36005551adeaba9698d8d67a296bd16fa91f8e8 # v1
env:
DOCKER_USER: ${{ secrets.DOCKER_HUB_LOGIN }}
DOCKER_PASS: ${{ secrets.DOCKER_HUB_PASSWORD }}
with:
destination_container_repo: ${{ env.DOCKER_REPO_NAME }}
provider: dockerhub
short_description: ${{ env.DOCKER_REPO_NAME }}
readme_file: 'README.md'
PushQuayIoReadme:
runs-on: ubuntu-latest
name: Push README to quay.io
if: github.repository_owner == 'prometheus' || github.repository_owner == 'prometheus-community' # Don't run this workflow on forks.
steps:
- name: git checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set quay.io org name
run: echo "DOCKER_REPO=$(echo quay.io/${GITHUB_REPOSITORY_OWNER} | tr -d '-')" >> $GITHUB_ENV
- name: Set quay.io repo name
run: echo "DOCKER_REPO_NAME=$(make docker-repo-name)" >> $GITHUB_ENV
- name: Push README to quay.io
uses: christian-korneck/update-container-description-action@d36005551adeaba9698d8d67a296bd16fa91f8e8 # v1
env:
DOCKER_APIKEY: ${{ secrets.QUAY_IO_API_TOKEN }}
with:
destination_container_repo: ${{ env.DOCKER_REPO_NAME }}
provider: quay
readme_file: 'README.md'

38
.github/workflows/golangci-lint.yml vendored Normal file
View file

@ -0,0 +1,38 @@
---
# This action is synced from https://github.com/prometheus/prometheus
name: golangci-lint
on:
push:
paths:
- "go.sum"
- "go.mod"
- "**.go"
- "scripts/errcheck_excludes.txt"
- ".github/workflows/golangci-lint.yml"
- ".golangci.yml"
pull_request:
permissions: # added using https://github.com/step-security/secure-repo
contents: read
jobs:
golangci:
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: install Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: 1.22.x
- name: Install snmp_exporter/generator dependencies
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
if: github.repository == 'prometheus/snmp_exporter'
- name: Lint
uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v4.0.0
with:
version: v1.56.2

8
.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
dependencies-stamp
/statsd_exporter
/.build
/.deps
/.release
/.tarballs
*~
/vendor

6
.gitpod.Dockerfile vendored Normal file
View file

@ -0,0 +1,6 @@
FROM gitpod/workspace-full
RUN sudo apt-get update && \
sudo apt-get install -y netcat-traditional socat && \
sudo apt-get clean && \
sudo rm -rf /var/lib/apt/lists/*

13
.gitpod.yml Normal file
View file

@ -0,0 +1,13 @@
tasks:
- init: go get
command: go build . && ./statsd_exporter
- command: printf 'Try:\n\n\techo "test.gauge:42|g" | socat - TCP:127.0.0.1:9125\n\n'
ports:
- port: 9102
onOpen: open-preview
- port: 9125
onOpen: ignore
image:
file: .gitpod.Dockerfile

27
.golangci.yml Normal file
View file

@ -0,0 +1,27 @@
run:
issues-exit-code: 1
tests: true
linters:
disable:
- errcheck
enable:
- deadcode
- goimports
- gosimple
- govet
- ineffassign
- nakedret
- staticcheck
- structcheck
- unused
- varcheck
- whitespace
linters-settings:
govet:
check-shadowing: true
issues:
exclude-use-default: false
exclude:
- 'shadow: declaration of "err" shadows declaration at line (\d+)'
max-issues-per-linter: 0
max-same-issues: 0

18
.promu.yml Normal file
View file

@ -0,0 +1,18 @@
go:
# Whenever the Go version is updated here, .circle/config.yml should also
# be updated.
version: 1.21
repository:
path: github.com/prometheus/statsd_exporter
build:
ldflags: |
-X github.com/prometheus/common/version.Version={{.Version}}
-X github.com/prometheus/common/version.Revision={{.Revision}}
-X github.com/prometheus/common/version.Branch={{.Branch}}
-X github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
tarball:
files:
- LICENSE
- NOTICE

25
.yamllint Normal file
View file

@ -0,0 +1,25 @@
---
extends: default
ignore: |
ui/react-app/node_modules
rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
commas: disable
comments: disable
comments-indentation: disable
document-start: disable
indentation:
spaces: consistent
indent-sequences: consistent
key-duplicates:
ignore: |
config/testdata/section_key_dup.bad.yml
line-length: disable
truthy:
check-keys: false

View file

@ -1,13 +0,0 @@
The Prometheus project was started by Matt T. Proud (emeritus) and
Julius Volz in 2012.
Maintainers of this repository:
* Julius Volz <julius@soundcloud.com>
The following individuals have contributed code to this repository
(listed in alphabetical order):
* Björn Rabenstein <beorn@soundcloud.com>
* Julius Volz <julius@soundcloud.com>
* Matt T. Proud <matt.proud@gmail.com>

464
CHANGELOG.md Normal file
View file

@ -0,0 +1,464 @@
## 0.26.1 / 2024-03-22
* [SECURITY] Update dependencies, including `google.golang.org/protobuf` for CVE-2024-24786
This is a maintenance release.
## 0.26.0 / 2023-12-06
* [CHANGE] Update dependencies: prometheus/common, client model, and Go 1.21
* [FEATURE] Add option to honor original labels from event tags over labels specified in mapping configuration ([#521](https://github.com/prometheus/statsd_exporter/pull/521))
Thank you @rabenhorst for the `honor_labels` contribution!
## 0.25.0 / 2023-10-23
* [CHANGE] Update `client_golang` ([#508](https://github.com/prometheus/statsd_exporter/pull/508), [#513](https://github.com/prometheus/statsd_exporter/pull/513))
* [ENHANCEMENT] Process UDP packets asynchronously ([#511](https://github.com/prometheus/statsd_exporter/pull/511))
* [BUGFIX] Debug-log incoming lines in cleartext ([#510](https://github.com/prometheus/statsd_exporter/pull/510))
* [SECURITY] Update `golang.org/x/net` ([#516](https://github.com/prometheus/statsd_exporter/pull/516))
This release is less likely to drop UDP packets under very high traffic.
Additionally, when it does, it now attempts to record that this happened in the metric `statsd_exporter_udp_packet_drops_total`, where previously this could only be detected from operating system metrics.
If you are already monitoring for OS-level UDP packet drops, you _must_ also monitor this metric.
The exporter will pull packets from the UDP socket queue much more quickly and queue them internally before processing.
Existing monitoring for packet drops will no longer be sufficient to detect dropped events, but attribution to the exporter is easier with this new metric.
Many thanks to @sumeshpremraj and @kullanici0606 for their contributions, and @pedro-stanaka for helping with the async UDP processing!
## 0.24.0 / 2023-06-02
* [FEATURE] Improve the landing page experience ([#504](https://github.com/prometheus/statsd_exporter/pull/504))
* [FEATURE] Support scaling parameter in mapping ([#499](https://github.com/prometheus/statsd_exporter/pull/499))
## 0.23.3 / 2023-06-02
* [SECURITY] Maintenance release, updating dependencies
* [ENHANCEMENT][library] Allow instantiating configuration without going through YAML ([#491](https://github.com/prometheus/statsd_exporter/pull/491))
Version 0.23.2 was mistagged and thus skipped.
## 0.23.1 / 2023-03-08
* [SECURITY] Update all dependencies ([#489](https://github.com/prometheus/statsd_exporter/pull/489))
## 0.23.0 / 2022-12-07
* [CHANGE] Print help and version to standard out ([#469](https://github.com/prometheus/statsd_exporter/pull/469))
* [FEATURE] Support experimental native histograms ([#474](https://github.com/prometheus/statsd_exporter/pull/474))
## 0.22.8 / 2022-09-13
* [BUGFIX] Prevent poisoning with gauge/distribution naming collision ([#461](https://github.com/prometheus/statsd_exporter/pull/461))
* [CHANGE] Update `client_golang` dependency ([#463](https://github.com/prometheus/statsd_exporter/pull/463))
## 0.22.7 / 2022-07-08
* [CHANGE] Build with Go 1.18 ([#450](https://github.com/prometheus/statsd_exporter/pull/450))
## 0.22.6 / 2022-07-08
* [CHANGE] Update dependencies ([#449](https://github.com/prometheus/statsd_exporter/pull/449))
This is another housekeeping release.
## 0.22.5 / 2022-05-06
* [ENHANCEMENT] Add metric for total lines relayed ([#434](https://github.com/prometheus/statsd_exporter/pull/434))
This release is built with Go 1.17.9, to address security issues in Go.
## 0.22.4 / 2021-11-26
* [BUGFIX] Make Docker image compatible with the runAsNonRoot setting in Kubernetes pods ([#409](https://github.com/prometheus/statsd_exporter/pull/409))
* [BUGFIX] Library: fix support for custom Registerers with histograms and summaries ([#410](https://github.com/prometheus/statsd_exporter/pull/410))
## 0.22.3 / 2021-10-26
* [BUGFIX] Accept metrics with multiple dashes even if not mapped ([#402](https://github.com/prometheus/statsd_exporter/pull/402))
## 0.22.2 / 2021-09-10
* [ENHANCEMENT] Add metrics to relay ([#393](https://github.com/prometheus/statsd_exporter/pull/393))
## 0.22.1 / 2021-09-01
* [ENHANCEMENT] Accept incoming metrics with multiple dashes (with mapping) ([#381](https://github.com/prometheus/statsd_exporter//pull/381))
* [ENHANCEMENT] Allow forwarding messages to statsd for easier transition ([#388](https://github.com/prometheus/statsd_exporter/pull/388))
* [BUGFIX] Actually expose pprof endpoints ([#386](https://github.com/prometheus/statsd_exporter/pull/386))
* [BUGFIX] Fix performance regression on metric ingestion ([#390](https://github.com/prometheus/statsd_exporter/pull/390))
## 0.21.0 / 2021-06-10
* [ENHANCEMENT] Update dependencies & switch to go-kit/log ([#379](https://github.com/prometheus/statsd_exporter/pull/379))
This release changes the log format to be more structured, in line with other Prometheus projects.
## 0.20.3 / 2021-06-04
* [ENHANCEMENT] Use extracted go-kit/log to reduce transitive dependencies ([#378](https://github.com/prometheus/statsd_exporter/pull/378))
Once again there is no functional change.
For library users, the dependency tree shrinks considerably.
See [prometheus/common#255](https://github.com/prometheus/common/issues/255) for more details.
## 0.20.2 / 2021-05-03
* [BUGFIX] Remove copyleft licensed dependency ([#375](https://github.com/prometheus/statsd_exporter/pull/375))
There is no functional change for exporter users.
Removing this dependency reduces uncertainty for anyone reusing the mapping code.
## 0.20.1 / 2021-03-26
* [CHANGE] [library] Split mapper caches out from mapper ([#363](https://github.com/prometheus/statsd_exporter/pull/363))
* [BUGFIX] Accept metric segments that start with numbers ([#365](https://github.com/prometheus/statsd_exporter/pull/365))
## 0.20.0 / 2021-02-05
* [ENHANCEMENT] Support full defaults for summaries and histograms ([#361](https://github.com/prometheus/statsd_exporter/pull/361))
This completes support for `summary_options` and `histogram_options`.
Change the legacy configuration attributes throughout the mapping configuration as follows:
* `quantiles: …` to `summary_options: { quantiles: … }`
* `buckets: …` to `histogram_options: { buckets: … }`
* `timer_type` to `observer_type`.
Support for the deprecated attributes will be removed in a future release.
## 0.19.1 / 2021-01-29
* [BUGFIX] Don't return empty responses to lifecycle api requests ([#360](https://github.com/prometheus/statsd_exporter/pull/360))
## 0.19.0 / 2021-01-22
* [CHANGE] [library] Require explicit Registerer ([#347](https://github.com/prometheus/statsd_exporter/pull/347))
* [ENHANCEMENT] Add /-/healthy and /-/ready endpoints ([#339](https://github.com/prometheus/statsd_exporter/pull/339))
* [BUGFIX] Do not open network ports when only checking config ([#357](https://github.com/prometheus/statsd_exporter/pull/357))
## 0.18.0 / 2020-08-21
* [ENHANCEMENT] Allow turning off tagging extensions ([#325](https://github.com/prometheus/statsd_exporter/pull/325))
* [ENHANCEMENT] Add a lifecycle API for configuration reloads and restarts ([#329](https://github.com/prometheus/statsd_exporter/pull/329))
This release changes the interface for the [`github.com/prometheus/statsd_exporter/pkg/line` library package](https://pkg.go.dev/github.com/prometheus/statsd_exporter@v0.18.0/pkg/line?tab=doc) to support the new configurability.
## 0.17.0 / 2020-06-26
* [CHANGE] Support non-timer distributions without unit conversion ([#314](https://github.com/prometheus/statsd_exporter/pull/314))
* [ENHANCEMENT] Offline configuration check ([#312](https://github.com/prometheus/statsd_exporter/pull/312))
* [ENHANCEMENT] Support the SignalFX tagging extension ([#315](https://github.com/prometheus/statsd_exporter/pull/315))
* [BUGFIX] Allow matching single-letter metric name components ([#309](https://github.com/prometheus/statsd_exporter/pull/309))
Distribution and histogram events (type `d`, `h`) are now treated as distinct from timer events (type `ms`).
Their values are observed as they are, while timer events are converted from milliseconds to seconds.
To reflect this generalization, the `observer_type` mapping option replaces `timer_type`.
Similary, change `match_metric_type: timer` to `match_metric_type: observer`.
The old name remains available for compatibility.
For users of the mapper library, the `ObserverEvent` replaces `TimerEvent`.
For timer metrics, it is emitted by the mapper already converted to seconds.
## 0.16.0 / 2020-05-29
* [CHANGE] Break out much of the exporter into reusable packages ([#298](https://github.com/prometheus/statsd_exporter/pull/298))
* [ENHANCEMENT] Log ingested lines at debug level ([#305](https://github.com/prometheus/statsd_exporter/pull/305))
This release mainly consists of an internal reorganization of the exporter.
This should not have any impact on users of the binary, if it does, please file
an issue.
For users of the existing library packages, nothing changes.
There are now multiple new packages available, exposing functionality that had
been locked away in the main package. Consider the interfaces of these
libraries preliminary; we will change them as we gain experience in how they
are used.
## 0.15.0 / 2020-03-05
* [ENHANCEMENT] Allow setting granularity for summary metrics ([#290](https://github.com/prometheus/statsd_exporter/pull/290))
* [ENHANCEMENT] Support a random-replacement cache invalidation strategy ([#281](https://github.com/prometheus/statsd_exporter/pull/281)
To facilitate the expanded settings for summaries, the configuration format changes from
```yaml
mappings:
- match: …
timer_type: summary
quantiles:
- quantile: 0.99
error: 0.001
- quantile: 0.95
error: 0.01
```
to
```yaml
mappings:
- match: …
timer_type: summary
summary_options:
quantiles:
- quantile: 0.99
error: 0.001
- quantile: 0.95
error: 0.01
max_summary_age: 30s
summary_age_buckets: 3
stream_buffer_size: 1000
```
For consistency, the format for histogram buckets also changes from
```yaml
mappings:
- match: …
timer_type: histogram
buckets: [ 0.01, 0.025, 0.05, 0.1 ]
```
to
```yaml
mappings:
- match: …
timer_type: histogram
histogram_options:
buckets: [ 0.01, 0.025, 0.05, 0.1 ]
```
Transitionally, the old format will still work but is *deprecated*. The new
settings are optional.
For users of the [mapper](https://pkg.go.dev/github.com/prometheus/statsd_exporter/pkg/mapper?tab=doc)
as a library, this is a breaking change. To adjust your code, replace
`mapping.Buckets` with `mapping.HistogramOptions.Buckets` and
`mapping.Quantiles` with `mapping.SummaryOptions.Quantiles`.
## 0.14.1 / 2020-01-13
* [BUGFIX] Mapper cache poisoning when name is variable ([#286](https://github.com/prometheus/statsd_exporter/pull/286))
* [BUGFIX] nil pointer dereference in UDP listener ([#287](https://github.com/prometheus/statsd_exporter/pull/287))
Thank you to everyone who reported these, and @bakins for the mapper cache fix!
## 0.14.0 / 2020-01-10
* [CHANGE] Switch logging to go-kit ([#283](https://github.com/prometheus/statsd_exporter/pull/283))
* [CHANGE] Rename existing metric for mapping cache size ([#284](https://github.com/prometheus/statsd_exporter/pull/284))
* [ENHANCEMENT] Add metrics for mapping cache hits ([#280](https://github.com/prometheus/statsd_exporter/pull/280))
Logs are more structured now. The `fatal` log level no longer exists; use `--log.level=error` instead. The valid log formats are `logfmt` and `json`.
The metric `statsd_exporter_cache_length` is now called `statsd_metric_mapper_cache_length`.
## 0.13.0 / 2019-12-06
* [ENHANCEMENT] Support sampling factors for all statsd metric types ([#264](https://github.com/prometheus/statsd_exporter/issues/250))
* [ENHANCEMENT] Support Librato and InfluxDB labeling formats ([#267](https://github.com/prometheus/statsd_exporter/pull/267))
## 0.12.2 / 2019-07-25
* [BUGFIX] Fix Unix socket handler ([#252](https://github.com/prometheus/statsd_exporter/pull/252))
* [BUGFIX] Fix panic under high load ([#253](https://github.com/prometheus/statsd_exporter/pull/253))
Thank you to everyone who reported and helped debug these issues!
## 0.12.1 / 2019-07-08
* [BUGFIX] Renew TTL when a metric receives updates ([#246](https://github.com/prometheus/statsd_exporter/pull/246))
* [CHANGE] Reload on SIGHUP instead of watching the file ([#243](https://github.com/prometheus/statsd_exporter/pull/243))
## 0.11.2 / 2019-06-14
* [BUGFIX] Fix TCP handler ([#235](https://github.com/prometheus/statsd_exporter/pull/235))
## 0.11.1 / 2019-06-14
* [ENHANCEMENT] Batch event processing for improved ingestion performance ([#227](https://github.com/prometheus/statsd_exporter/pull/227))
* [ENHANCEMENT] Switch Prometheus client to promhttp, freeing the standard HTTP metrics ([#233](https://github.com/prometheus/statsd_exporter/pull/233))
With #233, the exporter no longer exports metrics about its own HTTP status. These were not helpful since you could not get them when scraping fails. This allows mapping to metric names like `http_requests_total` that are useful as application metrics.
## 0.10.6 / 2019-06-07
* [BUGFIX] Fix mapping collision for metrics with different types, but the same name ([#229](https://github.com/prometheus/statsd_exporter/pull/229))
## 0.10.5 / 2019-05-27
* [BUGFIX] Fix "Error: inconsistent label cardinality: expected 0 label values but got N in prometheus.Labels" ([#224](https://github.com/prometheus/statsd_exporter/pull/224))
## 0.10.4 / 2019-05-20
* [BUGFIX] Revert #218 due to a race condition ([#221](https://github.com/prometheus/statsd_exporter/pull/221))
## 0.10.3 / 2019-05-17
* [ENHANCEMENT] Reduce allocations when escaping metric names ([#217](https://github.com/prometheus/statsd_exporter/pull/217))
* [ENHANCEMENT] Reduce allocations when handling packets ([#218](https://github.com/prometheus/statsd_exporter/pull/218))
* [ENHANCEMENT] Optimize label sorting ([#219](https://github.com/prometheus/statsd_exporter/pull/219))
This release is entirely powered by @claytono. Kudos!
## 0.10.2 / 2019-05-17
* [CHANGE] Do not run as root in the Docker container by default ([#202](https://github.com/prometheus/statsd_exporter/pull/202))
* [FEATURE] Add metric for count of events by action ([#193](https://github.com/prometheus/statsd_exporter/pull/193))
* [FEATURE] Add metric for count of distinct metric names ([#200](https://github.com/prometheus/statsd_exporter/pull/200))
* [FEATURE] Add UNIX socket listener support ([#199](https://github.com/prometheus/statsd_exporter/pull/199))
* [FEATURE] Accept Datadog [distributions](https://docs.datadoghq.com/graphing/metrics/distributions/) ([#211](https://github.com/prometheus/statsd_exporter/pull/211))
* [ENHANCEMENT] Add a health check to the Docker container ([#182](https://github.com/prometheus/statsd_exporter/pull/182))
* [ENHANCEMENT] Allow inconsistent label sets ([#194](https://github.com/prometheus/statsd_exporter/pull/194))
* [ENHANCEMENT] Speed up sanitization of metric names ([#197](https://github.com/prometheus/statsd_exporter/pull/197))
* [ENHANCEMENT] Enable pprof endpoints ([#205](https://github.com/prometheus/statsd_exporter/pull/205))
* [ENHANCEMENT] DogStatsD tag parsing is faster ([#210](https://github.com/prometheus/statsd_exporter/pull/210))
* [ENHANCEMENT] Cache mapped metrics ([#198](https://github.com/prometheus/statsd_exporter/pull/198))
* [BUGFIX] Fix panic if a mapping resulted in an empty name ([#192](https://github.com/prometheus/statsd_exporter/pull/192))
* [BUGFIX] Ensure that there are always default quantiles if using summaries ([#212](https://github.com/prometheus/statsd_exporter/pull/212))
* [BUGFIX] Prevent ingesting conflicting metric types that would make scraping fail ([#213](https://github.com/prometheus/statsd_exporter/pull/213))
With #192, the count of events rejected because of negative counter increments has moved into the `statsd_exporter_events_error_total` metric, instead of being lumped in with the different kinds of successful events.
## 0.9.0 / 2019-03-11
* [ENHANCEMENT] Update the Prometheus client library to 0.9.2 ([#171](https://github.com/prometheus/statsd_exporter/pull/171))
* [FEATURE] Metrics can now be expired with a per-mapping TTL ([#164](https://github.com/prometheus/statsd_exporter/pull/164))
* [CHANGE] Timers that mapped to a summary are scaled to seconds, just like histograms ([#178](https://github.com/prometheus/statsd_exporter/pull/178))
If you are using summaries, all your quantiles and `_total` will change by a factor of 1000.
Adjust your queries and dashboards, or consider switching to histograms altogether.
## 0.8.1 / 2018-12-05
* [BUGFIX] Expose the counter for unmapped matches ([#161](https://github.com/prometheus/statsd_exporter/pull/161))
* [BUGFIX] Unsuccessful backtracking does not clobber captures ([#169](https://github.com/prometheus/statsd_exporter/pull/169), fixes [#168](https://github.com/prometheus/statsd_exporter/issues/168))
## 0.8.0 / 2018-10-12
* [ENHANCEMENT] Speed up glob matching ([#157](https://github.com/prometheus/statsd_exporter/pull/157))
This release replaces the implementation of the glob matching mechanism,
speeding it up significantly. In certain sub-optimal configurations, a warning
is logged.
This major enhancement was contributed by [Wangchong Zhou](https://github.com/fffonion).
## 0.7.0 / 2018-08-22
This is a breaking release, but the migration is easy: command line flags now
require two dashes (`--help` instead of `-help`). The previous flag library
already accepts this form, so if necessary you can migrate the flags first
before upgrading.
The deprecated `--statsd.listen-address` flag has been removed, use
`--statsd.listen-udp` instead.
* [CHANGE] Switch to Kingpin for flags, fixes setting log level ([#141](https://github.com/prometheus/statsd_exporter/pull/141))
* [ENHANCEMENT] Allow matching on specific metric types ([#136](https://github.com/prometheus/statsd_exporter/pulls/136))
* [ENHANCEMENT] Summary quantiles can be configured ([#135](https://github.com/prometheus/statsd_exporter/pulls/135))
* [BUGFIX] Fix panic if an invalid regular expression is supplied ([#126](https://github.com/prometheus/statsd_exporter/pulls/126))
## 0.6.0 / 2018-01-17
* [ENHANCEMENT] Add a drop action ([#115](https://github.com/prometheus/statsd_exporter/pulls/115))
* [ENHANCEMENT] Allow templating metric names ([#117](https://github.com/prometheus/statsd_exporter/pulls/117))
## 0.5.0 / 2017-11-16
NOTE: This release breaks backward compatibility. `statsd_exporter` now uses
a YAML configuration file. You must convert your mappings configuration to
the new format when you upgrade. For example, the configuration
```
test.dispatcher.*.*.*
name="dispatcher_events_total"
processor="$1"
action="$2"
outcome="$3"
job="test_dispatcher"
*.signup.*.*
name="signup_events_total"
provider="$2"
outcome="$3"
job="${1}_server"
```
now has the format
```yaml
mappings:
- match: test.dispatcher.*.*.*
help: "The total number of events handled by the dispatcher."
name: "dispatcher_events_total"
labels:
processor: "$1"
action: "$2"
outcome: "$3"
job: "test_dispatcher"
- match: *.signup.*.*
name: "signup_events_total"
help: "The total number of signup events."
labels:
provider: "$2"
outcome: "$3"
job: "${1}_server"
```
The help field is optional.
There is a [tool](https://github.com/bakins/statsd-exporter-convert) available to help with this conversion.
* [CHANGE] Replace the overloaded "packets" metric ([#106](https://github.com/prometheus/statsd_exporter/pulls/106))
* [CHANGE] Removed `-statsd.add-suffix` option flag [#99](https://github.com/prometheus/statsd_exporter/pulls/99). Users should remove
this flag when upgrading. Metrics will no longer automatically include the
suffixes `_timer` or `counter`. You may need to adjust any graphs that used
metrics with these suffixes.
* [CHANGE] Reduce log levels [#92](https://github.com/prometheus/statsd_exporter/pulls/92). Many log events have been changed from error
to debug log level.
* [CHANGE] Use YAML for configuration file [#66](https://github.com/prometheus/statsd_exporter/pulls/66). See note above about file format
conversion.
* [ENHANCEMENT] Allow help text to be customized [#87](https://github.com/prometheus/statsd_exporter/pulls/87)
* [ENHANCEMENT] Add support for regex mappers [#85](https://github.com/prometheus/statsd_exporter/pulls/85)
* [ENHANCEMENT] Add TCP listener support [#71](https://github.com/prometheus/statsd_exporter/pulls/71)
* [ENHANCEMENT] Allow histograms for timer metrics [#66](https://github.com/prometheus/statsd_exporter/pulls/66)
* [ENHANCEMENT] Added support for sampling factor on timing events [#28](https://github.com/prometheus/statsd_exporter/pulls/28)
* [BUGFIX] Conflicting label sets no longer crash the exporter and will be
ignored. Restart to clear the remembered label set. [#72](https://github.com/prometheus/statsd_exporter/pulls/72)
## 0.4.0 / 2017-05-12
* [ENHANCEMENT] Improve mapping configuration parser [#61](https://github.com/prometheus/statsd_exporter/pulls/61)
* [ENHANCEMENT] Add increment/decrement support to Gauges [#65](https://github.com/prometheus/statsd_exporter/pulls/65)
* [BUGFIX] Tolerate more forms of broken lines from StatsD [#48](https://github.com/prometheus/statsd_exporter/pulls/48)
* [BUGFIX] Skip metrics with invalid utf8 [#50](https://github.com/prometheus/statsd_exporter/pulls/50)
* [BUGFIX] ListenAndServe now fails on exit [#58](https://github.com/prometheus/statsd_exporter/pulls/58)
## 0.3.0 / 2016-05-05
* [CHANGE] Drop `_count` suffix for `loaded_mappings` metric ([#41](https://github.com/prometheus/statsd_exporter/pulls/41))
* [ENHANCEMENT] Use common's log and version packages, and add -version flag ([#44](https://github.com/prometheus/statsd_exporter/pulls/44))
* [ENHANCEMENT] Add flag to disable metric type suffixes ([#37](https://github.com/prometheus/statsd_exporter/pulls/37))
* [BUGFIX] Increase receivable UDP datagram size to 65535 bytes ([#36](https://github.com/prometheus/statsd_exporter/pulls/36))
* [BUGFIX] Warn, not panic when negative number counter is submitted ([#33](https://github.com/prometheus/statsd_exporter/pulls/33))
## 0.2.0 / 2016-03-19
NOTE: This release renames `statsd_bridge` to `statsd_exporter`
* [CHANGE] New Dockerfile using alpine-golang-make-onbuild base image ([#17](https://github.com/prometheus/statsd_exporter/pulls/17))
* [ENHANCEMENT] Allow configuration of UDP read buffer ([#22](https://github.com/prometheus/statsd_exporter/pulls/22))
* [BUGFIX] allow metrics with dashes when mapping ([#24](https://github.com/prometheus/statsd_exporter/pulls/24))
* [ENHANCEMENT] add root endpoint with redirect ([#25](https://github.com/prometheus/statsd_exporter/pulls/25))
* [CHANGE] rename bridge to exporter ([#26](https://github.com/prometheus/statsd_exporter/pulls/26))
## 0.1.0 / 2015-04-17
* Initial release

3
CODE_OF_CONDUCT.md Normal file
View file

@ -0,0 +1,3 @@
# Prometheus Community Code of Conduct
Prometheus follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md).

View file

@ -2,9 +2,9 @@
Prometheus uses GitHub to manage reviews of pull requests.
* If you have a trivial fix or improvement, go ahead and create a pull
request, addressing (with `@...`) one or more of the maintainers
(see [AUTHORS.md](AUTHORS.md)) in the description of the pull request.
* If you have a trivial fix or improvement, go ahead and create a pull request,
addressing (with `@...`) the maintainer of this repository (see
[MAINTAINERS.md](MAINTAINERS.md)) in the description of the pull request.
* If you plan to do something more involved, first discuss your ideas
on our [mailing list](https://groups.google.com/forum/?fromgroups#!forum/prometheus-developers).
@ -16,3 +16,5 @@ Prometheus uses GitHub to manage reviews of pull requests.
and the _Formatting and style_ section of Peter Bourgon's [Go: Best
Practices for Production
Environments](http://peter.bourgon.org/go-in-production/#formatting-and-style).
* [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/prometheus/statsd_exporter)

13
Dockerfile Normal file
View file

@ -0,0 +1,13 @@
ARG ARCH="amd64"
ARG OS="linux"
FROM quay.io/prometheus/busybox-${OS}-${ARCH}:latest
LABEL maintainer="The Prometheus Authors <prometheus-developers@googlegroups.com>"
ARG ARCH="amd64"
ARG OS="linux"
COPY .build/${OS}-${ARCH}/statsd_exporter /bin/statsd_exporter
USER 65534
EXPOSE 9102 9125 9125/udp
HEALTHCHECK CMD wget --spider -S "http://localhost:9102/metrics" -T 60 2>&1 || exit 1
ENTRYPOINT [ "/bin/statsd_exporter" ]

1
MAINTAINERS.md Normal file
View file

@ -0,0 +1 @@
* Matthias Rampke <matthias@prometheus.io>

View file

@ -11,7 +11,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
VERSION := 0.1.0
TARGET := statsd_bridge
# Needs to be defined before including Makefile.common to auto-generate targets
DOCKER_ARCHS ?= amd64 armv7 arm64
include Makefile.COMMON
include Makefile.common
STATICCHECK_IGNORE =
DOCKER_IMAGE_NAME ?= statsd-exporter
.PHONY: bench
bench:
@echo ">> running all benchmarks"
$(GO) test -bench . -race $(pkgs)
all: bench

View file

@ -1,118 +0,0 @@
# Copyright 2015 The Prometheus 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.
# THE AUTHORITATIVE VERSION OF THIS MAKEFILE LIVES IN:
#
# https://github.com/prometheus/utils
#
# PLEASE MAKE ANY CHANGES THERE AND PROPAGATE THEM TO ALL PROMETHEUS
# REPOSITORIES THAT ARE USING THIS MAKEFILE.
#
# This file provides common Makefile infrastructure for several Prometheus
# components. This includes make tasks for downloading Go, setting up a
# self-contained build environment, fetching Go dependencies, building
# binaries, running tests, and doing release management. This file is intended
# to be included from a project's Makefile, which needs to define the following
# variables, at a minimum:
#
# * VERSION - The current version of the project in question.
# * TARGET - The desired name of the built binary.
#
# Many of the variables defined below are defined conditionally (using '?'),
# which allows the project's main Makefile to override any of these settings, if
# needed. See also:
#
# https://www.gnu.org/software/make/manual/html_node/Flavors.html#Flavors.
#
# The including Makefile may define any number of extra targets that are
# specific to that project.
VERSION ?= $(error VERSION not set in including Makefile)
TARGET ?= $(error TARGET not set in including Makefile)
SRC ?= $(shell find . -type f -name "*.go" ! -path "./.build/*")
GOOS ?= $(shell uname | tr A-Z a-z)
GOARCH ?= $(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m)))
ifeq ($(GOOS),darwin)
RELEASE_SUFFIX ?= -osx$(shell sw_vers -productVersion)
endif
GO_VERSION ?= 1.4.2
ifeq ($(shell type go >/dev/null && go version | sed 's/.*go\([0-9.]*\).*/\1/'), $(GO_VERSION))
GOROOT := $(shell go env GOROOT)
else
GOROOT := $(CURDIR)/.build/go$(GO_VERSION)
endif
GOURL ?= https://golang.org/dl
GOPKG ?= go$(GO_VERSION).$(GOOS)-$(GOARCH)$(RELEASE_SUFFIX).tar.gz
GOPATH := $(CURDIR)/.build/gopath
GOCC ?= $(GOROOT)/bin/go
GO ?= GOROOT=$(GOROOT) GOPATH=$(GOPATH) $(GOCC)
GOFMT ?= $(GOROOT)/bin/gofmt
# Never honor GOBIN, should it be set at all.
unexport GOBIN
SUFFIX ?= $(GOOS)-$(GOARCH)
BINARY ?= $(TARGET)
ARCHIVE ?= $(TARGET)-$(VERSION).$(SUFFIX).tar.gz
ROOTPKG ?= github.com/prometheus/$(TARGET)
SELFLINK ?= $(GOPATH)/src/$(ROOTPKG)
default: $(BINARY)
$(GOCC):
@echo Go version $(GO_VERSION) required but not found in PATH.
@echo About to download and install go$(GO_VERSION) to $(GOROOT)
@echo Abort now if you want to manually install it system-wide instead.
@echo
@sleep 5
mkdir -p $(GOROOT)
curl -L $(GOURL)/$(GOPKG) | tar -C $(GOROOT) --strip 1 -xz
$(SELFLINK):
mkdir -p $(dir $@)
ln -s $(CURDIR) $@
dependencies-stamp: $(GOCC) $(SRC) | $(SELFLINK)
$(GO) get -d
touch $@
$(BINARY): $(GOCC) $(SRC) dependencies-stamp Makefile Makefile.COMMON
$(GO) build $(GOFLAGS) -o $@
.PHONY: archive
archive: $(ARCHIVE)
$(ARCHIVE): $(BINARY)
tar -czf $@ $<
.PHONY: tag
tag:
git tag $(VERSION)
git push --tags
.PHONY: test
test: $(GOCC) dependencies-stamp
$(GO) test ./...
.PHONY: format
format: $(GOCC)
find . -iname '*.go' | egrep -v "^\./\.build|./generated|\./Godeps|\.(l|y)\.go" | xargs -n1 $(GOFMT) -w -s=true
.PHONY: clean
clean:
rm -rf $(BINARY) $(ARCHIVE) .build *-stamp

277
Makefile.common Normal file
View file

@ -0,0 +1,277 @@
# Copyright 2018 The Prometheus 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.
# A common Makefile that includes rules to be reused in different prometheus projects.
# !!! Open PRs only against the prometheus/prometheus/Makefile.common repository!
# Example usage :
# Create the main Makefile in the root project directory.
# include Makefile.common
# customTarget:
# @echo ">> Running customTarget"
#
# Ensure GOBIN is not set during build so that promu is installed to the correct path
unexport GOBIN
GO ?= go
GOFMT ?= $(GO)fmt
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
GOOPTS ?=
GOHOSTOS ?= $(shell $(GO) env GOHOSTOS)
GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH)
GO_VERSION ?= $(shell $(GO) version)
GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
PRE_GO_111 ?= $(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(10|[0-9])\.')
PROMU := $(FIRST_GOPATH)/bin/promu
pkgs = ./...
ifeq (arm, $(GOHOSTARCH))
GOHOSTARM ?= $(shell GOARM= $(GO) env GOARM)
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)v$(GOHOSTARM)
else
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)
endif
GOTEST := $(GO) test
GOTEST_DIR :=
ifneq ($(CIRCLE_JOB),)
ifneq ($(shell command -v gotestsum 2> /dev/null),)
GOTEST_DIR := test-results
GOTEST := gotestsum --junitfile $(GOTEST_DIR)/unit-tests.xml --
endif
endif
PROMU_VERSION ?= 0.15.0
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
SKIP_GOLANGCI_LINT :=
GOLANGCI_LINT :=
GOLANGCI_LINT_OPTS ?=
GOLANGCI_LINT_VERSION ?= v1.56.2
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
# windows isn't included here because of the path separator being different.
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386 arm64))
# If we're in CI and there is an Actions file, that means the linter
# is being run in Actions, so we don't need to run it here.
ifneq (,$(SKIP_GOLANGCI_LINT))
GOLANGCI_LINT :=
else ifeq (,$(CIRCLE_JOB))
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
else ifeq (,$(wildcard .github/workflows/golangci-lint.yml))
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
endif
endif
endif
PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
DOCKERFILE_PATH ?= ./Dockerfile
DOCKERBUILD_CONTEXT ?= ./
DOCKER_REPO ?= prom
DOCKER_ARCHS ?= amd64
BUILD_DOCKER_ARCHS = $(addprefix common-docker-,$(DOCKER_ARCHS))
PUBLISH_DOCKER_ARCHS = $(addprefix common-docker-publish-,$(DOCKER_ARCHS))
TAG_DOCKER_ARCHS = $(addprefix common-docker-tag-latest-,$(DOCKER_ARCHS))
SANITIZED_DOCKER_IMAGE_TAG := $(subst +,-,$(DOCKER_IMAGE_TAG))
ifeq ($(GOHOSTARCH),amd64)
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux freebsd darwin windows))
# Only supported on amd64
test-flags := -race
endif
endif
# This rule is used to forward a target like "build" to "common-build". This
# allows a new "build" target to be defined in a Makefile which includes this
# one and override "common-build" without override warnings.
%: common-% ;
.PHONY: common-all
common-all: precheck style check_license lint yamllint unused build test
.PHONY: common-style
common-style:
@echo ">> checking code style"
@fmtRes=$$($(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print)); \
if [ -n "$${fmtRes}" ]; then \
echo "gofmt checking failed!"; echo "$${fmtRes}"; echo; \
echo "Please ensure you are using $$($(GO) version) for formatting code."; \
exit 1; \
fi
.PHONY: common-check_license
common-check_license:
@echo ">> checking license header"
@licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
done); \
if [ -n "$${licRes}" ]; then \
echo "license header checking failed:"; echo "$${licRes}"; \
exit 1; \
fi
.PHONY: common-deps
common-deps:
@echo ">> getting dependencies"
$(GO) mod download
.PHONY: update-go-deps
update-go-deps:
@echo ">> updating Go dependencies"
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
$(GO) get -d $$m; \
done
$(GO) mod tidy
.PHONY: common-test-short
common-test-short: $(GOTEST_DIR)
@echo ">> running short tests"
$(GOTEST) -short $(GOOPTS) $(pkgs)
.PHONY: common-test
common-test: $(GOTEST_DIR)
@echo ">> running all tests"
$(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
$(GOTEST_DIR):
@mkdir -p $@
.PHONY: common-format
common-format:
@echo ">> formatting code"
$(GO) fmt $(pkgs)
.PHONY: common-vet
common-vet:
@echo ">> vetting code"
$(GO) vet $(GOOPTS) $(pkgs)
.PHONY: common-lint
common-lint: $(GOLANGCI_LINT)
ifdef GOLANGCI_LINT
@echo ">> running golangci-lint"
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
endif
.PHONY: common-lint-fix
common-lint-fix: $(GOLANGCI_LINT)
ifdef GOLANGCI_LINT
@echo ">> running golangci-lint fix"
$(GOLANGCI_LINT) run --fix $(GOLANGCI_LINT_OPTS) $(pkgs)
endif
.PHONY: common-yamllint
common-yamllint:
@echo ">> running yamllint on all YAML files in the repository"
ifeq (, $(shell command -v yamllint 2> /dev/null))
@echo "yamllint not installed so skipping"
else
yamllint .
endif
# For backward-compatibility.
.PHONY: common-staticcheck
common-staticcheck: lint
.PHONY: common-unused
common-unused:
@echo ">> running check for unused/missing packages in go.mod"
$(GO) mod tidy
@git diff --exit-code -- go.sum go.mod
.PHONY: common-build
common-build: promu
@echo ">> building binaries"
$(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
.PHONY: common-tarball
common-tarball: promu
@echo ">> building release tarball"
$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
.PHONY: common-docker-repo-name
common-docker-repo-name:
@echo "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)"
.PHONY: common-docker $(BUILD_DOCKER_ARCHS)
common-docker: $(BUILD_DOCKER_ARCHS)
$(BUILD_DOCKER_ARCHS): common-docker-%:
docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" \
-f $(DOCKERFILE_PATH) \
--build-arg ARCH="$*" \
--build-arg OS="linux" \
$(DOCKERBUILD_CONTEXT)
.PHONY: common-docker-publish $(PUBLISH_DOCKER_ARCHS)
common-docker-publish: $(PUBLISH_DOCKER_ARCHS)
$(PUBLISH_DOCKER_ARCHS): common-docker-publish-%:
docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)"
DOCKER_MAJOR_VERSION_TAG = $(firstword $(subst ., ,$(shell cat VERSION)))
.PHONY: common-docker-tag-latest $(TAG_DOCKER_ARCHS)
common-docker-tag-latest: $(TAG_DOCKER_ARCHS)
$(TAG_DOCKER_ARCHS): common-docker-tag-latest-%:
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:latest"
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:v$(DOCKER_MAJOR_VERSION_TAG)"
.PHONY: common-docker-manifest
common-docker-manifest:
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create -a "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)" $(foreach ARCH,$(DOCKER_ARCHS),$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$(ARCH):$(SANITIZED_DOCKER_IMAGE_TAG))
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)"
.PHONY: promu
promu: $(PROMU)
$(PROMU):
$(eval PROMU_TMP := $(shell mktemp -d))
curl -s -L $(PROMU_URL) | tar -xvzf - -C $(PROMU_TMP)
mkdir -p $(FIRST_GOPATH)/bin
cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
rm -r $(PROMU_TMP)
.PHONY: proto
proto:
@echo ">> generating code from proto files"
@./scripts/genproto.sh
ifdef GOLANGCI_LINT
$(GOLANGCI_LINT):
mkdir -p $(FIRST_GOPATH)/bin
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/$(GOLANGCI_LINT_VERSION)/install.sh \
| sed -e '/install -d/d' \
| sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)
endif
.PHONY: precheck
precheck::
define PRECHECK_COMMAND_template =
precheck:: $(1)_precheck
PRECHECK_COMMAND_$(1) ?= $(1) $$(strip $$(PRECHECK_OPTIONS_$(1)))
.PHONY: $(1)_precheck
$(1)_precheck:
@if ! $$(PRECHECK_COMMAND_$(1)) 1>/dev/null 2>&1; then \
echo "Execution of '$$(PRECHECK_COMMAND_$(1))' command failed. Is $(1) installed?"; \
exit 1; \
fi
endef

2
NOTICE
View file

@ -1,4 +1,4 @@
StatsD-to-Prometheus bridge
StatsD-to-Prometheus exporter
Copyright 2013-2015 The Prometheus Authors
This product includes software developed at

594
README.md
View file

@ -1,28 +1,123 @@
StatsD-Bridge
=============
# statsd exporter [![Build Status](https://travis-ci.org/prometheus/statsd_exporter.svg)][travis]
StatsD-Bridge receives StatsD-style metrics and exports them as Prometheus metrics.
[![CircleCI](https://circleci.com/gh/prometheus/statsd_exporter/tree/master.svg?style=shield)][circleci]
[![Docker Repository on Quay](https://quay.io/repository/prometheus/statsd-exporter/status)][quay]
[![Docker Pulls](https://img.shields.io/docker/pulls/prom/statsd-exporter.svg)][hub]
`statsd_exporter` receives StatsD-style metrics and exports them as Prometheus metrics.
## Overview
To pipe metrics from an existing StatsD environment into Prometheus, configure
StatsD's repeater backend to repeat all received packets to a StatsD-Bridge
process. This bridge translates StatsD metrics to Prometheus metrics via
configured mapping rules.
The StatsD exporter is a drop-in replacement for StatsD.
This exporter translates StatsD metrics to Prometheus metrics via configured mapping rules.
+----------+ +-----------------+ +--------------+
| StatsD |---(UDP repeater)--->| StatsD-Bridge |<---(scrape /metrics)---| Prometheus |
+----------+ +-----------------+ +--------------+
We recommend using the exporter only as an intermediate solution, and switching to [native Prometheus instrumentation](http://prometheus.io/docs/instrumenting/clientlibs/) in the long term.
While it is common to run centralized StatsD servers, the exporter works best as a [sidecar](https://docs.microsoft.com/en-us/azure/architecture/patterns/sidecar).
### Transitioning from an existing StatsD setup
The relay feature allows for a gradual transition.
Introduce the exporter by adding it as a sidecar alongside the application instances.
In Kubernetes, this means adding it to the [pod](https://kubernetes.io/docs/concepts/workloads/pods/).
Use the `--statsd.relay.address` to forward metrics to your existing StatsD UDP endpoint.
Relaying forwards statsd events unmodified, preserving the original metric name and tags in any format.
+-------------+ +----------+ +------------+
| Application +--->| Exporter +----------------->| StatsD |
+-------------+ +----------+ +------------+
^
| +------------+
+----------------------+ Prometheus |
+------------+
### Relaying from StatsD
To pipe metrics from an existing StatsD environment into Prometheus, configure StatsD's repeater backend to repeat all received metrics to a `statsd_exporter` process.
+----------+ +-------------------+ +--------------+
| StatsD |---(UDP/TCP repeater)--->| statsd_exporter |<---(scrape /metrics)---| Prometheus |
+----------+ +-------------------+ +--------------+
This allows trying out the exporter with minimal effort, but does not provide the per-instance metrics of the sidecar pattern.
### Tagging Extensions
The exporter supports Librato, InfluxDB, DogStatsD, and SignalFX-style tags,
which will be converted into Prometheus labels.
For Librato-style tags, they must be appended to the metric name with a
delimiting `#`, as so:
```
metric.name#tagName=val,tag2Name=val2:0|c
```
See the [statsd-librato-backend README](https://github.com/librato/statsd-librato-backend#tags)
for a more complete description.
For InfluxDB-style tags, they must be appended to the metric name with a
delimiting comma, as so:
```
metric.name,tagName=val,tag2Name=val2:0|c
```
See [this InfluxDB blog post](https://www.influxdata.com/blog/getting-started-with-sending-statsd-metrics-to-telegraf-influxdb/#introducing-influx-statsd)
for a larger overview.
For DogStatsD-style tags, they're appended as a `|#` delimited section at the
end of the metric, as so:
```
metric.name:0|c|#tagName:val,tag2Name:val2
```
See [Tags](https://docs.datadoghq.com/developers/dogstatsd/data_types/#tagging)
in the DogStatsD documentation for the concept description and
[Datagram Format](https://docs.datadoghq.com/developers/dogstatsd/datagram_shell/).
If you encounter problems, note that this tagging style is incompatible with
the original `statsd` implementation.
For [SignalFX dimension](https://github.com/signalfx/signalfx-agent/blob/main/docs/monitors/collectd-statsd.md#adding-dimensions-to-statsd-metrics), add the tags to the metric name in square brackets, as so:
```
metric.name[tagName=val,tag2Name=val2]:0|c
```
Be aware: If you mix tag styles (e.g., Librato/InfluxDB with DogStatsD), the exporter will consider this an error and the behavior is undefined.
Also, tags without values (`#some_tag`) are not supported and will be ignored.
The exporter parses all tagging formats by default, but individual tagging formats can be disabled with command line flags:
```
--no-statsd.parse-dogstatsd-tags
--no-statsd.parse-influxdb-tags
--no-statsd.parse-librato-tags
--no-statsd.parse-signalfx-tags
```
By default, labels explicitly specified in configuration take precedence over labels from tags.
To set the label from the statsd event tag, use [`honor_labels`](#honor-labels).
## Building and Running
$ go build
$ ./statsd_bridge --help
Usage of ./statsd_bridge:
-statsd.listen-address=":9125": The UDP address on which to receive statsd metric lines.
-statsd.mapping-config="": Metric mapping configuration file name.
-web.listen-address=":9102": The address on which to expose the web interface and generated Prometheus metrics.
-web.telemetry-path="/metrics": Path under which to expose metrics.
NOTE: Version 0.7.0 switched to the [kingpin](https://github.com/alecthomas/kingpin) flags library. With this change, flag behaviour is POSIX-ish:
* long flags start with two dashes (`--version`)
* boolean long flags are disabled by prefixing with no (`--flag-name` is true, `--no-flag-name` is false)
* multiple short flags can be combined (but there currently is only one)
* flag processing stops at the first `--`
* see `--help` for a full list of flags
## Lifecycle API
The `statsd_exporter` has an optional lifecycle API (disabled by default) that can be used to reload or quit the exporter
by sending a `PUT` or `POST` request to the `/-/reload` or `/-/quit` endpoints.
## Relay
The `statsd_exporter` has an optional mode that will buffer and relay incoming statsd lines to a remote server. This is useful to "tee" the data when migrating to using the exporter. The relay will flush the buffer at least once per second to avoid delaying delivery of metrics.
## Tests
@ -30,9 +125,11 @@ configured mapping rules.
## Metric Mapping and Configuration
The StatsD-Bridge can be configured to translate specific dot-separated StatsD
metrics into labeled Prometheus metrics via a simple mapping language. A
mapping definition starts with a line matching the StatsD metric in question,
The `statsd_exporter` can be configured to translate specific dot-separated StatsD
metrics into labeled Prometheus metrics via a simple mapping language. The config
file is reloaded on SIGHUP.
A mapping definition starts with a line matching the StatsD metric in question,
with `*`s acting as wildcards for each dot-separated metric component. The
lines following the matching expression must contain one `label="value"` pair
each, and at least define the metric name (label name `name`). The Prometheus
@ -42,43 +139,436 @@ starting at 1. Multiple matching definitions are separated by one or more empty
lines. The first mapping rule that matches a StatsD metric wins.
Metrics that don't match any mapping in the configuration file are translated
into Prometheus metrics without any labels and with certain characters escaped
(`_` -> `__`; `-` -> `__`; `.` -> `_`).
into Prometheus metrics without any labels and with any non-alphanumeric
characters, including periods, translated into underscores.
In general, the different metric types are translated as follows, with certain
suffixes appended to the Prometheus metric names:
In general, the different metric types are translated as follows:
StatsD gauge -> Prometheus gauge (suffix `_gauge`)
StatsD counter -> Prometheus counter (suffix `_counter`)
StatsD timer -> Prometheus summary (suffix `_timer`) <-- indicates timer quantiles
-> Prometheus counter (suffix `_timer_total`) <-- indicates total time spent
-> Prometheus counter (suffix `_timer_count`) <-- indicates total number of timer events
StatsD gauge -> Prometheus gauge
StatsD counter -> Prometheus counter
StatsD timer, histogram, distribution -> Prometheus summary or histogram
### Glob matching
The default (and fastest) `glob` mapping style uses `*` to denote parts of the statsd metric name that may vary.
These varying parts can then be referenced in the construction of the Prometheus metric name and labels.
An example mapping configuration:
test.dispatcher.*.*.*
name="dispatcher_events"
processor="$1"
action="$2"
outcome="$3"
job="test_dispatcher"
*.signup.*.*
name="signup_events"
provider="$2"
outcome="$3"
job="${1}_server"
```yaml
mappings:
- match: "test.dispatcher.*.*.*"
name: "dispatcher_events_total"
labels:
processor: "$1"
action: "$2"
outcome: "$3"
job: "test_dispatcher"
- match: "*.signup.*.*"
name: "signup_events_total"
labels:
provider: "$2"
outcome: "$3"
job: "${1}_server"
```
This would transform these example StatsD metrics into Prometheus metrics as
follows:
test.dispatcher.FooProcessor.send.success (counter)
=> dispatcher_events_counter{processor="FooProcessor", action="send", outcome="success", job="test_dispatcher"}
foo_product.signup.facebook.failure (counter)
=> signup_events_counter{provider="facebook", outcome="failure", job="foo_product_server"}
test.web-server.foo.bar (gauge)
=> test_web__server_foo_bar_gauge{}
test.dispatcher.FooProcessor.send.success
=> dispatcher_events_total{processor="FooProcessor", action="send", outcome="success", job="test_dispatcher"}
foo_product.signup.facebook.failure
=> signup_events_total{provider="facebook", outcome="failure", job="foo_product_server"}
test.web-server.foo.bar
=> test_web_server_foo_bar{}
Each mapping in the configuration file must define a `name` for the metric. The
metric's name can contain `$n`-style references to be replaced by the n-th
wildcard match in the matching line. That allows for dynamic rewrites, such as:
```yaml
mappings:
- match: "test.*.*.counter"
name: "${2}_total"
labels:
provider: "$1"
```
Glob matching offers the best performance for common mappings.
#### Ordering glob rules
List more specific matches before wildcards, from left to right:
a.b.c
a.b.*
a.*.d
a.*.*
This avoids unexpected shadowing of later rules, and performance impact from backtracking.
Alternatively, you can disable mapping ordering altogether.
With unordered mapping, at each hierarchy level the most specific match wins.
This has the same effect as using the recommended ordering.
### Regular expression matching
The `regex` mapping style uses regular expressions to match the full statsd metric name.
Use it if the glob mapping is not flexible enough to pull structured data from the available statsd metric names.
Regular expression matching is significantly slower than glob mapping as all mappings must be tested in order.
Because of this, **regex mappings are only executed after all glob mappings**.
In other words, glob mappings take preference over regex matches, irrespective of the order in which they are specified.
Regular expression matches are always evaluated in order, and the first match wins.
The metric name can also contain references to regex matches. The mapping above
could be written as:
```yaml
mappings:
- match: "test\\.(\\w+)\\.(\\w+)\\.counter"
match_type: regex
name: "${2}_total"
labels:
provider: "$1"
- match: "(.*)\\.(.*)--(.*)\\.status\.(.*)\\.count"
match_type: regex
name: "request_total"
labels:
hostname: "$1"
exec: "$2"
protocol: "$3"
code: "$4"
```
Be aware about yaml escape rules as a mapping like the following one will not work.
```yaml
mappings:
- match: "test\\.(\w+)\\.(\w+)\\.counter"
match_type: regex
name: "${2}_total"
labels:
provider: "$1"
```
#### Special match groups
When using regex, the match group `0` is the full match and can be used to attach labels to the metric.
Example:
```yaml
mappings:
- match: ".+"
match_type: regex
name: "$0"
labels:
statsd_metric_name: "$0"
```
If a metric `my.statsd_counter` is received, the metric name will **still** be mapped to `my_statsd_counter` (Prometheus compatible name).
But the metric will also have the label `statsd_metric_name` with the value `my.statsd_counter` (unchanged value).
Note: If you use the `match` like the example (i.e. `.+`), be aware that it will be a "catch-all" block. So it should come at the very end of the mapping list.
The same is not achievable with glob matching, for more details check [this issue](https://github.com/prometheus/statsd_exporter/issues/444).
### Naming, labels, and help
Please note that metrics with the same name must also have the same set of
label names.
If the default metric help text is insufficient for your needs you may use the YAML
configuration to specify a custom help text for each mapping:
```yaml
mappings:
- match: "http.request.*"
help: "Total number of http requests"
name: "http_requests_total"
labels:
code: "$1"
```
### Honor labels
By default, labels specified in the mapping configuration take precedence over tags in the statsd event.
To set the label value to the original tag value, if present, specify `honor_labels: true` in the mapping configuration.
In this case, the label specified in the mapping acts as a default.
### StatsD timers and distributions
By default, statsd timers and distributions (collectively "observers") are
represented as a Prometheus summary with quantiles. You may optionally
configure the [quantiles and acceptable
error](https://prometheus.io/docs/practices/histograms/#quantiles), as well
as adjusting how the summary metric is aggregated:
```yaml
mappings:
- match: "test.timing.*.*.*"
observer_type: summary
name: "my_timer"
labels:
provider: "$2"
outcome: "$3"
job: "${1}_server"
summary_options:
quantiles:
- quantile: 0.99
error: 0.001
- quantile: 0.95
error: 0.01
- quantile: 0.9
error: 0.05
- quantile: 0.5
error: 0.005
max_age: 30s
age_buckets: 3
buf_cap: 1000
```
The default quantiles are 0.99, 0.9, and 0.5.
The default summary age is 10 minutes, the default number of buckets
is 5 and the default buffer size is 500.
See also the [`golang_client` docs](https://godoc.org/github.com/prometheus/client_golang/prometheus#SummaryOpts).
The `max_summary_age` corresponds to `SummaryOptions.MaxAge`, `summary_age_buckets` to `SummaryOptions.AgeBuckets` and `stream_buffer_size` to `SummaryOptions.BufCap`.
In the configuration, one may also set the observer type to "histogram". For example,
to set the observer type for a single timer metric:
```yaml
mappings:
- match: "test.timing.*.*.*"
observer_type: histogram
histogram_options:
buckets: [ 0.01, 0.025, 0.05, 0.1 ]
native_histogram_bucket_factor: 1.1
native_histogram_max_buckets: 256
name: "my_timer"
labels:
provider: "$2"
outcome: "$3"
job: "${1}_server"
```
If not set, then the default
[Prometheus client
values](https://godoc.org/github.com/prometheus/client_golang/prometheus#pkg-variables)
are used for the histogram buckets:
`[.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10]`.
`+Inf` is added automatically.
If your Prometheus server is enabled to scrape native histograms (v2.40.0+),
then you can set the `native_histogram_bucket_factor` to configure precision of the
buckets in the sparse histogram. More about this in the original [client_golang docs](https://github.com/prometheus/client_golang/blob/449b46435075e6e069e05af920fe028b941033cf/prometheus/histogram.go#L399-L430).
Also, a configuration of the maximum number of buckets can be set with `native_histogram_max_buckets`, this
avoids the histograms to grow too large in memory. More about this in the original [client_golang docs](https://github.com/prometheus/client_golang/blob/449b46435075e6e069e05af920fe028b941033cf/prometheus/histogram.go#L443-L467).
`observer_type` is only used when the statsd metric type is a timer, histogram, or distribution.
`buckets` is only used when the statsd metric type is one of these, and the `observer_type` is set to `histogram`.
Timers will be accepted with the `ms` statsd type.
Statsd timer data is transmitted in milliseconds, while Prometheus expects the unit to be seconds.
The exporter converts all timer observations to seconds.
Histogram and distribution events (`h` and `d` metric type) are not subject to unit conversion.
### DogStatsD Client Behavior
#### `timed()` decorator
The DogStatsD client's [timed](https://datadogpy.readthedocs.io/en/latest/#datadog.threadstats.base.ThreadStats.timed) decorator emits the metric in seconds but uses the `ms` type.
Set [`use_ms=True`](https://datadogpy.readthedocs.io/en/latest/index.html?highlight=use_ms) to send the correct units.
### Regular expression matching
Another capability when using YAML configuration is the ability to define matches
using raw regular expressions as opposed to the default globbing style of match.
This may allow for pulling structured data from otherwise poorly named statsd
metrics AND allow for more precise targetting of match rules. When no `match_type`
parameter is specified the default value of `glob` will be assumed:
```yaml
mappings:
- match: "(.*)\\.(.*)--(.*)\\.status\\.(.*)\\.count"
match_type: regex
name: "request_total"
labels:
hostname: "$1"
exec: "$2"
protocol: "$3"
code: "$4"
```
### Global defaults
One may also set defaults for the observer type, histogram options, summary options, and match type.
These will be used by all mappings that do not define them.
An option that can only be configured in `defaults` is `glob_disable_ordering`, which is `false` if omitted.
By setting this to `true`, `glob` match type will not honor the occurance of rules in the mapping rules file and always treat `*` as lower priority than a concrete string.
Setting `buckets` or `quantiles` in the defaults is deprecated in favor of `histogram_options` and `summary_options`, which will override the deprecated values.
If `summary_options` is present in a mapping config, it will only override the fields set in the mapping. Unset fields in the mapping will take the values from the defaults.
```yaml
defaults:
observer_type: histogram
histogram_options:
buckets: [.005, .01, .025, .05, .1, .25, .5, 1, 2.5 ]
native_histogram_bucket_factor: 1.1
native_histogram_max_buckets: 256
summary_options:
quantiles:
- quantile: 0.99
error: 0.001
- quantile: 0.95
error: 0.01
- quantile: 0.9
error: 0.05
- quantile: 0.5
error: 0.005
max_age: 5m
age_buckets: 2
buf_cap: 1000
match_type: glob
glob_disable_ordering: false
ttl: 0 # metrics do not expire
mappings:
# This will be a histogram using the buckets set in `defaults`.
- match: "test.timing.*.*.*"
name: "my_timer"
labels:
provider: "$2"
outcome: "$3"
job: "${1}_server"
# This will be a summary using the summary_options set in `defaults`
- match: "other.distribution.*.*.*"
observer_type: summary
name: "other_distribution"
labels:
provider: "$2"
outcome: "$3"
job: "${1}_server_other"
```
### `drop` action
You may also drop metrics by specifying a "drop" action on a match. For
example:
```yaml
mappings:
# This metric would match as normal.
- match: "test.timing.*.*.*"
name: "my_timer"
labels:
provider: "$2"
outcome: "$3"
job: "${1}_server"
# Any metric not matched will be dropped because "." matches all metrics.
- match: "."
match_type: regex
action: drop
name: "dropped"
```
You can drop any metric using the normal match syntax.
The default action is "map" which does the normal metrics mapping.
### Explicit metric type mapping
StatsD allows emitting of different metric types under the same metric name,
but the Prometheus client library can't merge those. For this use-case the
mapping definition allows you to specify which metric type to match:
```
mappings:
- match: "test.foo.*"
name: "test_foo"
match_metric_type: counter
labels:
provider: "$1"
```
Possible values for `match_metric_type` are `gauge`, `counter` and `observer`.
### Mapping cache size and cache replacement policy
There is a cache used to improve the performance of the metric mapping, that can greatly improvement performance.
The cache has a default maximum of 1000 unique statsd metric names -> prometheus metrics mappings that it can store.
This maximum can be adjusted using the `statsd.cache-size` flag.
If the maximum is reached, entries are by default rotated using the [least recently used replacement policy](https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)). This strategy is optimal when memory is constrained as only the most recent entries are retained.
Alternatively, you can choose a [random-replacement cache strategy](https://en.wikipedia.org/wiki/Cache_replacement_policies#Random_replacement_(RR)). This is less optimal if the cache is smaller than the cacheable set, but requires less locking. Use this for very high throughput, but make sure to allow for a cache that holds all metrics.
The optimal cache size is determined by the cardinality of the _incoming_ metrics.
### Time series expiration
The `ttl` parameter can be used to define the expiration time for stale metrics.
The value is a time duration with valid time units: "ns", "us" (or "µs"),
"ms", "s", "m", "h". For example, `ttl: 1m20s`. `0` value is used to indicate
metrics that do not expire.
TTL configuration is stored for each mapped metric name/labels combination
whenever new samples are received. This means that you cannot immediately
expire a metric only by changing the mapping configuration. At least one
sample must be received for updated mappings to take effect.
### Unit conversions
The `scale` parameter can be used to define unit conversions for metric values. The value is a floating point number to scale metric values by. This can be useful for converting non-base units (e.g. milliseconds, kilobytes) to base units (e.g. seconds, bytes) as recommended in [prometheus best practices](https://prometheus.io/docs/practices/naming/).
```yaml
mappings:
- match: foo.latency_ms
name: foo_latency_seconds
scale: 0.001
- match: bar.processed_kb
name: bar_processed_bytes
scale: 1024
- match: baz.latency_us
name: baz_latency_seconds
scale: 1e-6
```
### Event flushing configuration
Internally `statsd_exporter` runs a goroutine for each network listener (UDP, TCP & Unix Socket). These each receive and parse metrics received into an event. For performance purposes, these events are queued internally and flushed to the main exporter goroutine periodically in batches. The size of this queue and the flush criteria can be tuned with the `--statsd.event-queue-size`, `--statsd.event-flush-threshold` and `--statsd.event-flush-interval`. However, the defaults should perform well even for very high traffic environments.
## Using Docker
You can deploy this exporter using the [prom/statsd-exporter](https://registry.hub.docker.com/r/prom/statsd-exporter) Docker image.
For example:
```bash
docker pull prom/statsd-exporter
docker run -d -p 9102:9102 -p 9125:9125 -p 9125:9125/udp \
-v $PWD/statsd_mapping.yml:/tmp/statsd_mapping.yml \
prom/statsd-exporter --statsd.mapping-config=/tmp/statsd_mapping.yml
```
## Library packages
Parts of the implementation of this exporter are available as separate packages.
See the [documentation](https://pkg.go.dev/github.com/prometheus/statsd_exporter/pkg) for details.
For the time being, there are *no stability guarantees* for library interfaces.
We will try to call out any significant changes in the [changelog](https://github.com/prometheus/statsd_exporter/blob/master/CHANGELOG.md).
Semantic versioning of the exporter is based on the impact on users of the exporter, not users of the library.
We encourage re-use of these packages and welcome [issues](https://github.com/prometheus/statsd_exporter/issues?q=is%3Aopen+is%3Aissue+label%3Alibrary) related to their usability as a library.
[circleci]: https://circleci.com/gh/prometheus/statsd_exporter
[quay]: https://quay.io/repository/prometheus/statsd-exporter
[hub]: https://hub.docker.com/r/prom/statsd-exporter/

6
SECURITY.md Normal file
View file

@ -0,0 +1,6 @@
# Reporting a security issue
The Prometheus security policy, including how to report vulnerabilities, can be
found here:
<https://prometheus.io/docs/operating/security/>

1
VERSION Normal file
View file

@ -0,0 +1 @@
0.26.1

364
bridge.go
View file

@ -1,364 +0,0 @@
// Copyright 2013 The Prometheus 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 (
"bytes"
"encoding/binary"
"fmt"
"hash/fnv"
"log"
"net"
"regexp"
"strconv"
"strings"
"github.com/prometheus/client_golang/model"
"github.com/prometheus/client_golang/prometheus"
)
const (
defaultHelp = "Metric autogenerated by statsd_bridge."
regErrF = "A change of configuration created inconsistent metrics for " +
"%q. You have to restart the statsd_bridge, and you should " +
"consider the effects on your monitoring setup. Error: %s"
)
var (
illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)
hash = fnv.New64a()
strBuf bytes.Buffer // Used for hashing.
intBuf = make([]byte, 8)
)
// hashNameAndLabels returns a hash value of the provided name string and all
// the label names and values in the provided labels map.
//
// Not safe for concurrent use! (Uses a shared buffer and hasher to save on
// allocations.)
func hashNameAndLabels(name string, labels prometheus.Labels) uint64 {
hash.Reset()
strBuf.Reset()
strBuf.WriteString(name)
hash.Write(strBuf.Bytes())
binary.BigEndian.PutUint64(intBuf, model.LabelsToSignature(labels))
hash.Write(intBuf)
return hash.Sum64()
}
type CounterContainer struct {
Elements map[uint64]prometheus.Counter
}
func NewCounterContainer() *CounterContainer {
return &CounterContainer{
Elements: make(map[uint64]prometheus.Counter),
}
}
func (c *CounterContainer) Get(metricName string, labels prometheus.Labels) prometheus.Counter {
hash := hashNameAndLabels(metricName, labels)
counter, ok := c.Elements[hash]
if !ok {
counter = prometheus.NewCounter(prometheus.CounterOpts{
Name: metricName,
Help: defaultHelp,
ConstLabels: labels,
})
c.Elements[hash] = counter
if err := prometheus.Register(counter); err != nil {
log.Fatalf(regErrF, metricName, err)
}
}
return counter
}
type GaugeContainer struct {
Elements map[uint64]prometheus.Gauge
}
func NewGaugeContainer() *GaugeContainer {
return &GaugeContainer{
Elements: make(map[uint64]prometheus.Gauge),
}
}
func (c *GaugeContainer) Get(metricName string, labels prometheus.Labels) prometheus.Gauge {
hash := hashNameAndLabels(metricName, labels)
gauge, ok := c.Elements[hash]
if !ok {
gauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: metricName,
Help: defaultHelp,
ConstLabels: labels,
})
c.Elements[hash] = gauge
if err := prometheus.Register(gauge); err != nil {
log.Fatalf(regErrF, metricName, err)
}
}
return gauge
}
type SummaryContainer struct {
Elements map[uint64]prometheus.Summary
}
func NewSummaryContainer() *SummaryContainer {
return &SummaryContainer{
Elements: make(map[uint64]prometheus.Summary),
}
}
func (c *SummaryContainer) Get(metricName string, labels prometheus.Labels) prometheus.Summary {
hash := hashNameAndLabels(metricName, labels)
summary, ok := c.Elements[hash]
if !ok {
summary = prometheus.NewSummary(
prometheus.SummaryOpts{
Name: metricName,
Help: defaultHelp,
ConstLabels: labels,
})
c.Elements[hash] = summary
if err := prometheus.Register(summary); err != nil {
log.Fatalf(regErrF, metricName, err)
}
}
return summary
}
type Event interface {
MetricName() string
Value() float64
}
type CounterEvent struct {
metricName string
value float64
}
func (c *CounterEvent) MetricName() string { return c.metricName }
func (c *CounterEvent) Value() float64 { return c.value }
type GaugeEvent struct {
metricName string
value float64
}
func (g *GaugeEvent) MetricName() string { return g.metricName }
func (g *GaugeEvent) Value() float64 { return g.value }
type TimerEvent struct {
metricName string
value float64
}
func (t *TimerEvent) MetricName() string { return t.metricName }
func (t *TimerEvent) Value() float64 { return t.value }
type Events []Event
type Bridge struct {
Counters *CounterContainer
Gauges *GaugeContainer
Summaries *SummaryContainer
mapper *metricMapper
}
func escapeMetricName(metricName string) string {
// If a metric starts with a digit, prepend an underscore.
if metricName[0] >= '0' && metricName[0] <= '9' {
metricName = "_" + metricName
}
// Replace all illegal metric chars with underscores.
metricName = illegalCharsRE.ReplaceAllString(metricName, "_")
return metricName
}
func (b *Bridge) Listen(e <-chan Events) {
for {
events := <-e
for _, event := range events {
metricName := ""
prometheusLabels := prometheus.Labels{}
labels, present := b.mapper.getMapping(event.MetricName())
if present {
metricName = labels["name"]
for label, value := range labels {
if label != "name" {
prometheusLabels[label] = value
}
}
} else {
metricName = escapeMetricName(event.MetricName())
}
switch event.(type) {
case *CounterEvent:
counter := b.Counters.Get(
metricName+"_counter",
prometheusLabels,
)
counter.Add(event.Value())
eventStats.WithLabelValues("counter").Inc()
case *GaugeEvent:
gauge := b.Gauges.Get(
metricName+"_gauge",
prometheusLabels,
)
gauge.Set(event.Value())
eventStats.WithLabelValues("gauge").Inc()
case *TimerEvent:
summary := b.Summaries.Get(
metricName+"_timer",
prometheusLabels,
)
summary.Observe(event.Value())
eventStats.WithLabelValues("timer").Inc()
default:
log.Println("Unsupported event type")
eventStats.WithLabelValues("illegal").Inc()
}
}
}
}
func NewBridge(mapper *metricMapper) *Bridge {
return &Bridge{
Counters: NewCounterContainer(),
Gauges: NewGaugeContainer(),
Summaries: NewSummaryContainer(),
mapper: mapper,
}
}
type StatsDListener struct {
conn *net.UDPConn
}
func buildEvent(statType, metric string, value float64) (Event, error) {
switch statType {
case "c":
return &CounterEvent{
metricName: metric,
value: float64(value),
}, nil
case "g":
return &GaugeEvent{
metricName: metric,
value: float64(value),
}, nil
case "ms":
return &TimerEvent{
metricName: metric,
value: float64(value),
}, nil
case "s":
return nil, fmt.Errorf("No support for StatsD sets")
default:
return nil, fmt.Errorf("Bad stat type %s", statType)
}
}
func (l *StatsDListener) Listen(e chan<- Events) {
// TODO: evaluate proper size according to MTU
var buf [512]byte
for {
n, _, err := l.conn.ReadFromUDP(buf[0:])
if err != nil {
log.Fatal(err)
}
l.handlePacket(buf[0:n], e)
}
}
func (l *StatsDListener) handlePacket(packet []byte, e chan<- Events) {
lines := strings.Split(string(packet), "\n")
events := Events{}
for _, line := range lines {
if line == "" {
continue
}
elements := strings.Split(line, ":")
if len(elements) < 2 {
networkStats.WithLabelValues("malformed_line").Inc()
log.Println("Bad line from StatsD:", line)
continue
}
metric := elements[0]
samples := elements[1:]
for _, sample := range samples {
components := strings.Split(sample, "|")
samplingFactor := 1.0
if len(components) < 2 || len(components) > 3 {
networkStats.WithLabelValues("malformed_component").Inc()
log.Println("Bad component on line:", line)
continue
}
valueStr, statType := components[0], components[1]
value, err := strconv.ParseFloat(valueStr, 64)
if err != nil {
log.Printf("Bad value %s on line: %s", valueStr, line)
networkStats.WithLabelValues("malformed_value").Inc()
continue
}
if len(components) == 3 {
if statType != "c" {
log.Println("Illegal sampling factor for non-counter metric on line", line)
networkStats.WithLabelValues("illegal_sample_factor").Inc()
}
samplingStr := components[2]
if samplingStr[0] != '@' {
log.Printf("Invalid sampling factor %s on line %s", samplingStr, line)
networkStats.WithLabelValues("invalid_sample_factor").Inc()
continue
}
samplingFactor, err = strconv.ParseFloat(samplingStr[1:], 64)
if err != nil {
log.Printf("Invalid sampling factor %s on line %s", samplingStr, line)
networkStats.WithLabelValues("invalid_sample_factor").Inc()
continue
}
if samplingFactor == 0 {
// This should never happen, but avoid division by zero if it does.
log.Printf("Invalid zero sampling factor %s on line %s, setting to 1", samplingStr, line)
samplingFactor = 1
}
value /= samplingFactor
}
event, err := buildEvent(statType, metric, value)
if err != nil {
log.Printf("Error building event on line %s: %s", line, err)
networkStats.WithLabelValues("illegal_event").Inc()
continue
}
events = append(events, event)
networkStats.WithLabelValues("legal").Inc()
}
}
e <- events
}

View file

@ -15,73 +15,486 @@ package main
import (
"fmt"
"net"
"reflect"
"testing"
"time"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/statsd_exporter/pkg/clock"
"github.com/prometheus/statsd_exporter/pkg/event"
"github.com/prometheus/statsd_exporter/pkg/exporter"
"github.com/prometheus/statsd_exporter/pkg/line"
"github.com/prometheus/statsd_exporter/pkg/listener"
"github.com/prometheus/statsd_exporter/pkg/mapper"
)
func TestHandlePacket(t *testing.T) {
scenarios := []struct {
name string
in string
out Events
out event.Events
}{
{
name: "empty",
}, {
name: "simple counter",
in: "foo:2|c",
out: Events{
&CounterEvent{
metricName: "foo",
value: 2,
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 2,
CLabels: map[string]string{},
},
},
}, {
name: "simple gauge",
in: "foo:3|g",
out: Events{
&GaugeEvent{
metricName: "foo",
value: 3,
out: event.Events{
&event.GaugeEvent{
GMetricName: "foo",
GValue: 3,
GLabels: map[string]string{},
},
},
}, {
name: "gauge with sampling",
in: "foo:3|g|@0.2",
out: event.Events{
&event.GaugeEvent{
GMetricName: "foo",
GValue: 3,
GLabels: map[string]string{},
},
},
}, {
name: "gauge decrement",
in: "foo:-10|g",
out: event.Events{
&event.GaugeEvent{
GMetricName: "foo",
GValue: -10,
GRelative: true,
GLabels: map[string]string{},
},
},
}, {
name: "gauge increment",
in: "foo:+10|g",
out: event.Events{
&event.GaugeEvent{
GMetricName: "foo",
GValue: 10,
GRelative: true,
GLabels: map[string]string{},
},
},
}, {
name: "gauge set negative",
in: "foo:0|g\nfoo:-1|g",
out: event.Events{
&event.GaugeEvent{
GMetricName: "foo",
GValue: 0,
GRelative: false,
GLabels: map[string]string{},
},
&event.GaugeEvent{
GMetricName: "foo",
GValue: -1,
GRelative: true,
GLabels: map[string]string{},
},
},
}, {
// Test the sequence given here https://github.com/statsd/statsd/blob/master/docs/metric_types.md#gauges
name: "gauge up and down",
in: "gaugor:333|g\ngaugor:-10|g\ngaugor:+4|g",
out: event.Events{
&event.GaugeEvent{
GMetricName: "gaugor",
GValue: 333,
GRelative: false,
GLabels: map[string]string{},
},
&event.GaugeEvent{
GMetricName: "gaugor",
GValue: -10,
GRelative: true,
GLabels: map[string]string{},
},
&event.GaugeEvent{
GMetricName: "gaugor",
GValue: 4,
GRelative: true,
GLabels: map[string]string{},
},
},
}, {
name: "simple timer",
in: "foo:200|ms",
out: Events{
&TimerEvent{
metricName: "foo",
value: 200,
out: event.Events{
&event.ObserverEvent{
OMetricName: "foo",
OValue: 0.2,
OLabels: map[string]string{},
},
},
}, {
name: "simple histogram",
in: "foo:200|h",
out: event.Events{
&event.ObserverEvent{
OMetricName: "foo",
OValue: 200,
OLabels: map[string]string{},
},
},
}, {
name: "simple distribution",
in: "foo:200|d",
out: event.Events{
&event.ObserverEvent{
OMetricName: "foo",
OValue: 200,
OLabels: map[string]string{},
},
},
}, {
name: "distribution with sampling",
in: "foo:0.01|d|@0.2|#tag1:bar,#tag2:baz",
out: event.Events{
&event.ObserverEvent{
OMetricName: "foo",
OValue: 0.01,
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
&event.ObserverEvent{
OMetricName: "foo",
OValue: 0.01,
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
&event.ObserverEvent{
OMetricName: "foo",
OValue: 0.01,
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
&event.ObserverEvent{
OMetricName: "foo",
OValue: 0.01,
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
&event.ObserverEvent{
OMetricName: "foo",
OValue: 0.01,
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
},
}, {
name: "librato tag extension",
in: "foo#tag1=bar,tag2=baz:100|c",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 100,
CLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
},
}, {
name: "librato tag extension with tag keys unsupported by prometheus",
in: "foo#09digits=0,tag.with.dots=1:100|c",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 100,
CLabels: map[string]string{"_09digits": "0", "tag_with_dots": "1"},
},
},
}, {
name: "influxdb tag extension",
in: "foo,tag1=bar,tag2=baz:100|c",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 100,
CLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
},
}, {
name: "SignalFx tag extension",
in: "foo.[tag1=bar,tag2=baz]test:100|c",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo.test",
CValue: 100,
CLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
},
}, {
name: "SignalFx tag extension, tags at end of name",
in: "foo.test[tag1=bar,tag2=baz]:100|c",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo.test",
CValue: 100,
CLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
},
}, {
name: "SignalFx tag extension, tags at beginning of name",
in: "[tag1=bar,tag2=baz]foo.test:100|c",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo.test",
CValue: 100,
CLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
},
}, {
name: "SignalFx tag extension, no tags",
in: "foo.[]test:100|c",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo.test",
CValue: 100,
CLabels: map[string]string{},
},
},
}, {
name: "SignalFx tag extension, non-kv tags",
in: "foo.[tag1,tag2]test:100|c",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo.test",
CValue: 100,
CLabels: map[string]string{},
},
},
}, {
name: "SignalFx tag extension, missing closing bracket",
in: "[tag1=bar,tag2=bazfoo.test:100|c",
out: event.Events{
&event.CounterEvent{
CMetricName: "[tag1=bar,tag2=bazfoo.test",
CValue: 100,
CLabels: map[string]string{},
},
},
}, {
name: "SignalFx tag extension, missing opening bracket",
in: "tag1=bar,tag2=baz]foo.test:100|c",
out: event.Events{
&event.CounterEvent{
CMetricName: "tag1=bar,tag2=baz]foo.test",
CValue: 100,
CLabels: map[string]string{},
},
},
}, {
name: "influxdb tag extension with tag keys unsupported by prometheus",
in: "foo,09digits=0,tag.with.dots=1:100|c",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 100,
CLabels: map[string]string{"_09digits": "0", "tag_with_dots": "1"},
},
},
}, {
name: "datadog tag extension",
in: "foo:100|c|#tag1:bar,tag2:baz",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 100,
CLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
},
}, {
name: "datadog tag extension with # in all keys (as sent by datadog php client)",
in: "foo:100|c|#tag1:bar,#tag2:baz",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 100,
CLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
},
}, {
name: "datadog tag extension with tag keys unsupported by prometheus",
in: "foo:100|c|#09digits:0,tag.with.dots:1",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 100,
CLabels: map[string]string{"_09digits": "0", "tag_with_dots": "1"},
},
},
}, {
name: "datadog tag extension with valueless tags: ignored",
in: "foo:100|c|#tag_without_a_value",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 100,
CLabels: map[string]string{},
},
},
}, {
name: "datadog tag extension with valueless tags (edge case)",
in: "foo:100|c|#tag_without_a_value,tag:value",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 100,
CLabels: map[string]string{"tag": "value"},
},
},
}, {
name: "datadog tag extension with empty tags (edge case)",
in: "foo:100|c|#tag:value,,",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 100,
CLabels: map[string]string{"tag": "value"},
},
},
}, {
name: "datadog tag extension with sampling",
in: "foo:100|c|@0.1|#tag1:bar,#tag2:baz",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 1000,
CLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
},
}, {
name: "librato/dogstatsd mixed tag styles without sampling",
in: "foo#tag1=foo,tag3=bing:100|c|#tag1:bar,#tag2:baz",
out: event.Events{},
}, {
name: "signalfx/dogstatsd mixed tag styles without sampling",
in: "foo[tag1=foo,tag3=bing]:100|c|#tag1:bar,#tag2:baz",
out: event.Events{},
}, {
name: "influxdb/dogstatsd mixed tag styles without sampling",
in: "foo,tag1=foo,tag3=bing:100|c|#tag1:bar,#tag2:baz",
out: event.Events{},
}, {
name: "mixed tag styles with sampling",
in: "foo#tag1=foo,tag3=bing:100|c|@0.1|#tag1:bar,#tag2:baz",
out: event.Events{},
}, {
name: "histogram with sampling",
in: "foo:0.01|h|@0.2|#tag1:bar,#tag2:baz",
out: event.Events{
&event.ObserverEvent{
OMetricName: "foo",
OValue: 0.01,
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
&event.ObserverEvent{
OMetricName: "foo",
OValue: 0.01,
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
&event.ObserverEvent{
OMetricName: "foo",
OValue: 0.01,
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
&event.ObserverEvent{
OMetricName: "foo",
OValue: 0.01,
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
&event.ObserverEvent{
OMetricName: "foo",
OValue: 0.01,
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
},
}, {
name: "datadog tag extension with multiple colons",
in: "foo:100|c|@0.1|#tag1:foo:bar",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 1000,
CLabels: map[string]string{"tag1": "foo:bar"},
},
},
}, {
name: "datadog tag extension with invalid utf8 tag values",
in: "foo:100|c|@0.1|#tag:\xc3\x28invalid",
}, {
name: "datadog tag extension with both valid and invalid utf8 tag values",
in: "foo:100|c|@0.1|#tag1:valid,tag2:\xc3\x28invalid",
}, {
name: "multiple metrics with invalid datadog utf8 tag values",
in: "foo:200|c|#tag:value\nfoo:300|c|#tag:\xc3\x28invalid",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 200,
CLabels: map[string]string{"tag": "value"},
},
},
}, {
name: "combined multiline metrics",
in: "foo:200|ms:300|ms:5|c|@0.1:6|g\nbar:1|c:5|ms",
out: Events{
&TimerEvent{
metricName: "foo",
value: 200,
out: event.Events{
&event.ObserverEvent{
OMetricName: "foo",
OValue: .200,
OLabels: map[string]string{},
},
&TimerEvent{
metricName: "foo",
value: 300,
&event.ObserverEvent{
OMetricName: "foo",
OValue: .300,
OLabels: map[string]string{},
},
&CounterEvent{
metricName: "foo",
value: 50,
&event.CounterEvent{
CMetricName: "foo",
CValue: 50,
CLabels: map[string]string{},
},
&GaugeEvent{
metricName: "foo",
value: 6,
&event.GaugeEvent{
GMetricName: "foo",
GValue: 6,
GLabels: map[string]string{},
},
&CounterEvent{
metricName: "bar",
value: 1,
&event.CounterEvent{
CMetricName: "bar",
CValue: 1,
CLabels: map[string]string{},
},
&TimerEvent{
metricName: "bar",
value: 5,
&event.ObserverEvent{
OMetricName: "bar",
OValue: .005,
OLabels: map[string]string{},
},
},
}, {
name: "timings with sampling factor",
in: "foo.timing:0.5|ms|@0.1",
out: event.Events{
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
},
}, {
name: "bad line",
in: "foo",
@ -94,40 +507,359 @@ func TestHandlePacket(t *testing.T) {
}, {
name: "illegal sampling factor",
in: "foo:1|c|@bar",
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 1,
CLabels: map[string]string{},
},
},
}, {
name: "zero sampling factor",
in: "foo:2|c|@0",
out: Events{
&CounterEvent{
metricName: "foo",
value: 2,
out: event.Events{
&event.CounterEvent{
CMetricName: "foo",
CValue: 2,
CLabels: map[string]string{},
},
},
}, {
name: "illegal stat type",
in: "foo:2|t",
},
{
name: "empty metric name",
in: ":100|ms",
},
{
name: "empty component",
in: "foo:1|c|",
},
{
name: "invalid utf8",
in: "invalid\xc3\x28utf8:1|c",
},
{
name: "some invalid utf8",
in: "valid_utf8:1|c\ninvalid\xc3\x28utf8:1|c",
out: event.Events{
&event.CounterEvent{
CMetricName: "valid_utf8",
CValue: 1,
CLabels: map[string]string{},
},
},
}, {
name: "ms timer with conversion to seconds",
in: "foo:200|ms",
out: event.Events{
&event.ObserverEvent{
OMetricName: "foo",
OValue: 0.2,
OLabels: map[string]string{},
},
},
}, {
name: "histogram with no unit conversion",
in: "foo:200|h",
out: event.Events{
&event.ObserverEvent{
OMetricName: "foo",
OValue: 200,
OLabels: map[string]string{},
},
},
}, {
name: "distribution with no unit conversion",
in: "foo:200|d",
out: event.Events{
&event.ObserverEvent{
OMetricName: "foo",
OValue: 200,
OLabels: map[string]string{},
},
},
},
}
l := StatsDListener{}
events := make(chan Events, 32)
for i, scenario := range scenarios {
l.handlePacket([]byte(scenario.in), events)
parser := line.NewParser()
parser.EnableDogstatsdParsing()
parser.EnableInfluxdbParsing()
parser.EnableLibratoParsing()
parser.EnableSignalFXParsing()
// Flatten actual events.
actual := Events{}
for i := 0; i < len(events); i++ {
actual = append(actual, <-events...)
}
for k, l := range []statsDPacketHandler{&listener.StatsDUDPListener{
Conn: nil,
EventHandler: nil,
Logger: log.NewNopLogger(),
LineParser: parser,
UDPPackets: udpPackets,
UDPPacketDrops: udpPacketDrops,
LinesReceived: linesReceived,
EventsFlushed: eventsFlushed,
SampleErrors: *sampleErrors,
SamplesReceived: samplesReceived,
TagErrors: tagErrors,
TagsReceived: tagsReceived,
}, &mockStatsDTCPListener{listener.StatsDTCPListener{
Conn: nil,
EventHandler: nil,
Logger: log.NewNopLogger(),
LineParser: parser,
LinesReceived: linesReceived,
EventsFlushed: eventsFlushed,
SampleErrors: *sampleErrors,
SamplesReceived: samplesReceived,
TagErrors: tagErrors,
TagsReceived: tagsReceived,
TCPConnections: tcpConnections,
TCPErrors: tcpErrors,
TCPLineTooLong: tcpLineTooLong,
}, log.NewNopLogger()}} {
events := make(chan event.Events, 32)
l.SetEventHandler(&event.UnbufferedEventHandler{C: events})
for i, scenario := range scenarios {
l.HandlePacket([]byte(scenario.in))
if len(actual) != len(scenario.out) {
t.Fatalf("%d. Expected %d events, got %d", i, len(scenario.out), len(actual))
}
le := len(events)
// Flatten actual events.
actual := event.Events{}
for j := 0; j < le; j++ {
actual = append(actual, <-events...)
}
for j, expected := range scenario.out {
if fmt.Sprintf("%v", actual[j]) != fmt.Sprintf("%v", expected) {
t.Fatalf("%d.%d. Expected %v, got %v", i, j, actual[j], expected)
if len(actual) != len(scenario.out) {
t.Fatalf("%d.%d. Expected %d events, got %d in scenario '%s'", k, i, len(scenario.out), len(actual), scenario.name)
}
for j, expected := range scenario.out {
if !reflect.DeepEqual(&expected, &actual[j]) {
t.Fatalf("%d.%d.%d. Expected %#v, got %#v in scenario '%s'", k, i, j, expected, actual[j], scenario.name)
}
}
}
}
}
type statsDPacketHandler interface {
HandlePacket(packet []byte)
SetEventHandler(eh event.EventHandler)
}
type mockStatsDTCPListener struct {
listener.StatsDTCPListener
log.Logger
}
func (ml *mockStatsDTCPListener) HandlePacket(packet []byte) {
// Forcing IPv4 because the TravisCI build environment does not have IPv6
// addresses.
lc, err := net.ListenTCP("tcp4", nil)
if err != nil {
panic(fmt.Sprintf("mockStatsDTCPListener: listen failed: %v", err))
}
defer lc.Close()
go func() {
cc, err := net.DialTCP("tcp", nil, lc.Addr().(*net.TCPAddr))
if err != nil {
panic(fmt.Sprintf("mockStatsDTCPListener: dial failed: %v", err))
}
defer cc.Close()
n, err := cc.Write(packet)
if err != nil || n != len(packet) {
panic(fmt.Sprintf("mockStatsDTCPListener: write failed: %v,%d", err, n))
}
}()
sc, err := lc.AcceptTCP()
if err != nil {
panic(fmt.Sprintf("mockStatsDTCPListener: accept failed: %v", err))
}
ml.HandleConn(sc)
}
// TestTtlExpiration validates expiration of time series.
// foobar metric without mapping should expire with default ttl of 1s
// bazqux metric should expire with ttl of 2s
func TestTtlExpiration(t *testing.T) {
// Mock a time.NewTicker
tickerCh := make(chan time.Time)
clock.ClockInstance = &clock.Clock{
TickerCh: tickerCh,
}
config := `
defaults:
ttl: 1s
mappings:
- match: bazqux.*
name: bazqux
ttl: 2s
`
// Create mapper from config and start an Exporter with a synchronous channel
testMapper := &mapper.MetricMapper{}
err := testMapper.InitFromYAMLString(config)
if err != nil {
t.Fatalf("Config load error: %s %s", config, err)
}
events := make(chan event.Events)
defer close(events)
go func() {
ex := exporter.NewExporter(prometheus.DefaultRegisterer, testMapper, log.NewNopLogger(), eventsActions, eventsUnmapped, errorEventStats, eventStats, conflictingEventStats, metricsCount)
ex.Listen(events)
}()
ev := event.Events{
// event with default ttl = 1s
&event.GaugeEvent{
GMetricName: "foobar",
GValue: 200,
},
// event with ttl = 2s from a mapping
&event.ObserverEvent{
OMetricName: "bazqux.main",
OValue: 42,
},
}
var metrics []*dto.MetricFamily
var foobarValue *float64
var bazquxValue *float64
// Step 1. Send events with statsd metrics.
// Send empty Events to wait for events are handled.
// saveLabelValues will use fake instant as a lastRegisteredAt time.
clock.ClockInstance.Instant = time.Unix(0, 0)
events <- ev
events <- event.Events{}
// Check values
metrics, err = prometheus.DefaultGatherer.Gather()
if err != nil {
t.Fatal("Gather should not fail")
}
foobarValue = getFloat64(metrics, "foobar", prometheus.Labels{})
bazquxValue = getFloat64(metrics, "bazqux", prometheus.Labels{})
if foobarValue == nil || bazquxValue == nil {
t.Fatalf("Gauge `foobar` and Summary `bazqux` should be gathered")
}
if *foobarValue != 200 {
t.Fatalf("Gauge `foobar` observation %f is not expected. Should be 200", *foobarValue)
}
if *bazquxValue != 42 {
t.Fatalf("Summary `bazqux` observation %f is not expected. Should be 42", *bazquxValue)
}
// Step 2. Increase Instant to emulate metrics expiration after 1s
clock.ClockInstance.Instant = time.Unix(1, 10)
clock.ClockInstance.TickerCh <- time.Unix(0, 0)
events <- event.Events{}
// Check values
metrics, err = prometheus.DefaultGatherer.Gather()
if err != nil {
t.Fatal("Gather should not fail")
}
foobarValue = getFloat64(metrics, "foobar", prometheus.Labels{})
bazquxValue = getFloat64(metrics, "bazqux", prometheus.Labels{})
if foobarValue != nil {
t.Fatalf("Gauge `foobar` should be expired")
}
if bazquxValue == nil {
t.Fatalf("Summary `bazqux` should be gathered")
}
if *bazquxValue != 42 {
t.Fatalf("Summary `bazqux` observation %f is not expected. Should be 42", *bazquxValue)
}
// Step 3. Increase Instant to emulate metrics expiration after 2s
clock.ClockInstance.Instant = time.Unix(2, 200)
clock.ClockInstance.TickerCh <- time.Unix(0, 0)
events <- event.Events{}
// Check values
metrics, err = prometheus.DefaultGatherer.Gather()
if err != nil {
t.Fatal("Gather should not fail")
}
foobarValue = getFloat64(metrics, "foobar", prometheus.Labels{})
bazquxValue = getFloat64(metrics, "bazqux", prometheus.Labels{})
if bazquxValue != nil {
t.Fatalf("Summary `bazqux` should be expired")
}
if foobarValue != nil {
t.Fatalf("Gauge `foobar` should not be gathered after expiration")
}
}
// getFloat64 search for metric by name in array of MetricFamily and then search a value by labels.
// Method returns a value or nil if metric is not found.
func getFloat64(metrics []*dto.MetricFamily, name string, labels prometheus.Labels) *float64 {
var metricFamily *dto.MetricFamily
for _, m := range metrics {
if *m.Name == name {
metricFamily = m
break
}
}
if metricFamily == nil {
return nil
}
var metric *dto.Metric
labelStr := fmt.Sprintf("%v", labels)
for _, m := range metricFamily.Metric {
l := labelPairsAsLabels(m.GetLabel())
ls := fmt.Sprintf("%v", l)
if labelStr == ls {
metric = m
break
}
}
if metric == nil {
return nil
}
var value float64
if metric.Gauge != nil {
value = metric.Gauge.GetValue()
return &value
}
if metric.Counter != nil {
value = metric.Counter.GetValue()
return &value
}
if metric.Histogram != nil {
value = metric.Histogram.GetSampleSum()
return &value
}
if metric.Summary != nil {
value = metric.Summary.GetSampleSum()
return &value
}
if metric.Untyped != nil {
value = metric.Untyped.GetValue()
return &value
}
panic(fmt.Errorf("collected a non-gauge/counter/histogram/summary/untyped metric: %s", metric))
}
func labelPairsAsLabels(pairs []*dto.LabelPair) (labels prometheus.Labels) {
labels = prometheus.Labels{}
for _, pair := range pairs {
if pair.Name == nil {
continue
}
value := ""
if pair.Value != nil {
value = *pair.Value
}
labels[*pair.Name] = value
}
return
}

201
exporter_benchmark_test.go Normal file
View file

@ -0,0 +1,201 @@
// Copyright 2013 The Prometheus 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 (
"fmt"
"testing"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/statsd_exporter/pkg/event"
"github.com/prometheus/statsd_exporter/pkg/exporter"
"github.com/prometheus/statsd_exporter/pkg/line"
"github.com/prometheus/statsd_exporter/pkg/listener"
"github.com/prometheus/statsd_exporter/pkg/mapper"
)
func benchmarkUDPListener(times int, b *testing.B) {
input := []string{
"foo1:2|c",
"foo2:3|g",
"foo3:200|ms",
"foo4:100|c|#tag1:bar,tag2:baz",
"foo5:100|c|#tag1:bar,#tag2:baz",
"foo6:100|c|#09digits:0,tag.with.dots:1",
"foo10:100|c|@0.1|#tag1:bar,#tag2:baz",
"foo11:100|c|@0.1|#tag1:foo:bar",
"foo.[foo=bar,dim=val]test:1|g",
"foo15:200|ms:300|ms:5|c|@0.1:6|g\nfoo15a:1|c:5|ms",
"some_very_useful_metrics_with_quite_a_log_name:13|c",
}
bytesInput := make([]string, len(input)*times)
logger := log.NewNopLogger()
for run := 0; run < times; run++ {
for i := 0; i < len(input); i++ {
bytesInput[run*len(input)+i] = fmt.Sprintf("run%d%s", run, input[i])
}
}
parser := line.NewParser()
parser.EnableDogstatsdParsing()
parser.EnableInfluxdbParsing()
parser.EnableLibratoParsing()
parser.EnableSignalFXParsing()
// reset benchmark timer to not measure startup costs
b.ResetTimer()
for n := 0; n < b.N; n++ {
// pause benchmark timer for creating the chan and listener
b.StopTimer()
// there are more events than input lines, need bigger buffer
events := make(chan event.Events, len(bytesInput)*times*2)
udpChan := make(chan []byte, len(bytesInput)*times*2)
l := listener.StatsDUDPListener{
EventHandler: &event.UnbufferedEventHandler{C: events},
Logger: logger,
LineParser: parser,
UDPPackets: udpPackets,
LinesReceived: linesReceived,
SamplesReceived: samplesReceived,
TagsReceived: tagsReceived,
UdpPacketQueue: udpChan,
}
// resume benchmark timer
b.StartTimer()
for i := 0; i < times; i++ {
for _, line := range bytesInput {
l.HandlePacket([]byte(line))
}
}
}
}
func BenchmarkUDPListener1(b *testing.B) {
benchmarkUDPListener(1, b)
}
func BenchmarkUDPListener5(b *testing.B) {
benchmarkUDPListener(5, b)
}
func BenchmarkUDPListener50(b *testing.B) {
benchmarkUDPListener(50, b)
}
func BenchmarkExporterListener(b *testing.B) {
events := event.Events{
&event.CounterEvent{ // simple counter
CMetricName: "counter",
CValue: 2,
},
&event.GaugeEvent{ // simple gauge
GMetricName: "gauge",
GValue: 10,
},
&event.ObserverEvent{ // simple timer
OMetricName: "timer",
OValue: 200,
},
&event.ObserverEvent{ // simple histogram
OMetricName: "histogram.test",
OValue: 200,
},
&event.CounterEvent{ // simple_tags
CMetricName: "simple_tags",
CValue: 100,
CLabels: map[string]string{
"alpha": "bar",
"bravo": "baz",
},
},
&event.CounterEvent{ // slightly different tags
CMetricName: "simple_tags",
CValue: 100,
CLabels: map[string]string{
"alpha": "bar",
"charlie": "baz",
},
},
&event.CounterEvent{ // and even more different tags
CMetricName: "simple_tags",
CValue: 100,
CLabels: map[string]string{
"alpha": "bar",
"bravo": "baz",
"golf": "looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
},
},
&event.CounterEvent{ // datadog tag extension with complex tags
CMetricName: "foo",
CValue: 100,
CLabels: map[string]string{
"action": "test",
"application": "testapp",
"application_component": "testcomp",
"application_role": "test_role",
"category": "category",
"controller": "controller",
"deployed_to": "production",
"kube_deployment": "deploy",
"kube_namespace": "kube-production",
"method": "get",
"version": "5.2.8374",
"status": "200",
"status_range": "2xx",
},
},
}
config := `
mappings:
- match: histogram.test
timer_type: histogram
name: "histogram_test"
`
testMapper := &mapper.MetricMapper{}
err := testMapper.InitFromYAMLString(config)
if err != nil {
b.Fatalf("Config load error: %s %s", config, err)
}
ex := exporter.NewExporter(prometheus.DefaultRegisterer, testMapper, log.NewNopLogger(), eventsActions, eventsUnmapped, errorEventStats, eventStats, conflictingEventStats, metricsCount)
// reset benchmark timer to not measure startup costs
b.ResetTimer()
for i := 0; i < b.N; i++ {
// pause benchmark timer for creating the chan
b.StopTimer()
ec := make(chan event.Events, 1000)
// resume benchmark timer
b.StartTimer()
go func() {
for i := 0; i < 1000; i++ {
ec <- events
}
close(ec)
}()
ex.Listen(ec)
}
}

36
go.mod Normal file
View file

@ -0,0 +1,36 @@
module github.com/prometheus/statsd_exporter
go 1.20
require (
github.com/alecthomas/kingpin/v2 v2.4.0
github.com/go-kit/log v0.2.1
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
github.com/prometheus/client_golang v1.19.0
github.com/prometheus/client_model v0.6.0
github.com/prometheus/common v0.48.0
github.com/prometheus/exporter-toolkit v0.11.0
github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807
gopkg.in/yaml.v2 v2.4.0
)
require (
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)

82
go.sum Normal file
View file

@ -0,0 +1,82 @@
github.com/alecthomas/kingpin/v2 v2.4.0 h1:f48lwail6p8zpO1bC4TxtqACaGqHYA22qkHjHpqDjYY=
github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU=
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU=
github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k=
github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos=
github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8=
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
github.com/prometheus/exporter-toolkit v0.11.0 h1:yNTsuZ0aNCNFQ3aFTD2uhPOvr4iD7fdBvKPAEGkNf+g=
github.com/prometheus/exporter-toolkit v0.11.0/go.mod h1:BVnENhnNecpwoTLiABx7mrPB/OLRIgN74qlQbV+FK1Q=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807 h1:LUsDduamlucuNnWcaTbXQ6aLILFcLXADpOzeEH3U+OI=
github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc=
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ=
golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

105
line_benchmark_test.go Normal file
View file

@ -0,0 +1,105 @@
// Copyright 2020 The Prometheus 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 (
"testing"
"github.com/go-kit/log"
"github.com/prometheus/statsd_exporter/pkg/line"
)
var (
// just a grab bag of mixed formats, valid, invalid
mixedLines = []string{
"foo1:2|c",
"foo2:3|g",
"foo3:200|ms",
"foo4:100|c|#tag1:bar,tag2:baz",
"foo5:100|c|#tag1:bar,#tag2:baz",
"foo6:100|c|#09digits:0,tag.with.dots:1",
"foo10:100|c|@0.1|#tag1:bar,#tag2:baz",
"foo11:100|c|@0.1|#tag1:foo:bar",
"foo.[foo=bar,dim=val]test:1|g",
"foo15:200|ms:300|ms:5|c|@0.1:6|g\nfoo15a:1|c:5|ms",
"some_very_useful_metrics_with_quite_a_log_name:13|c",
}
nopLogger = log.NewNopLogger()
)
func benchmarkLinesToEvents(times int, b *testing.B, input []string) {
// always report allocations since this is a hot path
b.ReportAllocs()
parser := line.NewParser()
parser.EnableDogstatsdParsing()
parser.EnableInfluxdbParsing()
parser.EnableLibratoParsing()
parser.EnableSignalFXParsing()
// reset benchmark timer to not measure startup costs
b.ResetTimer()
for n := 0; n < b.N; n++ {
for i := 0; i < times; i++ {
for _, l := range input {
parser.LineToEvents(l, *sampleErrors, samplesReceived, tagErrors, tagsReceived, nopLogger)
}
}
}
}
// Mixed statsd formats
func BenchmarkLineToEventsMixed1(b *testing.B) {
benchmarkLinesToEvents(1, b, mixedLines)
}
func BenchmarkLineToEventsMixed5(b *testing.B) {
benchmarkLinesToEvents(5, b, mixedLines)
}
func BenchmarkLineToEventsMixed50(b *testing.B) {
benchmarkLinesToEvents(50, b, mixedLines)
}
func BenchmarkLineFormats(b *testing.B) {
input := map[string]string{
"statsd": "foo1:2|c",
"invalidStatsd": "foo1:2|c||",
"dogStatsd": "foo1:100|c|#tag1:bar,tag2:baz",
"invalidDogStatsd": "foo3:100|c|#09digits:0,tag.with.dots:1",
"signalFx": "foo1.[foo=bar1,dim=val1]test:1|g",
"invalidSignalFx": "foo1.[foo=bar1,dim=val1test:1|g",
"influxDb": "foo1,tag1=bar,tag2=baz:100|c",
"invalidInfluxDb": "foo3,tag1=bar,tag2:100|c",
}
parser := line.NewParser()
parser.EnableDogstatsdParsing()
parser.EnableInfluxdbParsing()
parser.EnableLibratoParsing()
parser.EnableSignalFXParsing()
// reset benchmark timer to not measure startup costs
b.ResetTimer()
for name, l := range input {
b.Run(name, func(b *testing.B) {
// always report allocations since this is a hot path
b.ReportAllocs()
for n := 0; n < b.N; n++ {
parser.LineToEvents(l, *sampleErrors, samplesReceived, tagErrors, tagsReceived, nopLogger)
}
})
}
}

580
main.go
View file

@ -14,115 +14,555 @@
package main
import (
"flag"
"log"
"bufio"
"fmt"
"net"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"strconv"
"syscall"
"github.com/howeyc/fsnotify"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
"github.com/prometheus/common/version"
"github.com/prometheus/exporter-toolkit/web"
"github.com/prometheus/statsd_exporter/pkg/address"
"github.com/prometheus/statsd_exporter/pkg/event"
"github.com/prometheus/statsd_exporter/pkg/exporter"
"github.com/prometheus/statsd_exporter/pkg/level"
"github.com/prometheus/statsd_exporter/pkg/line"
"github.com/prometheus/statsd_exporter/pkg/listener"
"github.com/prometheus/statsd_exporter/pkg/mapper"
"github.com/prometheus/statsd_exporter/pkg/mappercache/lru"
"github.com/prometheus/statsd_exporter/pkg/mappercache/randomreplacement"
"github.com/prometheus/statsd_exporter/pkg/relay"
)
var (
listenAddress = flag.String("web.listen-address", ":9102", "The address on which to expose the web interface and generated Prometheus metrics.")
metricsEndpoint = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
statsdListenAddress = flag.String("statsd.listen-address", ":9125", "The UDP address on which to receive statsd metric lines.")
mappingConfig = flag.String("statsd.mapping-config", "", "Metric mapping configuration file name.")
eventStats = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "statsd_exporter_events_total",
Help: "The total number of StatsD events seen.",
},
[]string{"type"},
)
eventsFlushed = promauto.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_event_queue_flushed_total",
Help: "Number of times events were flushed to exporter",
},
)
eventsUnmapped = promauto.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_events_unmapped_total",
Help: "The total number of StatsD events no mapping was found for.",
})
udpPackets = promauto.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_udp_packets_total",
Help: "The total number of StatsD packets received over UDP.",
},
)
udpPacketDrops = promauto.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_udp_packet_drops_total",
Help: "The total number of dropped StatsD packets which received over UDP.",
},
)
tcpConnections = promauto.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_tcp_connections_total",
Help: "The total number of TCP connections handled.",
},
)
tcpErrors = promauto.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_tcp_connection_errors_total",
Help: "The number of errors encountered reading from TCP.",
},
)
tcpLineTooLong = promauto.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_tcp_too_long_lines_total",
Help: "The number of lines discarded due to being too long.",
},
)
unixgramPackets = promauto.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_unixgram_packets_total",
Help: "The total number of StatsD packets received over Unixgram.",
},
)
linesReceived = promauto.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_lines_total",
Help: "The total number of StatsD lines received.",
},
)
samplesReceived = promauto.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_samples_total",
Help: "The total number of StatsD samples received.",
},
)
sampleErrors = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "statsd_exporter_sample_errors_total",
Help: "The total number of errors parsing StatsD samples.",
},
[]string{"reason"},
)
tagsReceived = promauto.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_tags_total",
Help: "The total number of DogStatsD tags processed.",
},
)
tagErrors = promauto.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_tag_errors_total",
Help: "The number of errors parsing DogStatsD tags.",
},
)
configLoads = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "statsd_exporter_config_reloads_total",
Help: "The number of configuration reloads.",
},
[]string{"outcome"},
)
mappingsCount = promauto.NewGauge(prometheus.GaugeOpts{
Name: "statsd_exporter_loaded_mappings",
Help: "The current number of configured metric mappings.",
})
conflictingEventStats = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "statsd_exporter_events_conflict_total",
Help: "The total number of StatsD events with conflicting names.",
},
[]string{"type"},
)
errorEventStats = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "statsd_exporter_events_error_total",
Help: "The total number of StatsD events discarded due to errors.",
},
[]string{"reason"},
)
eventsActions = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "statsd_exporter_events_actions_total",
Help: "The total number of StatsD events by action.",
},
[]string{"action"},
)
metricsCount = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "statsd_exporter_metrics_total",
Help: "The total number of metrics.",
},
[]string{"type"},
)
)
func serveHTTP() {
http.Handle(*metricsEndpoint, prometheus.Handler())
http.ListenAndServe(*listenAddress, nil)
func serveHTTP(mux http.Handler, listenAddress string, logger log.Logger) {
level.Error(logger).Log("msg", http.ListenAndServe(listenAddress, mux))
os.Exit(1)
}
func udpAddrFromString(addr string) *net.UDPAddr {
host, portStr, err := net.SplitHostPort(addr)
if err != nil {
log.Fatal("Bad StatsD listening address", addr)
}
func sighupConfigReloader(fileName string, mapper *mapper.MetricMapper, logger log.Logger) {
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGHUP)
if host == "" {
host = "0.0.0.0"
}
ip, err := net.ResolveIPAddr("ip", host)
if err != nil {
log.Fatalf("Unable to resolve %s: %s", host, err)
}
for s := range signals {
if fileName == "" {
level.Warn(logger).Log("msg", "Received signal but no mapping config to reload", "signal", s)
continue
}
port, err := strconv.Atoi(portStr)
if err != nil || port < 0 || port > 65535 {
log.Fatalf("Bad port %s: %s", portStr, err)
}
level.Info(logger).Log("msg", "Received signal, attempting reload", "signal", s)
return &net.UDPAddr{
IP: ip.IP,
Port: port,
Zone: ip.Zone,
reloadConfig(fileName, mapper, logger)
}
}
func watchConfig(fileName string, mapper *metricMapper) {
watcher, err := fsnotify.NewWatcher()
func reloadConfig(fileName string, mapper *mapper.MetricMapper, logger log.Logger) {
err := mapper.InitFromFile(fileName)
if err != nil {
log.Fatal(err)
level.Info(logger).Log("msg", "Error reloading config", "error", err)
configLoads.WithLabelValues("failure").Inc()
} else {
level.Info(logger).Log("msg", "Config reloaded successfully")
configLoads.WithLabelValues("success").Inc()
}
}
err = watcher.WatchFlags(fileName, fsnotify.FSN_MODIFY)
func dumpFSM(mapper *mapper.MetricMapper, dumpFilename string, logger log.Logger) error {
f, err := os.Create(dumpFilename)
if err != nil {
log.Fatal(err)
return err
}
level.Info(logger).Log("msg", "Start dumping FSM", "file_name", dumpFilename)
w := bufio.NewWriter(f)
mapper.FSM.DumpFSM(w)
w.Flush()
f.Close()
level.Info(logger).Log("msg", "Finish dumping FSM")
return nil
}
for {
select {
case ev := <-watcher.Event:
log.Printf("Config file changed (%s), attempting reload", ev)
err = mapper.initFromFile(fileName)
if err != nil {
log.Println("Error reloading config:", err)
configLoads.WithLabelValues("failure").Inc()
} else {
log.Println("Config reloaded successfully")
configLoads.WithLabelValues("success").Inc()
}
// Re-add the file watcher since it can get lost on some changes. E.g.
// saving a file with vim results in a RENAME-MODIFY-DELETE event
// sequence, after which the newly written file is no longer watched.
err = watcher.WatchFlags(fileName, fsnotify.FSN_MODIFY)
case err := <-watcher.Error:
log.Println("Error watching config:", err)
func getCache(cacheSize int, cacheType string, registerer prometheus.Registerer) (mapper.MetricMapperCache, error) {
var cache mapper.MetricMapperCache
var err error
if cacheSize == 0 {
return nil, nil
} else {
switch cacheType {
case "lru":
cache, err = lru.NewMetricMapperLRUCache(registerer, cacheSize)
case "random":
cache, err = randomreplacement.NewMetricMapperRRCache(registerer, cacheSize)
default:
err = fmt.Errorf("unsupported cache type %q", cacheType)
}
if err != nil {
return nil, err
}
}
return cache, nil
}
func main() {
flag.Parse()
var (
listenAddress = kingpin.Flag("web.listen-address", "The address on which to expose the web interface and generated Prometheus metrics.").Default(":9102").String()
enableLifecycle = kingpin.Flag("web.enable-lifecycle", "Enable shutdown and reload via HTTP request.").Default("false").Bool()
metricsEndpoint = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
statsdListenUDP = kingpin.Flag("statsd.listen-udp", "The UDP address on which to receive statsd metric lines. \"\" disables it.").Default(":9125").String()
statsdListenTCP = kingpin.Flag("statsd.listen-tcp", "The TCP address on which to receive statsd metric lines. \"\" disables it.").Default(":9125").String()
statsdListenUnixgram = kingpin.Flag("statsd.listen-unixgram", "The Unixgram socket path to receive statsd metric lines in datagram. \"\" disables it.").Default("").String()
// not using Int here because flag displays default in decimal, 0755 will show as 493
statsdUnixSocketMode = kingpin.Flag("statsd.unixsocket-mode", "The permission mode of the unix socket.").Default("755").String()
mappingConfig = kingpin.Flag("statsd.mapping-config", "Metric mapping configuration file name.").String()
readBuffer = kingpin.Flag("statsd.read-buffer", "Size (in bytes) of the operating system's transmit read buffer associated with the UDP or Unixgram connection. Please make sure the kernel parameters net.core.rmem_max is set to a value greater than the value specified.").Int()
cacheSize = kingpin.Flag("statsd.cache-size", "Maximum size of your metric mapping cache. Relies on least recently used replacement policy if max size is reached.").Default("1000").Int()
cacheType = kingpin.Flag("statsd.cache-type", "Metric mapping cache type. Valid options are \"lru\" and \"random\"").Default("lru").Enum("lru", "random")
eventQueueSize = kingpin.Flag("statsd.event-queue-size", "Size of internal queue for processing events.").Default("10000").Uint()
eventFlushThreshold = kingpin.Flag("statsd.event-flush-threshold", "Number of events to hold in queue before flushing.").Default("1000").Int()
eventFlushInterval = kingpin.Flag("statsd.event-flush-interval", "Maximum time between event queue flushes.").Default("200ms").Duration()
dumpFSMPath = kingpin.Flag("debug.dump-fsm", "The path to dump internal FSM generated for glob matching as Dot file.").Default("").String()
checkConfig = kingpin.Flag("check-config", "Check configuration and exit.").Default("false").Bool()
dogstatsdTagsEnabled = kingpin.Flag("statsd.parse-dogstatsd-tags", "Parse DogStatsd style tags. Enabled by default.").Default("true").Bool()
influxdbTagsEnabled = kingpin.Flag("statsd.parse-influxdb-tags", "Parse InfluxDB style tags. Enabled by default.").Default("true").Bool()
libratoTagsEnabled = kingpin.Flag("statsd.parse-librato-tags", "Parse Librato style tags. Enabled by default.").Default("true").Bool()
signalFXTagsEnabled = kingpin.Flag("statsd.parse-signalfx-tags", "Parse SignalFX style tags. Enabled by default.").Default("true").Bool()
relayAddr = kingpin.Flag("statsd.relay.address", "The UDP relay target address (host:port)").String()
relayPacketLen = kingpin.Flag("statsd.relay.packet-length", "Maximum relay output packet length to avoid fragmentation").Default("1400").Uint()
udpPacketQueueSize = kingpin.Flag("statsd.udp-packet-queue-size", "Size of internal queue for processing UDP packets.").Default("10000").Int()
)
log.Println("Starting StatsD -> Prometheus Bridge...")
log.Println("Accepting StatsD Traffic on", *statsdListenAddress)
log.Println("Accepting Prometheus Requests on", *listenAddress)
promlogConfig := &promlog.Config{}
flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.Version(version.Print("statsd_exporter"))
kingpin.CommandLine.UsageWriter(os.Stdout)
kingpin.HelpFlag.Short('h')
kingpin.Parse()
logger := promlog.New(promlogConfig)
if err := level.SetLogLevel(promlogConfig.Level.String()); err != nil {
level.Error(logger).Log("msg", "failed to set log level", "error", err)
os.Exit(1)
}
prometheus.MustRegister(version.NewCollector("statsd_exporter"))
go serveHTTP()
parser := line.NewParser()
if *dogstatsdTagsEnabled {
parser.EnableDogstatsdParsing()
}
if *influxdbTagsEnabled {
parser.EnableInfluxdbParsing()
}
if *libratoTagsEnabled {
parser.EnableLibratoParsing()
}
if *signalFXTagsEnabled {
parser.EnableSignalFXParsing()
}
events := make(chan Events, 1024)
level.Info(logger).Log("msg", "Starting StatsD -> Prometheus Exporter", "version", version.Info())
level.Info(logger).Log("msg", "Build context", "context", version.BuildContext())
events := make(chan event.Events, *eventQueueSize)
defer close(events)
eventQueue := event.NewEventQueue(events, *eventFlushThreshold, *eventFlushInterval, eventsFlushed)
listenAddr := udpAddrFromString(*statsdListenAddress)
conn, err := net.ListenUDP("udp", listenAddr)
thisMapper := &mapper.MetricMapper{Registerer: prometheus.DefaultRegisterer, MappingsCount: mappingsCount, Logger: logger}
cache, err := getCache(*cacheSize, *cacheType, thisMapper.Registerer)
if err != nil {
log.Fatal(err)
level.Error(logger).Log("msg", "Unable to setup metric mapper cache", "error", err)
os.Exit(1)
}
l := &StatsDListener{conn: conn}
go l.Listen(events)
thisMapper.UseCache(cache)
mapper := &metricMapper{}
if *mappingConfig != "" {
err := mapper.initFromFile(*mappingConfig)
err := thisMapper.InitFromFile(*mappingConfig)
if err != nil {
log.Fatal("Error loading config:", err)
level.Error(logger).Log("msg", "error loading config", "error", err)
os.Exit(1)
}
if *dumpFSMPath != "" {
err := dumpFSM(thisMapper, *dumpFSMPath, logger)
if err != nil {
level.Error(logger).Log("msg", "error dumping FSM", "error", err)
// Failure to dump the FSM is an error (the user asked for it and it
// didn't happen) but not fatal (the exporter is fully functional
// afterwards).
}
}
go watchConfig(*mappingConfig, mapper)
}
bridge := NewBridge(mapper)
bridge.Listen(events)
exporter := exporter.NewExporter(prometheus.DefaultRegisterer, thisMapper, logger, eventsActions, eventsUnmapped, errorEventStats, eventStats, conflictingEventStats, metricsCount)
if *checkConfig {
level.Info(logger).Log("msg", "Configuration check successful, exiting")
return
}
var relayTarget *relay.Relay
if *relayAddr != "" {
var err error
relayTarget, err = relay.NewRelay(logger, *relayAddr, *relayPacketLen)
if err != nil {
level.Error(logger).Log("msg", "Unable to create relay", "err", err)
os.Exit(1)
}
}
level.Info(logger).Log("msg", "Accepting StatsD Traffic", "udp", *statsdListenUDP, "tcp", *statsdListenTCP, "unixgram", *statsdListenUnixgram)
level.Info(logger).Log("msg", "Accepting Prometheus Requests", "addr", *listenAddress)
if *statsdListenUDP == "" && *statsdListenTCP == "" && *statsdListenUnixgram == "" {
level.Error(logger).Log("At least one of UDP/TCP/Unixgram listeners must be specified.")
os.Exit(1)
}
if *statsdListenUDP != "" {
udpListenAddr, err := address.UDPAddrFromString(*statsdListenUDP)
if err != nil {
level.Error(logger).Log("msg", "invalid UDP listen address", "address", *statsdListenUDP, "error", err)
os.Exit(1)
}
uconn, err := net.ListenUDP("udp", udpListenAddr)
if err != nil {
level.Error(logger).Log("msg", "failed to start UDP listener", "error", err)
os.Exit(1)
}
if *readBuffer != 0 {
err = uconn.SetReadBuffer(*readBuffer)
if err != nil {
level.Error(logger).Log("msg", "error setting UDP read buffer", "error", err)
os.Exit(1)
}
}
udpPacketQueue := make(chan []byte, *udpPacketQueueSize)
ul := &listener.StatsDUDPListener{
Conn: uconn,
EventHandler: eventQueue,
Logger: logger,
LineParser: parser,
UDPPackets: udpPackets,
UDPPacketDrops: udpPacketDrops,
LinesReceived: linesReceived,
EventsFlushed: eventsFlushed,
Relay: relayTarget,
SampleErrors: *sampleErrors,
SamplesReceived: samplesReceived,
TagErrors: tagErrors,
TagsReceived: tagsReceived,
UdpPacketQueue: udpPacketQueue,
}
go ul.Listen()
}
if *statsdListenTCP != "" {
tcpListenAddr, err := address.TCPAddrFromString(*statsdListenTCP)
if err != nil {
level.Error(logger).Log("msg", "invalid TCP listen address", "address", *statsdListenUDP, "error", err)
os.Exit(1)
}
tconn, err := net.ListenTCP("tcp", tcpListenAddr)
if err != nil {
level.Error(logger).Log("msg", err)
os.Exit(1)
}
defer tconn.Close()
tl := &listener.StatsDTCPListener{
Conn: tconn,
EventHandler: eventQueue,
Logger: logger,
LineParser: parser,
LinesReceived: linesReceived,
EventsFlushed: eventsFlushed,
Relay: relayTarget,
SampleErrors: *sampleErrors,
SamplesReceived: samplesReceived,
TagErrors: tagErrors,
TagsReceived: tagsReceived,
TCPConnections: tcpConnections,
TCPErrors: tcpErrors,
TCPLineTooLong: tcpLineTooLong,
}
go tl.Listen()
}
if *statsdListenUnixgram != "" {
var err error
if _, err = os.Stat(*statsdListenUnixgram); !os.IsNotExist(err) {
level.Error(logger).Log("msg", "Unixgram socket already exists", "socket_name", *statsdListenUnixgram)
os.Exit(1)
}
uxgconn, err := net.ListenUnixgram("unixgram", &net.UnixAddr{
Net: "unixgram",
Name: *statsdListenUnixgram,
})
if err != nil {
level.Error(logger).Log("msg", "failed to listen on Unixgram socket", "error", err)
os.Exit(1)
}
defer uxgconn.Close()
if *readBuffer != 0 {
err = uxgconn.SetReadBuffer(*readBuffer)
if err != nil {
level.Error(logger).Log("msg", "error setting Unixgram read buffer", "error", err)
os.Exit(1)
}
}
ul := &listener.StatsDUnixgramListener{
Conn: uxgconn,
EventHandler: eventQueue,
Logger: logger,
LineParser: parser,
UnixgramPackets: unixgramPackets,
LinesReceived: linesReceived,
EventsFlushed: eventsFlushed,
Relay: relayTarget,
SampleErrors: *sampleErrors,
SamplesReceived: samplesReceived,
TagErrors: tagErrors,
TagsReceived: tagsReceived,
}
go ul.Listen()
// if it's an abstract unix domain socket, it won't exist on fs
// so we can't chmod it either
if _, err := os.Stat(*statsdListenUnixgram); !os.IsNotExist(err) {
defer os.Remove(*statsdListenUnixgram)
// convert the string to octet
perm, err := strconv.ParseInt("0"+string(*statsdUnixSocketMode), 8, 32)
if err != nil {
level.Warn(logger).Log("Bad permission %s: %v, ignoring\n", *statsdUnixSocketMode, err)
} else {
err = os.Chmod(*statsdListenUnixgram, os.FileMode(perm))
if err != nil {
level.Warn(logger).Log("Failed to change unixgram socket permission: %v", err)
}
}
}
}
mux := http.DefaultServeMux
mux.Handle(*metricsEndpoint, promhttp.Handler())
if *metricsEndpoint != "/" && *metricsEndpoint != "" {
landingConfig := web.LandingConfig{
Name: "StatsD Exporter",
Description: "Prometheus Exporter for converting StatsD to Prometheus metrics",
Version: version.Info(),
Links: []web.LandingLinks{
{
Address: *metricsEndpoint,
Text: "Metrics",
},
},
}
landingPage, err := web.NewLandingPage(landingConfig)
if err != nil {
level.Error(logger).Log("err", err)
os.Exit(1)
}
mux.Handle("/", landingPage)
}
quitChan := make(chan struct{}, 1)
if *enableLifecycle {
mux.HandleFunc("/-/reload", func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPut || r.Method == http.MethodPost {
fmt.Fprintf(w, "Requesting reload")
if *mappingConfig == "" {
level.Warn(logger).Log("msg", "Received lifecycle api reload but no mapping config to reload")
return
}
level.Info(logger).Log("msg", "Received lifecycle api reload, attempting reload")
reloadConfig(*mappingConfig, thisMapper, logger)
}
})
mux.HandleFunc("/-/quit", func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPut || r.Method == http.MethodPost {
fmt.Fprintf(w, "Requesting termination... Goodbye!")
quitChan <- struct{}{}
}
})
}
mux.HandleFunc("/-/healthy", func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
level.Debug(logger).Log("msg", "Received health check")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Statsd Exporter is Healthy.\n")
}
})
mux.HandleFunc("/-/ready", func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
level.Debug(logger).Log("msg", "Received ready check")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Statsd Exporter is Ready.\n")
}
})
go serveHTTP(mux, *listenAddress, logger)
go sighupConfigReloader(*mappingConfig, thisMapper, logger)
go exporter.Listen(events)
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
// quit if we get a message on either channel
select {
case sig := <-signals:
level.Info(logger).Log("msg", "Received os signal, exiting", "signal", sig.String())
case <-quitChan:
level.Info(logger).Log("msg", "Received lifecycle api quit, exiting")
}
}

142
mapper.go
View file

@ -1,142 +0,0 @@
// Copyright 2013 The Prometheus 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 (
"fmt"
"io/ioutil"
"regexp"
"strings"
"sync"
"github.com/prometheus/client_golang/prometheus"
)
var (
identifierRE = `[a-zA-Z_][a-zA-Z0-9_]+`
metricLineRE = regexp.MustCompile(`^(\*\.|` + identifierRE + `\.)+(\*|` + identifierRE + `)$`)
labelLineRE = regexp.MustCompile(`^(` + identifierRE + `)\s*=\s*"(.*)"$`)
metricNameRE = regexp.MustCompile(`^` + identifierRE + `$`)
)
type metricMapping struct {
regex *regexp.Regexp
labels prometheus.Labels
}
type metricMapper struct {
mappings []metricMapping
mutex sync.Mutex
}
type configLoadStates int
const (
SEARCHING configLoadStates = iota
METRIC_DEFINITION
)
func (m *metricMapper) initFromString(fileContents string) error {
lines := strings.Split(fileContents, "\n")
state := SEARCHING
parsedMappings := []metricMapping{}
currentMapping := metricMapping{labels: prometheus.Labels{}}
for i, line := range lines {
line := strings.TrimSpace(line)
switch state {
case SEARCHING:
if line == "" {
continue
}
if !metricLineRE.MatchString(line) {
return fmt.Errorf("Line %d: expected metric match line, got: %s", i, line)
}
// Translate the glob-style metric match line into a proper regex that we
// can use to match metrics later on.
metricRe := strings.Replace(line, ".", "\\.", -1)
metricRe = strings.Replace(metricRe, "*", "([^.]+)", -1)
currentMapping.regex = regexp.MustCompile("^" + metricRe + "$")
state = METRIC_DEFINITION
case METRIC_DEFINITION:
if line == "" {
if len(currentMapping.labels) == 0 {
return fmt.Errorf("Line %d: metric mapping didn't set any labels", i)
}
if _, ok := currentMapping.labels["name"]; !ok {
return fmt.Errorf("Line %d: metric mapping didn't set a metric name", i)
}
parsedMappings = append(parsedMappings, currentMapping)
state = SEARCHING
currentMapping = metricMapping{labels: prometheus.Labels{}}
continue
}
matches := labelLineRE.FindStringSubmatch(line)
if len(matches) != 3 {
return fmt.Errorf("Line %d: expected label mapping line, got: %s", i, line)
}
label, value := matches[1], matches[2]
if label == "name" && !metricNameRE.MatchString(value) {
return fmt.Errorf("Line %d: metric name '%s' doesn't match regex '%s'", i, value, metricNameRE)
}
currentMapping.labels[label] = value
default:
panic("illegal state")
}
}
m.mutex.Lock()
defer m.mutex.Unlock()
m.mappings = parsedMappings
mappingsCount.Set(float64(len(parsedMappings)))
return nil
}
func (m *metricMapper) initFromFile(fileName string) error {
mappingStr, err := ioutil.ReadFile(fileName)
if err != nil {
return err
}
return m.initFromString(string(mappingStr))
}
func (m *metricMapper) getMapping(statsdMetric string) (labels prometheus.Labels, present bool) {
m.mutex.Lock()
defer m.mutex.Unlock()
for _, mapping := range m.mappings {
matches := mapping.regex.FindStringSubmatchIndex(statsdMetric)
if len(matches) == 0 {
continue
}
labels := prometheus.Labels{}
for label, valueExpr := range mapping.labels {
value := mapping.regex.ExpandString([]byte{}, valueExpr, statsdMetric, matches)
labels[label] = string(value)
}
return labels, true
}
return nil, false
}

View file

@ -1,142 +0,0 @@
// Copyright 2013 The Prometheus 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 (
"testing"
)
func TestMetricMapper(t *testing.T) {
scenarios := []struct {
config string
configBad bool
mappings map[string]map[string]string
}{
// Empty config.
{},
// Config with several mapping definitions.
{
config: `
test.dispatcher.*.*.*
name="dispatch_events"
processor="$1"
action="$2"
result="$3"
job="test_dispatcher"
*.*
name="catchall"
first="$1"
second="$2"
third="$3"
job="$1-$2-$3"
`,
mappings: map[string]map[string]string{
"test.dispatcher.FooProcessor.send.succeeded": map[string]string{
"name": "dispatch_events",
"processor": "FooProcessor",
"action": "send",
"result": "succeeded",
"job": "test_dispatcher",
},
"foo.bar": map[string]string{
"name": "catchall",
"first": "foo",
"second": "bar",
"third": "",
"job": "foo-bar-",
},
"foo.bar.baz": map[string]string{},
},
},
// Config with bad regex reference.
{
config: `
test.*
name="name"
label="$1_foo"
`,
mappings: map[string]map[string]string{
"test.a": map[string]string{
"name": "name",
"label": "",
},
},
},
// Config with good regex reference.
{
config: `
test.*
name="name"
label="${1}_foo"
`,
mappings: map[string]map[string]string{
"test.a": map[string]string{
"name": "name",
"label": "a_foo",
},
},
},
// Config with bad metric line.
{
config: `
bad-metric-line.*.*
name="foo"
`,
configBad: true,
},
// Config with bad label line.
{
config: `
test.*.*
name=foo
`,
configBad: true,
},
// Config with bad metric name.
{
config: `
test.*.*
name="0foo"
`,
configBad: true,
},
}
mapper := metricMapper{}
for i, scenario := range scenarios {
err := mapper.initFromString(scenario.config)
if err != nil && !scenario.configBad {
t.Fatalf("%d. Config load error: %s", i, err)
}
if err == nil && scenario.configBad {
t.Fatalf("%d. Expected bad config, but loaded ok", i)
}
for metric, mapping := range scenario.mappings {
labels, present := mapper.getMapping(metric)
if len(labels) == 0 && present {
t.Fatalf("%d.%q: Expected metric to not be present", i, metric)
}
if len(labels) != len(mapping) {
t.Fatalf("%d.%q: Expected %d labels, got %d", i, metric, len(mapping), len(labels))
}
for label, value := range labels {
if mapping[label] != value {
t.Fatalf("%d.%q: Expected labels %v, got %v", i, metric, mapping, labels)
}
}
}
}
}

3
pkg/README.md Normal file
View file

@ -0,0 +1,3 @@
The `pkg` directory is deprecated.
Please do not add new packages to this directory.
Existing packages will be moved elsewhere eventually.

66
pkg/address/address.go Normal file
View file

@ -0,0 +1,66 @@
// Copyright 2013 The Prometheus 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 address
import (
"fmt"
"net"
"strconv"
)
func IPPortFromString(addr string) (*net.IPAddr, int, error) {
host, portStr, err := net.SplitHostPort(addr)
if err != nil {
return nil, 0, fmt.Errorf("bad StatsD listening address: %s", addr)
}
if host == "" {
host = "0.0.0.0"
}
ip, err := net.ResolveIPAddr("ip", host)
if err != nil {
return nil, 0, fmt.Errorf("unable to resolve %s: %s", host, err)
}
port, err := strconv.Atoi(portStr)
if err != nil || port < 0 || port > 65535 {
return nil, 0, fmt.Errorf("bad port %s: %s", portStr, err)
}
return ip, port, nil
}
func UDPAddrFromString(addr string) (*net.UDPAddr, error) {
ip, port, err := IPPortFromString(addr)
if err != nil {
return nil, err
}
return &net.UDPAddr{
IP: ip.IP,
Port: port,
Zone: ip.Zone,
}, nil
}
func TCPAddrFromString(addr string) (*net.TCPAddr, error) {
ip, port, err := IPPortFromString(addr)
if err != nil {
return nil, err
}
return &net.TCPAddr{
IP: ip.IP,
Port: port,
Zone: ip.Zone,
}, nil
}

41
pkg/clock/clock.go Normal file
View file

@ -0,0 +1,41 @@
// Copyright 2018 The Prometheus 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 clock
import (
"time"
)
var ClockInstance *Clock
type Clock struct {
Instant time.Time
TickerCh chan time.Time
}
func Now() time.Time {
if ClockInstance == nil {
return time.Now()
}
return ClockInstance.Instant
}
func NewTicker(d time.Duration) *time.Ticker {
if ClockInstance == nil || ClockInstance.TickerCh == nil {
return time.NewTicker(d)
}
return &time.Ticker{
C: ClockInstance.TickerCh,
}
}

138
pkg/event/event.go Normal file
View file

@ -0,0 +1,138 @@
// Copyright 2013 The Prometheus 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 event
import (
"sync"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/statsd_exporter/pkg/clock"
"github.com/prometheus/statsd_exporter/pkg/mapper"
)
type Event interface {
MetricName() string
Value() float64
Labels() map[string]string
MetricType() mapper.MetricType
}
type CounterEvent struct {
CMetricName string
CValue float64
CLabels map[string]string
}
func (c *CounterEvent) MetricName() string { return c.CMetricName }
func (c *CounterEvent) Value() float64 { return c.CValue }
func (c *CounterEvent) Labels() map[string]string { return c.CLabels }
func (c *CounterEvent) MetricType() mapper.MetricType { return mapper.MetricTypeCounter }
type GaugeEvent struct {
GMetricName string
GValue float64
GRelative bool
GLabels map[string]string
}
func (g *GaugeEvent) MetricName() string { return g.GMetricName }
func (g *GaugeEvent) Value() float64 { return g.GValue }
func (g *GaugeEvent) Labels() map[string]string { return g.GLabels }
func (g *GaugeEvent) MetricType() mapper.MetricType { return mapper.MetricTypeGauge }
type ObserverEvent struct {
OMetricName string
OValue float64
OLabels map[string]string
}
func (o *ObserverEvent) MetricName() string { return o.OMetricName }
func (o *ObserverEvent) Value() float64 { return o.OValue }
func (o *ObserverEvent) Labels() map[string]string { return o.OLabels }
func (o *ObserverEvent) MetricType() mapper.MetricType { return mapper.MetricTypeObserver }
type Events []Event
type EventQueue struct {
C chan Events
q Events
m sync.Mutex
flushTicker *time.Ticker
flushThreshold int
flushInterval time.Duration
eventsFlushed prometheus.Counter
}
type EventHandler interface {
Queue(event Events)
}
func NewEventQueue(c chan Events, flushThreshold int, flushInterval time.Duration, eventsFlushed prometheus.Counter) *EventQueue {
ticker := clock.NewTicker(flushInterval)
eq := &EventQueue{
C: c,
flushThreshold: flushThreshold,
flushInterval: flushInterval,
flushTicker: ticker,
q: make([]Event, 0, flushThreshold),
eventsFlushed: eventsFlushed,
}
go func() {
for {
<-ticker.C
eq.Flush()
}
}()
return eq
}
func (eq *EventQueue) Queue(events Events) {
eq.m.Lock()
defer eq.m.Unlock()
for _, e := range events {
eq.q = append(eq.q, e)
if len(eq.q) >= eq.flushThreshold {
eq.FlushUnlocked()
}
}
}
func (eq *EventQueue) Flush() {
eq.m.Lock()
defer eq.m.Unlock()
eq.FlushUnlocked()
}
func (eq *EventQueue) FlushUnlocked() {
eq.C <- eq.q
eq.q = make([]Event, 0, cap(eq.q))
eq.eventsFlushed.Inc()
}
func (eq *EventQueue) Len() int {
eq.m.Lock()
defer eq.m.Unlock()
return len(eq.q)
}
type UnbufferedEventHandler struct {
C chan Events
}
func (ueh *UnbufferedEventHandler) Queue(events Events) {
ueh.C <- events
}

87
pkg/event/event_test.go Normal file
View file

@ -0,0 +1,87 @@
// Copyright 2013 The Prometheus 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 event
import (
"testing"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/statsd_exporter/pkg/clock"
)
var eventsFlushed = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_event_queue_flushed_total",
Help: "Number of times events were flushed to exporter",
},
)
func TestEventThresholdFlush(t *testing.T) {
c := make(chan Events, 100)
// We're not going to flush during this test, so the duration doesn't matter.
eq := NewEventQueue(c, 5, time.Second, eventsFlushed)
e := make(Events, 13)
go func() {
eq.Queue(e)
}()
batch := <-c
if len(batch) != 5 {
t.Fatalf("Expected event batch to be 5 elements, but got %v", len(batch))
}
batch = <-c
if len(batch) != 5 {
t.Fatalf("Expected event batch to be 5 elements, but got %v", len(batch))
}
batch = <-c
if len(batch) != 3 {
t.Fatalf("Expected event batch to be 3 elements, but got %v", len(batch))
}
}
func TestEventIntervalFlush(t *testing.T) {
// Mock a time.NewTicker
tickerCh := make(chan time.Time)
clock.ClockInstance = &clock.Clock{
TickerCh: tickerCh,
}
clock.ClockInstance.Instant = time.Unix(0, 0)
c := make(chan Events, 100)
eq := NewEventQueue(c, 1000, time.Second*1000, eventsFlushed)
e := make(Events, 10)
eq.Queue(e)
if eq.Len() != 10 {
t.Fatal("Expected 10 events to be queued, but got", eq.Len())
}
if len(eq.C) != 0 {
t.Fatal("Expected 0 events in the event channel, but got", len(eq.C))
}
// Tick time forward to trigger a flush
clock.ClockInstance.Instant = time.Unix(10000, 0)
clock.ClockInstance.TickerCh <- time.Unix(10000, 0)
events := <-eq.C
if eq.Len() != 0 {
t.Fatal("Expected 0 events to be queued, but got", eq.Len())
}
if len(events) != 10 {
t.Fatal("Expected 10 events in the event channel, but got", len(events))
}
}

212
pkg/exporter/exporter.go Normal file
View file

@ -0,0 +1,212 @@
// Copyright 2013 The Prometheus 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 exporter
import (
"os"
"time"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/statsd_exporter/pkg/clock"
"github.com/prometheus/statsd_exporter/pkg/event"
"github.com/prometheus/statsd_exporter/pkg/level"
"github.com/prometheus/statsd_exporter/pkg/mapper"
"github.com/prometheus/statsd_exporter/pkg/registry"
)
const (
defaultHelp = "Metric autogenerated by statsd_exporter."
regErrF = "Failed to update metric"
)
type Registry interface {
GetCounter(metricName string, labels prometheus.Labels, help string, mapping *mapper.MetricMapping, metricsCount *prometheus.GaugeVec) (prometheus.Counter, error)
GetGauge(metricName string, labels prometheus.Labels, help string, mapping *mapper.MetricMapping, metricsCount *prometheus.GaugeVec) (prometheus.Gauge, error)
GetHistogram(metricName string, labels prometheus.Labels, help string, mapping *mapper.MetricMapping, metricsCount *prometheus.GaugeVec) (prometheus.Observer, error)
GetSummary(metricName string, labels prometheus.Labels, help string, mapping *mapper.MetricMapping, metricsCount *prometheus.GaugeVec) (prometheus.Observer, error)
RemoveStaleMetrics()
}
type Exporter struct {
Mapper *mapper.MetricMapper
Registry Registry
Logger log.Logger
EventsActions *prometheus.CounterVec
EventsUnmapped prometheus.Counter
ErrorEventStats *prometheus.CounterVec
EventStats *prometheus.CounterVec
ConflictingEventStats *prometheus.CounterVec
MetricsCount *prometheus.GaugeVec
}
// Listen handles all events sent to the given channel sequentially. It
// terminates when the channel is closed.
func (b *Exporter) Listen(e <-chan event.Events) {
removeStaleMetricsTicker := clock.NewTicker(time.Second)
for {
select {
case <-removeStaleMetricsTicker.C:
b.Registry.RemoveStaleMetrics()
case events, ok := <-e:
if !ok {
level.Debug(b.Logger).Log("msg", "Channel is closed. Break out of Exporter.Listener.")
removeStaleMetricsTicker.Stop()
return
}
for _, event := range events {
b.handleEvent(event)
}
}
}
}
// handleEvent processes a single Event according to the configured mapping.
func (b *Exporter) handleEvent(thisEvent event.Event) {
mapping, labels, present := b.Mapper.GetMapping(thisEvent.MetricName(), thisEvent.MetricType())
if mapping == nil {
mapping = &mapper.MetricMapping{}
if b.Mapper.Defaults.Ttl != 0 {
mapping.Ttl = b.Mapper.Defaults.Ttl
}
}
if mapping.Action == mapper.ActionTypeDrop {
b.EventsActions.WithLabelValues("drop").Inc()
return
}
metricName := ""
help := defaultHelp
if mapping.HelpText != "" {
help = mapping.HelpText
}
prometheusLabels := thisEvent.Labels()
if present {
if mapping.Name == "" {
level.Debug(b.Logger).Log("msg", "The mapping generates an empty metric name", "metric_name", thisEvent.MetricName(), "match", mapping.Match)
b.ErrorEventStats.WithLabelValues("empty_metric_name").Inc()
return
}
metricName = mapper.EscapeMetricName(mapping.Name)
for label, value := range labels {
if _, ok := prometheusLabels[label]; mapping.HonorLabels && ok {
continue
}
prometheusLabels[label] = value
}
b.EventsActions.WithLabelValues(string(mapping.Action)).Inc()
} else {
b.EventsUnmapped.Inc()
metricName = mapper.EscapeMetricName(thisEvent.MetricName())
}
eventValue := thisEvent.Value()
if mapping.Scale.Set {
eventValue *= mapping.Scale.Val
}
switch ev := thisEvent.(type) {
case *event.CounterEvent:
// We don't accept negative values for counters. Incrementing the counter with a negative number
// will cause the exporter to panic. Instead we will warn and continue to the next event.
if eventValue < 0.0 {
level.Debug(b.Logger).Log("msg", "counter must be non-negative value", "metric", metricName, "event_value", eventValue)
b.ErrorEventStats.WithLabelValues("illegal_negative_counter").Inc()
return
}
counter, err := b.Registry.GetCounter(metricName, prometheusLabels, help, mapping, b.MetricsCount)
if err == nil {
counter.Add(eventValue)
b.EventStats.WithLabelValues("counter").Inc()
} else {
level.Debug(b.Logger).Log("msg", regErrF, "metric", metricName, "error", err)
b.ConflictingEventStats.WithLabelValues("counter").Inc()
}
case *event.GaugeEvent:
gauge, err := b.Registry.GetGauge(metricName, prometheusLabels, help, mapping, b.MetricsCount)
if err == nil {
if ev.GRelative {
gauge.Add(eventValue)
} else {
gauge.Set(eventValue)
}
b.EventStats.WithLabelValues("gauge").Inc()
} else {
level.Debug(b.Logger).Log("msg", regErrF, "metric", metricName, "error", err)
b.ConflictingEventStats.WithLabelValues("gauge").Inc()
}
case *event.ObserverEvent:
t := mapper.ObserverTypeDefault
if mapping != nil {
t = mapping.ObserverType
}
if t == mapper.ObserverTypeDefault {
t = b.Mapper.Defaults.ObserverType
}
switch t {
case mapper.ObserverTypeHistogram:
histogram, err := b.Registry.GetHistogram(metricName, prometheusLabels, help, mapping, b.MetricsCount)
if err == nil {
histogram.Observe(eventValue)
b.EventStats.WithLabelValues("observer").Inc()
} else {
level.Debug(b.Logger).Log("msg", regErrF, "metric", metricName, "error", err)
b.ConflictingEventStats.WithLabelValues("observer").Inc()
}
case mapper.ObserverTypeDefault, mapper.ObserverTypeSummary:
summary, err := b.Registry.GetSummary(metricName, prometheusLabels, help, mapping, b.MetricsCount)
if err == nil {
summary.Observe(eventValue)
b.EventStats.WithLabelValues("observer").Inc()
} else {
level.Debug(b.Logger).Log("msg", regErrF, "metric", metricName, "error", err)
b.ConflictingEventStats.WithLabelValues("observer").Inc()
}
default:
level.Error(b.Logger).Log("msg", "unknown observer type", "type", t)
os.Exit(1)
}
default:
level.Debug(b.Logger).Log("msg", "Unsupported event type")
b.EventStats.WithLabelValues("illegal").Inc()
}
}
func NewExporter(reg prometheus.Registerer, mapper *mapper.MetricMapper, logger log.Logger, eventsActions *prometheus.CounterVec, eventsUnmapped prometheus.Counter, errorEventStats *prometheus.CounterVec, eventStats *prometheus.CounterVec, conflictingEventStats *prometheus.CounterVec, metricsCount *prometheus.GaugeVec) *Exporter {
return &Exporter{
Mapper: mapper,
Registry: registry.NewRegistry(reg, mapper),
Logger: logger,
EventsActions: eventsActions,
EventsUnmapped: eventsUnmapped,
ErrorEventStats: errorEventStats,
EventStats: eventStats,
ConflictingEventStats: conflictingEventStats,
MetricsCount: metricsCount,
}
}

File diff suppressed because it is too large Load diff

97
pkg/level/level.go Normal file
View file

@ -0,0 +1,97 @@
// Copyright 2021 The Prometheus 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 level
import (
"fmt"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
)
var logLevel = LevelInfo
// A Level is a logging priority. Higher levels are more important.
type Level int
const (
// LevelDebug logs are typically voluminous, and are usually disabled in
// production.
LevelDebug Level = iota
// LevelInfo is the default logging priority.
LevelInfo
// LevelWarn logs are more important than Info, but don't need individual
// human review.
LevelWarn
// LevelError logs are high-priority. If an application is running smoothly,
// it shouldn't generate any error-level logs.
LevelError
)
var emptyLogger = &EmptyLogger{}
type EmptyLogger struct{}
func (l *EmptyLogger) Log(keyvals ...interface{}) error {
return nil
}
// SetLogLevel sets the log level.
func SetLogLevel(level string) error {
switch level {
case "debug":
logLevel = LevelDebug
case "info":
logLevel = LevelInfo
case "warn":
logLevel = LevelWarn
case "error":
logLevel = LevelError
default:
return fmt.Errorf("unrecognized log level %s", level)
}
return nil
}
// Error returns a logger that includes a Key/ErrorValue pair.
func Error(logger log.Logger) log.Logger {
if logLevel <= LevelError {
return level.Error(logger)
}
return emptyLogger
}
// Warn returns a logger that includes a Key/WarnValue pair.
func Warn(logger log.Logger) log.Logger {
if logLevel <= LevelWarn {
return level.Warn(logger)
}
return emptyLogger
}
// Info returns a logger that includes a Key/InfoValue pair.
func Info(logger log.Logger) log.Logger {
if logLevel <= LevelInfo {
return level.Info(logger)
}
return emptyLogger
}
// Debug returns a logger that includes a Key/DebugValue pair.
func Debug(logger log.Logger) log.Logger {
if logLevel <= LevelDebug {
return level.Debug(logger)
}
return emptyLogger
}

110
pkg/level/level_test.go Normal file
View file

@ -0,0 +1,110 @@
// Copyright 2021 The Prometheus 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 level
import (
"bytes"
"strings"
"testing"
"github.com/go-kit/log"
)
func TestSetLogLevel(t *testing.T) {
tests := []struct {
name string
level string
logLevel Level
wantErr bool
}{
{"wrong level", "foo", LevelInfo, true},
{"level debug", "debug", LevelDebug, false},
{"level info", "info", LevelInfo, false},
{"level warn", "warn", LevelWarn, false},
{"level error", "error", LevelError, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := SetLogLevel(tt.level); (err != nil) != tt.wantErr {
t.Fatalf("Expected log level to be set successfully, but got %v", err)
}
if tt.logLevel != logLevel {
t.Fatalf("Expected log level %v, but got %v", tt.logLevel, logLevel)
}
})
}
}
func TestVariousLevels(t *testing.T) {
tests := []struct {
name string
level string
want string
}{
{
"level debug",
"debug",
strings.Join([]string{
"level=debug log=debug",
"level=info log=info",
"level=warn log=warn",
"level=error log=error",
}, "\n"),
},
{
"level info",
"info",
strings.Join([]string{
"level=info log=info",
"level=warn log=warn",
"level=error log=error",
}, "\n"),
},
{
"level warn",
"warn",
strings.Join([]string{
"level=warn log=warn",
"level=error log=error",
}, "\n"),
},
{
"level error",
"error",
strings.Join([]string{
"level=error log=error",
}, "\n"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var buf bytes.Buffer
logger := log.NewLogfmtLogger(&buf)
if err := SetLogLevel(tt.level); err != nil {
t.Fatalf("Expected log level to be set successfully, but got %v", err)
}
Debug(logger).Log("log", "debug")
Info(logger).Log("log", "info")
Warn(logger).Log("log", "warn")
Error(logger).Log("log", "error")
got := strings.TrimSpace(buf.String())
if tt.want != got {
t.Fatalf("Expected log output %v, but got %v", tt.want, got)
}
})
}
}

316
pkg/line/line.go Normal file
View file

@ -0,0 +1,316 @@
// Copyright 2013 The Prometheus 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 line
import (
"fmt"
"strconv"
"strings"
"unicode/utf8"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/statsd_exporter/pkg/event"
"github.com/prometheus/statsd_exporter/pkg/level"
"github.com/prometheus/statsd_exporter/pkg/mapper"
)
// Parser is a struct to hold configuration for parsing behavior
type Parser struct {
DogstatsdTagsEnabled bool
InfluxdbTagsEnabled bool
LibratoTagsEnabled bool
SignalFXTagsEnabled bool
}
// NewParser returns a new line parser
func NewParser() *Parser {
p := Parser{}
return &p
}
// EnableDogstatsdParsing option to enable dogstatsd tag parsing
func (p *Parser) EnableDogstatsdParsing() {
p.DogstatsdTagsEnabled = true
}
// EnableInfluxdbParsing option to enable influxdb tag parsing
func (p *Parser) EnableInfluxdbParsing() {
p.InfluxdbTagsEnabled = true
}
// EnableLibratoParsing option to enable librato tag parsing
func (p *Parser) EnableLibratoParsing() {
p.LibratoTagsEnabled = true
}
// EnableSignalFXParsing option to enable signalfx tag parsing
func (p *Parser) EnableSignalFXParsing() {
p.SignalFXTagsEnabled = true
}
func buildEvent(statType, metric string, value float64, relative bool, labels map[string]string) (event.Event, error) {
switch statType {
case "c":
return &event.CounterEvent{
CMetricName: metric,
CValue: float64(value),
CLabels: labels,
}, nil
case "g":
return &event.GaugeEvent{
GMetricName: metric,
GValue: float64(value),
GRelative: relative,
GLabels: labels,
}, nil
case "ms":
return &event.ObserverEvent{
OMetricName: metric,
OValue: float64(value) / 1000, // prometheus presumes seconds, statsd millisecond
OLabels: labels,
}, nil
case "h", "d":
return &event.ObserverEvent{
OMetricName: metric,
OValue: float64(value),
OLabels: labels,
}, nil
case "s":
return nil, fmt.Errorf("no support for StatsD sets")
default:
return nil, fmt.Errorf("bad stat type %s", statType)
}
}
func parseTag(component, tag string, separator rune, labels map[string]string, tagErrors prometheus.Counter, logger log.Logger) {
// Entirely empty tag is an error
if len(tag) == 0 {
tagErrors.Inc()
level.Debug(logger).Log("msg", "Empty name tag", "component", component)
return
}
for i, c := range tag {
if c == separator {
k := tag[:i]
v := tag[i+1:]
if len(k) == 0 || len(v) == 0 {
// Empty key or value is an error
tagErrors.Inc()
level.Debug(logger).Log("msg", "Malformed name tag", "k", k, "v", v, "component", component)
} else {
labels[mapper.EscapeMetricName(k)] = v
}
return
}
}
// Missing separator (no value) is an error
tagErrors.Inc()
level.Debug(logger).Log("msg", "Malformed name tag", "tag", tag, "component", component)
}
func parseNameTags(component string, labels map[string]string, tagErrors prometheus.Counter, logger log.Logger) {
lastTagEndIndex := 0
for i, c := range component {
if c == ',' {
tag := component[lastTagEndIndex:i]
lastTagEndIndex = i + 1
parseTag(component, tag, '=', labels, tagErrors, logger)
}
}
// If we're not off the end of the string, add the last tag
if lastTagEndIndex < len(component) {
tag := component[lastTagEndIndex:]
parseTag(component, tag, '=', labels, tagErrors, logger)
}
}
func trimLeftHash(s string) string {
if s != "" && s[0] == '#' {
return s[1:]
}
return s
}
func (p *Parser) ParseDogStatsDTags(component string, labels map[string]string, tagErrors prometheus.Counter, logger log.Logger) {
if p.DogstatsdTagsEnabled {
lastTagEndIndex := 0
for i, c := range component {
if c == ',' {
tag := component[lastTagEndIndex:i]
lastTagEndIndex = i + 1
parseTag(component, trimLeftHash(tag), ':', labels, tagErrors, logger)
}
}
// If we're not off the end of the string, add the last tag
if lastTagEndIndex < len(component) {
tag := component[lastTagEndIndex:]
parseTag(component, trimLeftHash(tag), ':', labels, tagErrors, logger)
}
}
}
func (p *Parser) parseNameAndTags(name string, labels map[string]string, tagErrors prometheus.Counter, logger log.Logger) string {
if p.SignalFXTagsEnabled {
// check for SignalFx tags first
// `[` delimits start of tags by SignalFx
// `]` delimits end of tags by SignalFx
// https://docs.signalfx.com/en/latest/integrations/agent/monitors/collectd-statsd.html
startIdx := strings.IndexRune(name, '[')
endIdx := strings.IndexRune(name, ']')
switch {
case startIdx != -1 && endIdx != -1:
// good signalfx tags
parseNameTags(name[startIdx+1:endIdx], labels, tagErrors, logger)
return name[:startIdx] + name[endIdx+1:]
case (startIdx != -1) != (endIdx != -1):
// only one bracket, return unparsed
level.Debug(logger).Log("msg", "invalid SignalFx tags, not parsing", "metric", name)
tagErrors.Inc()
return name
}
}
for i, c := range name {
// `#` delimits start of tags by Librato
// https://www.librato.com/docs/kb/collect/collection_agents/stastd/#stat-level-tags
// `,` delimits start of tags by InfluxDB
// https://www.influxdata.com/blog/getting-started-with-sending-statsd-metrics-to-telegraf-influxdb/#introducing-influx-statsd
if (c == '#' && p.LibratoTagsEnabled) || (c == ',' && p.InfluxdbTagsEnabled) {
parseNameTags(name[i+1:], labels, tagErrors, logger)
return name[:i]
}
}
return name
}
func (p *Parser) LineToEvents(line string, sampleErrors prometheus.CounterVec, samplesReceived prometheus.Counter, tagErrors prometheus.Counter, tagsReceived prometheus.Counter, logger log.Logger) event.Events {
events := event.Events{}
if line == "" {
return events
}
elements := strings.SplitN(line, ":", 2)
if len(elements) < 2 || len(elements[0]) == 0 || !utf8.ValidString(line) {
sampleErrors.WithLabelValues("malformed_line").Inc()
level.Debug(logger).Log("msg", "Bad line from StatsD", "line", line)
return events
}
labels := map[string]string{}
metric := p.parseNameAndTags(elements[0], labels, tagErrors, logger)
var samples []string
if strings.Contains(elements[1], "|#") {
// using DogStatsD tags
// don't allow mixed tagging styles
if len(labels) > 0 {
sampleErrors.WithLabelValues("mixed_tagging_styles").Inc()
level.Debug(logger).Log("msg", "Bad line (multiple tagging styles) from StatsD", "line", line)
return events
}
// disable multi-metrics
samples = elements[1:]
} else {
samples = strings.Split(elements[1], ":")
}
samples:
for _, sample := range samples {
samplesReceived.Inc()
components := strings.Split(sample, "|")
if len(components) < 2 || len(components) > 4 {
sampleErrors.WithLabelValues("malformed_component").Inc()
level.Debug(logger).Log("msg", "Bad component", "line", line)
continue
}
valueStr, statType := components[0], components[1]
var relative = false
if strings.Index(valueStr, "+") == 0 || strings.Index(valueStr, "-") == 0 {
relative = true
}
value, err := strconv.ParseFloat(valueStr, 64)
if err != nil {
level.Debug(logger).Log("msg", "Bad value", "value", valueStr, "line", line)
sampleErrors.WithLabelValues("malformed_value").Inc()
continue
}
multiplyEvents := 1
if len(components) >= 3 {
for _, component := range components[2:] {
if len(component) == 0 {
level.Debug(logger).Log("msg", "Empty component", "line", line)
sampleErrors.WithLabelValues("malformed_component").Inc()
continue samples
}
}
for _, component := range components[2:] {
switch component[0] {
case '@':
samplingFactor, err := strconv.ParseFloat(component[1:], 64)
if err != nil {
level.Debug(logger).Log("msg", "Invalid sampling factor", "component", component[1:], "line", line)
sampleErrors.WithLabelValues("invalid_sample_factor").Inc()
}
if samplingFactor == 0 {
samplingFactor = 1
}
if statType == "g" {
continue
} else if statType == "c" {
value /= samplingFactor
} else if statType == "ms" || statType == "h" || statType == "d" {
multiplyEvents = int(1 / samplingFactor)
}
case '#':
p.ParseDogStatsDTags(component[1:], labels, tagErrors, logger)
default:
level.Debug(logger).Log("msg", "Invalid sampling factor or tag section", "component", components[2], "line", line)
sampleErrors.WithLabelValues("invalid_sample_factor").Inc()
continue
}
}
}
if len(labels) > 0 {
tagsReceived.Inc()
}
for i := 0; i < multiplyEvents; i++ {
event, err := buildEvent(statType, metric, value, relative, labels)
if err != nil {
level.Debug(logger).Log("msg", "Error building event", "line", line, "error", err)
sampleErrors.WithLabelValues("illegal_event").Inc()
continue
}
events = append(events, event)
}
}
return events
}

1703
pkg/line/line_test.go Normal file

File diff suppressed because it is too large Load diff

219
pkg/listener/listener.go Normal file
View file

@ -0,0 +1,219 @@
// Copyright 2013 The Prometheus 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 listener
import (
"bufio"
"io"
"net"
"os"
"strings"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/statsd_exporter/pkg/event"
"github.com/prometheus/statsd_exporter/pkg/level"
"github.com/prometheus/statsd_exporter/pkg/relay"
)
type Parser interface {
LineToEvents(line string, sampleErrors prometheus.CounterVec, samplesReceived prometheus.Counter, tagErrors prometheus.Counter, tagsReceived prometheus.Counter, logger log.Logger) event.Events
}
type StatsDUDPListener struct {
Conn *net.UDPConn
EventHandler event.EventHandler
Logger log.Logger
LineParser Parser
UDPPackets prometheus.Counter
UDPPacketDrops prometheus.Counter
LinesReceived prometheus.Counter
EventsFlushed prometheus.Counter
Relay *relay.Relay
SampleErrors prometheus.CounterVec
SamplesReceived prometheus.Counter
TagErrors prometheus.Counter
TagsReceived prometheus.Counter
UdpPacketQueue chan []byte
}
func (l *StatsDUDPListener) SetEventHandler(eh event.EventHandler) {
l.EventHandler = eh
}
func (l *StatsDUDPListener) Listen() {
buf := make([]byte, 65535)
go l.ProcessUdpPacketQueue()
for {
n, _, err := l.Conn.ReadFromUDP(buf)
if err != nil {
// https://github.com/golang/go/issues/4373
// ignore net: errClosing error as it will occur during shutdown
if strings.HasSuffix(err.Error(), "use of closed network connection") {
return
}
level.Error(l.Logger).Log("error", err)
return
}
l.EnqueueUdpPacket(buf, n)
}
}
func (l *StatsDUDPListener) EnqueueUdpPacket(packet []byte, n int) {
l.UDPPackets.Inc()
packetCopy := make([]byte, n)
copy(packetCopy, packet)
select {
case l.UdpPacketQueue <- packetCopy:
// do nothing
default:
l.UDPPacketDrops.Inc()
}
}
func (l *StatsDUDPListener) ProcessUdpPacketQueue() {
for {
packet := <-l.UdpPacketQueue
l.HandlePacket(packet)
}
}
func (l *StatsDUDPListener) HandlePacket(packet []byte) {
lines := strings.Split(string(packet), "\n")
for _, line := range lines {
level.Debug(l.Logger).Log("msg", "Incoming line", "proto", "udp", "line", line)
l.LinesReceived.Inc()
if l.Relay != nil && len(line) > 0 {
l.Relay.RelayLine(line)
}
l.EventHandler.Queue(l.LineParser.LineToEvents(line, l.SampleErrors, l.SamplesReceived, l.TagErrors, l.TagsReceived, l.Logger))
}
}
type StatsDTCPListener struct {
Conn *net.TCPListener
EventHandler event.EventHandler
Logger log.Logger
LineParser Parser
LinesReceived prometheus.Counter
EventsFlushed prometheus.Counter
Relay *relay.Relay
SampleErrors prometheus.CounterVec
SamplesReceived prometheus.Counter
TagErrors prometheus.Counter
TagsReceived prometheus.Counter
TCPConnections prometheus.Counter
TCPErrors prometheus.Counter
TCPLineTooLong prometheus.Counter
}
func (l *StatsDTCPListener) SetEventHandler(eh event.EventHandler) {
l.EventHandler = eh
}
func (l *StatsDTCPListener) Listen() {
for {
c, err := l.Conn.AcceptTCP()
if err != nil {
// https://github.com/golang/go/issues/4373
// ignore net: errClosing error as it will occur during shutdown
if strings.HasSuffix(err.Error(), "use of closed network connection") {
return
}
level.Error(l.Logger).Log("msg", "AcceptTCP failed", "error", err)
os.Exit(1)
}
go l.HandleConn(c)
}
}
func (l *StatsDTCPListener) HandleConn(c *net.TCPConn) {
defer c.Close()
l.TCPConnections.Inc()
r := bufio.NewReader(c)
for {
line, isPrefix, err := r.ReadLine()
if err != nil {
if err != io.EOF {
l.TCPErrors.Inc()
level.Debug(l.Logger).Log("msg", "Read failed", "addr", c.RemoteAddr(), "error", err)
}
break
}
level.Debug(l.Logger).Log("msg", "Incoming line", "proto", "tcp", "line", string(line))
if isPrefix {
l.TCPLineTooLong.Inc()
level.Debug(l.Logger).Log("msg", "Read failed: line too long", "addr", c.RemoteAddr())
break
}
l.LinesReceived.Inc()
if l.Relay != nil && len(line) > 0 {
l.Relay.RelayLine(string(line))
}
l.EventHandler.Queue(l.LineParser.LineToEvents(string(line), l.SampleErrors, l.SamplesReceived, l.TagErrors, l.TagsReceived, l.Logger))
}
}
type StatsDUnixgramListener struct {
Conn *net.UnixConn
EventHandler event.EventHandler
Logger log.Logger
LineParser Parser
UnixgramPackets prometheus.Counter
LinesReceived prometheus.Counter
EventsFlushed prometheus.Counter
Relay *relay.Relay
SampleErrors prometheus.CounterVec
SamplesReceived prometheus.Counter
TagErrors prometheus.Counter
TagsReceived prometheus.Counter
}
func (l *StatsDUnixgramListener) SetEventHandler(eh event.EventHandler) {
l.EventHandler = eh
}
func (l *StatsDUnixgramListener) Listen() {
buf := make([]byte, 65535)
for {
n, _, err := l.Conn.ReadFromUnix(buf)
if err != nil {
// https://github.com/golang/go/issues/4373
// ignore net: errClosing error as it will occur during shutdown
if strings.HasSuffix(err.Error(), "use of closed network connection") {
return
}
level.Error(l.Logger).Log(err)
os.Exit(1)
}
l.HandlePacket(buf[:n])
}
}
func (l *StatsDUnixgramListener) HandlePacket(packet []byte) {
l.UnixgramPackets.Inc()
lines := strings.Split(string(packet), "\n")
for _, line := range lines {
level.Debug(l.Logger).Log("msg", "Incoming line", "proto", "unixgram", "line", line)
l.LinesReceived.Inc()
if l.Relay != nil && len(line) > 0 {
l.Relay.RelayLine(line)
}
l.EventHandler.Queue(l.LineParser.LineToEvents(line, l.SampleErrors, l.SamplesReceived, l.TagErrors, l.TagsReceived, l.Logger))
}
}

42
pkg/mapper/action.go Normal file
View file

@ -0,0 +1,42 @@
// Copyright 2018 The Prometheus 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 mapper
import "fmt"
type ActionType string
const (
ActionTypeMap ActionType = "map"
ActionTypeDrop ActionType = "drop"
ActionTypeDefault ActionType = ""
)
func (t *ActionType) UnmarshalYAML(unmarshal func(interface{}) error) error {
var v string
if err := unmarshal(&v); err != nil {
return err
}
switch ActionType(v) {
case ActionTypeDrop:
*t = ActionTypeDrop
case ActionTypeMap, ActionTypeDefault:
*t = ActionTypeMap
default:
return fmt.Errorf("invalid action type %q", v)
}
return nil
}

86
pkg/mapper/escape.go Normal file
View file

@ -0,0 +1,86 @@
// Copyright 2020 The Prometheus 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 mapper
import (
"strings"
"unicode/utf8"
)
// EscapeMetricName replaces invalid characters in the metric name with "_"
// Valid characters are a-z, A-Z, 0-9, and _
func EscapeMetricName(metricName string) string {
metricLen := len(metricName)
if metricLen == 0 {
return ""
}
escaped := false
var sb strings.Builder
// If a metric starts with a digit, allocate the memory and prepend an
// underscore.
if metricName[0] >= '0' && metricName[0] <= '9' {
escaped = true
sb.Grow(metricLen + 1)
sb.WriteByte('_')
}
// This is an character replacement method optimized for this limited
// use case. It is much faster than using a regex.
offset := 0
var prevChar rune
for i, c := range metricName {
// Seek forward, skipping valid characters until we find one that needs
// to be replaced, then add all the characters we've seen so far to the
// string.Builder.
if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') || (c == '_') {
// Character is valid, so skip over it without doing anything.
} else {
// Double-dashes are allowed if there is a corresponding mapping.
// For consistency, double-dashes should also be allowed in the default case.
if c == '-' && prevChar == '-' {
offset = i + utf8.RuneLen(c)
continue
}
if !escaped {
// Up until now we've been lazy and avoided actually allocating
// memory. Unfortunately we've now determined this string needs
// escaping, so allocate the buffer for the whole string.
escaped = true
sb.Grow(metricLen)
}
sb.WriteString(metricName[offset:i])
offset = i + utf8.RuneLen(c)
sb.WriteByte('_')
}
prevChar = c
}
if !escaped {
// This is the happy path where nothing had to be escaped, so we can
// avoid doing anything.
return metricName
}
if offset < metricLen {
sb.WriteString(metricName[offset:])
}
return sb.String()
}

60
pkg/mapper/escape_test.go Normal file
View file

@ -0,0 +1,60 @@
// Copyright 2020 The Prometheus 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 mapper
import "testing"
func TestEscapeMetricName(t *testing.T) {
scenarios := map[string]string{
"clean": "clean",
"0starts_with_digit": "_0starts_with_digit",
"with_underscore": "with_underscore",
"with--doubledash": "with_doubledash",
"with---multiple-dashes": "with_multiple_dashes",
"with.dot": "with_dot",
"with😱emoji": "with_emoji",
"with.*.multiple": "with___multiple",
"test.web-server.foo.bar": "test_web_server_foo_bar",
"": "",
}
for in, want := range scenarios {
if got := EscapeMetricName(in); want != got {
t.Errorf("expected `%s` to be escaped to `%s`, got `%s`", in, want, got)
}
}
}
func BenchmarkEscapeMetricName(b *testing.B) {
scenarios := []string{
"clean",
"0starts_with_digit",
"with_underscore",
"with--doubledash",
"with---multiple-dashes",
"with.dot",
"with😱emoji",
"with.*.multiple",
"test.web-server.foo.bar",
"",
}
for _, s := range scenarios {
b.Run(s, func(b *testing.B) {
for n := 0; n < b.N; n++ {
EscapeMetricName(s)
}
})
}
}

132
pkg/mapper/fsm/README.md Normal file
View file

@ -0,0 +1,132 @@
# FSM Mapping
## Overview
This package implements a fast and efficient algorithm for generic glob style
string matching using a finite state machine (FSM).
### Source Hierachy
```
'-- fsm
'-- dump.go // functionality to dump the FSM to Dot file
'-- formatter.go // format glob templates using captured * groups
'-- fsm.go // manipulating and searching of FSM
'-- minmax.go // min() max() function for interger
```
## FSM Explained
Per [Wikipedia](https://en.wikipedia.org/wiki/Finite-state_machine):
> A finite-state machine (FSM) or finite-state automaton (FSA, plural: automata),
> finite automaton, or simply a state machine, is a mathematical model of
> computation. It is an abstract machine that can be in exactly one of a finite
> number of states at any given time. The FSM can change from one state to
> another in response to some external inputs; the change from one state to
> another is called a transition. An FSM is defined by a list of its states, its
> initial state, and the conditions for each transition.
In our use case, each *state* is a substring after the input StatsD metric name is splitted by `.`.
### Add state to FSM
`func (f *FSM) AddState(match string, matchMetricType string,
maxPossibleTransitions int, result interface{}) int`
At first, the FSM only contains three states, representing three possible metric types:
____ [gauge]
/
(start)---- [counter]
\
'--- [observer]
Adding a rule `client.*.request.count` with type `counter` will make the FSM to be:
____ [gauge]
/
(start)---- [counter] -- [client] -- [*] -- [request] -- [count] -- {R1}
\
'--- [observer]
`{R1}` is short for result 1, which is the match result for `client.*.request.count`.
Adding a rule `client.*.*.size` with type `counter` will make the FSM to be:
____ [gauge] __ [request] -- [count] -- {R1}
/ /
(start)---- [counter] -- [client] -- [*]
\ \__ [*] -- [size] -- {R2}
'--- [observer]
### Finding a result state in FSM
`func (f *FSM) GetMapping(statsdMetric string, statsdMetricType string)
(*mappingState, []string)`
For example, when mapping `client.aaa.request.count` with `counter` type in the
FSM, the `^1` to `^7` symbols indicate how FSM will traversal in its tree:
____ [gauge] __ [request] -- [count] -- {R1}
/ / ^5 ^6 ^7
(start)---- [counter] -- [client] -- [*]
^1 \ ^2 ^3 \__ [*] -- [size] -- {R2}
'--- [observer] ^4
To map `client.bbb.request.size`, FSM will do a backtracking:
____ [gauge] __ [request] -- [count] -- {R1}
/ / ^5 ^6
(start)---- [counter] -- [client] -- [*]
^1 \ ^2 ^3 \__ [*] -- [size] -- {R2}
'--- [observer] ^4
^7 ^8 ^9
## Debugging
To see all the states of the current FSM, use `func (f *FSM) DumpFSM(w io.Writer)`
to dump into a Dot file. The Dot file can be further renderer into image using:
```shell
$ dot -Tpng dump.dot > dump.png
```
In StatsD exporter, one could use the following:
```shell
$ statsd_exporter --statsd.mapping-config=statsd.rules --debug.dump-fsm=dump.dot
$ dot -Tpng dump.dot > dump.png
```
For example, the following rules:
```yaml
mappings:
- match: client.*.request.count
name: request_count
match_metric_type: counter
labels:
client: $1
- match: client.*.*.size
name: sizes
match_metric_type: counter
labels:
client: $1
direction: $2
```
will be rendered as:
![FSM](fsm.png)
The `dot` program is part of [Graphviz](https://www.graphviz.org/) and is
available in most of popular operating systems.

48
pkg/mapper/fsm/dump.go Normal file
View file

@ -0,0 +1,48 @@
// Copyright 2018 The Prometheus 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 fsm
import (
"fmt"
"io"
)
// DumpFSM accepts a io.writer and write the current FSM into dot file format.
func (f *FSM) DumpFSM(w io.Writer) {
idx := 0
states := make(map[int]*mappingState)
states[idx] = f.root
w.Write([]byte("digraph g {\n"))
w.Write([]byte("rankdir=LR\n")) // make it vertical
w.Write([]byte("node [ label=\"\",style=filled,fillcolor=white,shape=circle ]\n")) // remove label of node
for idx < len(states) {
for field, transition := range states[idx].transitions {
states[len(states)] = transition
w.Write([]byte(fmt.Sprintf("%d -> %d [label = \"%s\"];\n", idx, len(states)-1, field)))
if idx == 0 {
// color for metric types
w.Write([]byte(fmt.Sprintf("%d [color=\"#D6B656\",fillcolor=\"#FFF2CC\"];\n", len(states)-1)))
} else if transition.transitions == nil || len(transition.transitions) == 0 {
// color for end state
w.Write([]byte(fmt.Sprintf("%d [color=\"#82B366\",fillcolor=\"#D5E8D4\"];\n", len(states)-1)))
}
}
idx++
}
// color for start state
w.Write([]byte(fmt.Sprintln("0 [color=\"#a94442\",fillcolor=\"#f2dede\"];")))
w.Write([]byte("}"))
}

View file

@ -0,0 +1,76 @@
// Copyright 2018 The Prometheus 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 fsm
import (
"fmt"
"regexp"
"strconv"
"strings"
)
var (
templateReplaceCaptureRE = regexp.MustCompile(`\$\{?([a-zA-Z0-9_\$]+)\}?`)
)
type TemplateFormatter struct {
captureIndexes []int
captureCount int
fmtString string
}
// NewTemplateFormatter instantiates a TemplateFormatter
// from given template string and the maximum amount of captures.
func NewTemplateFormatter(template string, captureCount int) *TemplateFormatter {
matches := templateReplaceCaptureRE.FindAllStringSubmatch(template, -1)
if len(matches) == 0 {
// if no regex reference found, keep it as it is
return &TemplateFormatter{captureCount: 0, fmtString: template}
}
var indexes []int
valueFormatter := template
for _, match := range matches {
idx, err := strconv.Atoi(match[len(match)-1])
if err != nil || idx > captureCount || idx < 1 {
// if index larger than captured count or using unsupported named capture group,
// replace with empty string
valueFormatter = strings.Replace(valueFormatter, match[0], "", -1)
} else {
valueFormatter = strings.Replace(valueFormatter, match[0], "%s", -1)
// note: the regex reference variable $? starts from 1
indexes = append(indexes, idx-1)
}
}
return &TemplateFormatter{
captureIndexes: indexes,
captureCount: len(indexes),
fmtString: valueFormatter,
}
}
// Format accepts a list containing captured strings and returns the formatted
// string using the template stored in current TemplateFormatter.
func (formatter *TemplateFormatter) Format(captures []string) string {
if formatter.captureCount == 0 {
// no label substitution, keep as it is
return formatter.fmtString
}
indexes := formatter.captureIndexes
vargs := make([]interface{}, formatter.captureCount)
for i, idx := range indexes {
vargs[i] = captures[idx]
}
return fmt.Sprintf(formatter.fmtString, vargs...)
}

326
pkg/mapper/fsm/fsm.go Normal file
View file

@ -0,0 +1,326 @@
// Copyright 2018 The Prometheus 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 fsm
import (
"regexp"
"strings"
"github.com/go-kit/log"
"github.com/prometheus/statsd_exporter/pkg/level"
)
type mappingState struct {
transitions map[string]*mappingState
minRemainingLength int
maxRemainingLength int
// result* members are nil unless there's a metric ends with this state
Result interface{}
ResultPriority int
}
type fsmBacktrackStackCursor struct {
fieldIndex int
captureIndex int
currentCapture string
state *mappingState
prev *fsmBacktrackStackCursor
next *fsmBacktrackStackCursor
}
type FSM struct {
root *mappingState
metricTypes []string
statesCount int
BacktrackingNeeded bool
OrderingDisabled bool
}
// NewFSM creates a new FSM instance
func NewFSM(metricTypes []string, maxPossibleTransitions int, orderingDisabled bool) *FSM {
fsm := FSM{}
root := &mappingState{}
root.transitions = make(map[string]*mappingState, len(metricTypes))
for _, field := range metricTypes {
state := &mappingState{}
(*state).transitions = make(map[string]*mappingState, maxPossibleTransitions)
root.transitions[string(field)] = state
}
fsm.OrderingDisabled = orderingDisabled
fsm.metricTypes = metricTypes
fsm.statesCount = 0
fsm.root = root
return &fsm
}
// AddState adds a mapping rule into the existing FSM.
// The maxPossibleTransitions parameter sets the expected count of transitions left.
// The result parameter sets the generic type to be returned when fsm found a match in GetMapping.
func (f *FSM) AddState(match string, matchMetricType string, maxPossibleTransitions int, result interface{}) int {
// first split by "."
matchFields := strings.Split(match, ".")
// fill into our FSM
roots := []*mappingState{}
// first state is the metric type
if matchMetricType == "" {
// if metricType not specified, connect the start state from all three types
for _, metricType := range f.metricTypes {
roots = append(roots, f.root.transitions[string(metricType)])
}
} else {
roots = append(roots, f.root.transitions[matchMetricType])
}
var captureCount int
var finalStates []*mappingState
// iterating over different start state (different metric types)
for _, root := range roots {
captureCount = 0
// for each start state, connect from start state to end state
for i, field := range matchFields {
state, prs := root.transitions[field]
if !prs {
// create a state if it's not exist in the fsm
state = &mappingState{}
(*state).transitions = make(map[string]*mappingState, maxPossibleTransitions)
(*state).maxRemainingLength = len(matchFields) - i - 1
(*state).minRemainingLength = len(matchFields) - i - 1
root.transitions[field] = state
// if this is last field, set result to currentMapping instance
if i == len(matchFields)-1 {
root.transitions[field].Result = result
}
} else {
(*state).maxRemainingLength = max(len(matchFields)-i-1, (*state).maxRemainingLength)
(*state).minRemainingLength = min(len(matchFields)-i-1, (*state).minRemainingLength)
}
if field == "*" {
captureCount++
}
// goto next state
root = state
}
finalStates = append(finalStates, root)
}
for _, state := range finalStates {
state.ResultPriority = f.statesCount
}
f.statesCount++
return captureCount
}
// GetMapping using the fsm to find matching rules according to given statsdMetric and statsdMetricType.
// If it finds a match, the final state and the captured strings are returned;
// if there's no match found, nil and a empty list will be returned.
func (f *FSM) GetMapping(statsdMetric string, statsdMetricType string) (*mappingState, []string) {
matchFields := strings.Split(statsdMetric, ".")
currentState := f.root.transitions[statsdMetricType]
// the cursor/pointer in the backtrack stack implemented as a double-linked list
var backtrackCursor *fsmBacktrackStackCursor
resumeFromBacktrack := false
// the return variable
var finalState *mappingState
captures := make([]string, len(matchFields))
finalCaptures := make([]string, len(matchFields))
// keep track of captured group so we don't need to do append() on captures
captureIdx := 0
filedsCount := len(matchFields)
i := 0
var state *mappingState
for { // the loop for backtracking
for { // the loop for a single "depth only" search
var present bool
// if we resume from backtrack, we should skip this branch in this case
// since the state that were saved at the end of this branch
if !resumeFromBacktrack {
if len(currentState.transitions) > 0 {
field := matchFields[i]
state, present = currentState.transitions[field]
fieldsLeft := filedsCount - i - 1
// also compare length upfront to avoid unnecessary loop or backtrack
if !present || fieldsLeft > state.maxRemainingLength || fieldsLeft < state.minRemainingLength {
state, present = currentState.transitions["*"]
if !present || fieldsLeft > state.maxRemainingLength || fieldsLeft < state.minRemainingLength {
break
} else {
captures[captureIdx] = field
captureIdx++
}
} else if f.BacktrackingNeeded {
// if backtracking is needed, also check for alternative transition, i.e. *
altState, present := currentState.transitions["*"]
if !present || fieldsLeft > altState.maxRemainingLength || fieldsLeft < altState.minRemainingLength {
} else {
// push to backtracking stack
newCursor := fsmBacktrackStackCursor{prev: backtrackCursor, state: altState,
fieldIndex: i,
captureIndex: captureIdx, currentCapture: field,
}
// if this is not the first time, connect to the previous cursor
if backtrackCursor != nil {
backtrackCursor.next = &newCursor
}
backtrackCursor = &newCursor
}
}
} else {
// no more transitions for this state
break
}
} // backtrack will resume from here
// do we reach a final state?
if state.Result != nil && i == filedsCount-1 {
if f.OrderingDisabled {
finalState = state
return finalState, captures
} else if finalState == nil || finalState.ResultPriority > state.ResultPriority {
// if we care about ordering, try to find a result with highest prioity
finalState = state
// do a deep copy to preserve current captures
copy(finalCaptures, captures)
}
break
}
i++
if i >= filedsCount {
break
}
resumeFromBacktrack = false
currentState = state
}
if backtrackCursor == nil {
// if we are not doing backtracking or all path has been travesaled
break
} else {
// pop one from stack
state = backtrackCursor.state
currentState = state
i = backtrackCursor.fieldIndex
captureIdx = backtrackCursor.captureIndex + 1
// put the * capture back
captures[captureIdx-1] = backtrackCursor.currentCapture
backtrackCursor = backtrackCursor.prev
if backtrackCursor != nil {
// deref for GC
backtrackCursor.next = nil
}
resumeFromBacktrack = true
}
}
return finalState, finalCaptures
}
// TestIfNeedBacktracking tests if backtrack is needed for given list of mappings
// and whether ordering is disabled.
func TestIfNeedBacktracking(mappings []string, orderingDisabled bool, logger log.Logger) bool {
backtrackingNeeded := false
// A has * in rules, but there's other transisitions at the same state,
// this makes A the cause of backtracking
ruleByLength := make(map[int][]string)
ruleREByLength := make(map[int][]*regexp.Regexp)
// first sort rules by length
for _, mapping := range mappings {
l := len(strings.Split(mapping, "."))
ruleByLength[l] = append(ruleByLength[l], mapping)
metricRe := strings.Replace(mapping, ".", "\\.", -1)
metricRe = strings.Replace(metricRe, "*", "([^.]*)", -1)
regex, err := regexp.Compile("^" + metricRe + "$")
if err != nil {
level.Warn(logger).Log("msg", "Invalid match, cannot compile regex in mapping", "mapping", mapping, "err", err)
}
// put into array no matter there's error or not, we will skip later if regex is nil
ruleREByLength[l] = append(ruleREByLength[l], regex)
}
for l, rules := range ruleByLength {
if len(rules) == 1 {
continue
}
rulesRE := ruleREByLength[l]
for i1, r1 := range rules {
currentRuleNeedBacktrack := false
re1 := rulesRE[i1]
if re1 == nil || !strings.Contains(r1, "*") {
continue
}
// if rule r1 is A.B.C.*.E.*, is there a rule r2 is A.B.C.D.x.x or A.B.C.*.E.F ? (x is any string or *)
// if such r2 exists, then to match r1 we will need backtracking
for index := 0; index < len(r1); index++ {
if r1[index] != '*' {
continue
}
// translate the substring of r1 from 0 to the index of current * into regex
// A.B.C.*.E.* will becomes ^A\.B\.C\. and ^A\.B\.C\.\*\.E\.
reStr := strings.Replace(r1[:index], ".", "\\.", -1)
reStr = strings.Replace(reStr, "*", "\\*", -1)
re := regexp.MustCompile("^" + reStr)
for i2, r2 := range rules {
if i2 == i1 {
continue
}
if len(re.FindStringSubmatchIndex(r2)) > 0 {
currentRuleNeedBacktrack = true
break
}
}
}
for i2, r2 := range rules {
if i2 != i1 && len(re1.FindStringSubmatchIndex(r2)) > 0 {
// log if we care about ordering and the superset occurs before
if !orderingDisabled && i1 < i2 {
level.Warn(logger).Log("msg", "match is a super set of match but in a lower order, the first will never be matched", "first_match", r1, "second_match", r2)
}
currentRuleNeedBacktrack = false
}
}
for i2, re2 := range rulesRE {
if i2 == i1 || re2 == nil {
continue
}
// if r1 is a subset of other rule, we don't need backtrack
// because either we turned on ordering
// or we disabled ordering and can't match it even with backtrack
if len(re2.FindStringSubmatchIndex(r1)) > 0 {
currentRuleNeedBacktrack = false
}
}
if currentRuleNeedBacktrack {
level.Warn(logger).Log("msg", "backtracking required because of match. Performance may be degraded", "match", r1)
backtrackingNeeded = true
}
}
}
// backtracking will always be needed if ordering of rules is not disabled
// since transistions are stored in (unordered) map
// note: don't move this branch to the beginning of this function
// since we need logs for superset rules
return !orderingDisabled || backtrackingNeeded
}

BIN
pkg/mapper/fsm/fsm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

30
pkg/mapper/fsm/minmax.go Normal file
View file

@ -0,0 +1,30 @@
// Copyright 2018 The Prometheus 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 fsm
// min and max implementation for integer
func min(x, y int) int {
if x < y {
return x
}
return y
}
func max(x, y int) int {
if x > y {
return x
}
return y
}

394
pkg/mapper/mapper.go Normal file
View file

@ -0,0 +1,394 @@
// Copyright 2013 The Prometheus 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 mapper
import (
"fmt"
"os"
"regexp"
"sync"
"time"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"gopkg.in/yaml.v2"
"github.com/prometheus/statsd_exporter/pkg/level"
"github.com/prometheus/statsd_exporter/pkg/mapper/fsm"
)
var (
// The first segment of a match cannot start with a number
statsdMetricRE = `[a-zA-Z_]([a-zA-Z0-9_\-])*`
// The subsequent segments of a match can start with a number
// See https://github.com/prometheus/statsd_exporter/issues/328
statsdMetricSubsequentRE = `[a-zA-Z0-9_]([a-zA-Z0-9_\-])*`
templateReplaceRE = `(\$\{?\d+\}?)`
metricLineRE = regexp.MustCompile(`^(\*|` + statsdMetricRE + `)(\.\*|\.` + statsdMetricSubsequentRE + `)*$`)
metricNameRE = regexp.MustCompile(`^([a-zA-Z_]|` + templateReplaceRE + `)([a-zA-Z0-9_]|` + templateReplaceRE + `)*$`)
labelNameRE = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]+$`)
)
type MetricMapper struct {
Registerer prometheus.Registerer
Defaults MapperConfigDefaults `yaml:"defaults"`
Mappings []MetricMapping `yaml:"mappings"`
FSM *fsm.FSM
doFSM bool
doRegex bool
cache MetricMapperCache
mutex sync.RWMutex
MappingsCount prometheus.Gauge
Logger log.Logger
}
type SummaryOptions struct {
Quantiles []MetricObjective `yaml:"quantiles"`
MaxAge time.Duration `yaml:"max_age"`
AgeBuckets uint32 `yaml:"age_buckets"`
BufCap uint32 `yaml:"buf_cap"`
}
type HistogramOptions struct {
Buckets []float64 `yaml:"buckets"`
NativeHistogramBucketFactor float64 `yaml:"native_histogram_bucket_factor"`
NativeHistogramMaxBuckets uint32 `yaml:"native_histogram_max_buckets"`
}
type MetricObjective struct {
Quantile float64 `yaml:"quantile"`
Error float64 `yaml:"error"`
}
var defaultQuantiles = []MetricObjective{
{Quantile: 0.5, Error: 0.05},
{Quantile: 0.9, Error: 0.01},
{Quantile: 0.99, Error: 0.001},
}
func (m *MetricMapper) InitFromYAMLString(fileContents string) error {
var n MetricMapper
if err := yaml.Unmarshal([]byte(fileContents), &n); err != nil {
return err
}
if len(n.Defaults.HistogramOptions.Buckets) == 0 {
n.Defaults.HistogramOptions.Buckets = prometheus.DefBuckets
}
if n.Defaults.HistogramOptions.NativeHistogramBucketFactor == 0 {
n.Defaults.HistogramOptions.NativeHistogramBucketFactor = 1.1
}
if n.Defaults.HistogramOptions.NativeHistogramMaxBuckets <= 0 {
n.Defaults.HistogramOptions.NativeHistogramMaxBuckets = 256
}
if len(n.Defaults.SummaryOptions.Quantiles) == 0 {
n.Defaults.SummaryOptions.Quantiles = defaultQuantiles
}
if n.Defaults.MatchType == MatchTypeDefault {
n.Defaults.MatchType = MatchTypeGlob
}
remainingMappingsCount := len(n.Mappings)
n.FSM = fsm.NewFSM([]string{string(MetricTypeCounter), string(MetricTypeGauge), string(MetricTypeObserver)},
remainingMappingsCount, n.Defaults.GlobDisableOrdering)
for i := range n.Mappings {
remainingMappingsCount--
currentMapping := &n.Mappings[i]
// check that label is correct
for k := range currentMapping.Labels {
if !labelNameRE.MatchString(k) {
return fmt.Errorf("invalid label key: %s", k)
}
}
if currentMapping.Name == "" {
return fmt.Errorf("line %d: metric mapping didn't set a metric name", i)
}
if !metricNameRE.MatchString(currentMapping.Name) {
return fmt.Errorf("metric name '%s' doesn't match regex '%s'", currentMapping.Name, metricNameRE)
}
if currentMapping.MatchType == "" {
currentMapping.MatchType = n.Defaults.MatchType
}
if currentMapping.Action == "" {
currentMapping.Action = ActionTypeMap
}
if currentMapping.MatchType == MatchTypeGlob {
n.doFSM = true
if !metricLineRE.MatchString(currentMapping.Match) {
return fmt.Errorf("invalid match: %s", currentMapping.Match)
}
captureCount := n.FSM.AddState(currentMapping.Match, string(currentMapping.MatchMetricType),
remainingMappingsCount, currentMapping)
currentMapping.nameFormatter = fsm.NewTemplateFormatter(currentMapping.Name, captureCount)
labelKeys := make([]string, len(currentMapping.Labels))
labelFormatters := make([]*fsm.TemplateFormatter, len(currentMapping.Labels))
labelIndex := 0
for label, valueExpr := range currentMapping.Labels {
labelKeys[labelIndex] = label
labelFormatters[labelIndex] = fsm.NewTemplateFormatter(valueExpr, captureCount)
labelIndex++
}
currentMapping.labelFormatters = labelFormatters
currentMapping.labelKeys = labelKeys
} else {
if regex, err := regexp.Compile(currentMapping.Match); err != nil {
return fmt.Errorf("invalid regex %s in mapping: %v", currentMapping.Match, err)
} else {
currentMapping.regex = regex
}
n.doRegex = true
}
if currentMapping.ObserverType == "" {
currentMapping.ObserverType = n.Defaults.ObserverType
}
if currentMapping.LegacyQuantiles != nil &&
(currentMapping.SummaryOptions == nil || currentMapping.SummaryOptions.Quantiles != nil) {
level.Warn(m.Logger).Log("msg", "using the top level quantiles is deprecated. Please use quantiles in the summary_options hierarchy")
}
if currentMapping.LegacyBuckets != nil &&
(currentMapping.HistogramOptions == nil || currentMapping.HistogramOptions.Buckets != nil) {
level.Warn(m.Logger).Log("msg", "using the top level buckets is deprecated. Please use buckets in the histogram_options hierarchy")
}
if currentMapping.SummaryOptions != nil &&
currentMapping.LegacyQuantiles != nil &&
currentMapping.SummaryOptions.Quantiles != nil {
return fmt.Errorf("cannot use quantiles in both the top level and summary options at the same time in %s", currentMapping.Match)
}
if currentMapping.HistogramOptions != nil &&
currentMapping.LegacyBuckets != nil &&
currentMapping.HistogramOptions.Buckets != nil {
return fmt.Errorf("cannot use buckets in both the top level and histogram options at the same time in %s", currentMapping.Match)
}
if currentMapping.ObserverType == ObserverTypeHistogram {
if currentMapping.SummaryOptions != nil {
return fmt.Errorf("cannot use histogram observer and summary options at the same time")
}
if currentMapping.HistogramOptions == nil {
currentMapping.HistogramOptions = &HistogramOptions{}
}
if currentMapping.LegacyBuckets != nil && len(currentMapping.LegacyBuckets) != 0 {
currentMapping.HistogramOptions.Buckets = currentMapping.LegacyBuckets
}
if currentMapping.HistogramOptions.Buckets == nil || len(currentMapping.HistogramOptions.Buckets) == 0 {
currentMapping.HistogramOptions.Buckets = n.Defaults.HistogramOptions.Buckets
}
}
if currentMapping.ObserverType == ObserverTypeSummary {
if currentMapping.HistogramOptions != nil {
return fmt.Errorf("cannot use summary observer and histogram options at the same time")
}
if currentMapping.SummaryOptions == nil {
currentMapping.SummaryOptions = &SummaryOptions{}
}
if currentMapping.LegacyQuantiles != nil && len(currentMapping.LegacyQuantiles) != 0 {
currentMapping.SummaryOptions.Quantiles = currentMapping.LegacyQuantiles
}
if currentMapping.SummaryOptions.Quantiles == nil || len(currentMapping.SummaryOptions.Quantiles) == 0 {
currentMapping.SummaryOptions.Quantiles = n.Defaults.SummaryOptions.Quantiles
}
if currentMapping.SummaryOptions.MaxAge == 0 {
currentMapping.SummaryOptions.MaxAge = n.Defaults.SummaryOptions.MaxAge
}
if currentMapping.SummaryOptions.AgeBuckets == 0 {
currentMapping.SummaryOptions.AgeBuckets = n.Defaults.SummaryOptions.AgeBuckets
}
if currentMapping.SummaryOptions.BufCap == 0 {
currentMapping.SummaryOptions.BufCap = n.Defaults.SummaryOptions.BufCap
}
}
if currentMapping.Ttl == 0 && n.Defaults.Ttl > 0 {
currentMapping.Ttl = n.Defaults.Ttl
}
}
m.mutex.Lock()
defer m.mutex.Unlock()
if m.Logger == nil {
m.Logger = log.NewNopLogger()
}
m.Defaults = n.Defaults
m.Mappings = n.Mappings
// Reset the cache since this function can be used to reload config
if m.cache != nil {
m.cache.Reset()
}
if n.doFSM {
var mappings []string
for _, mapping := range n.Mappings {
if mapping.MatchType == MatchTypeGlob {
mappings = append(mappings, mapping.Match)
}
}
n.FSM.BacktrackingNeeded = fsm.TestIfNeedBacktracking(mappings, n.FSM.OrderingDisabled, m.Logger)
m.FSM = n.FSM
m.doRegex = n.doRegex
}
m.doFSM = n.doFSM
if m.MappingsCount != nil {
m.MappingsCount.Set(float64(len(n.Mappings)))
}
return nil
}
func (m *MetricMapper) InitFromFile(fileName string) error {
mappingStr, err := os.ReadFile(fileName)
if err != nil {
return err
}
return m.InitFromYAMLString(string(mappingStr))
}
// UseCache tells the mapper to use a cache that implements the MetricMapperCache interface.
// This cache MUST be thread-safe!
func (m *MetricMapper) UseCache(cache MetricMapperCache) {
m.mutex.Lock()
defer m.mutex.Unlock()
m.cache = cache
}
func (m *MetricMapper) GetMapping(statsdMetric string, statsdMetricType MetricType) (*MetricMapping, prometheus.Labels, bool) {
m.mutex.RLock()
defer m.mutex.RUnlock()
// only use a cache if one is present
if m.cache != nil {
result, cached := m.cache.Get(formatKey(statsdMetric, statsdMetricType))
if cached {
r := result.(MetricMapperCacheResult)
return r.Mapping, r.Labels, r.Matched
}
}
// glob matching
if m.doFSM {
finalState, captures := m.FSM.GetMapping(statsdMetric, string(statsdMetricType))
if finalState != nil && finalState.Result != nil {
v := finalState.Result.(*MetricMapping)
result := copyMetricMapping(v)
result.Name = result.nameFormatter.Format(captures)
labels := prometheus.Labels{}
for index, formatter := range result.labelFormatters {
labels[result.labelKeys[index]] = formatter.Format(captures)
}
r := MetricMapperCacheResult{
Mapping: result,
Matched: true,
Labels: labels,
}
// add match to cache
if m.cache != nil {
m.cache.Add(formatKey(statsdMetric, statsdMetricType), r)
}
return result, labels, true
} else if !m.doRegex {
// if there's no regex match type, return immediately
// Add miss to cache
if m.cache != nil {
m.cache.Add(formatKey(statsdMetric, statsdMetricType), MetricMapperCacheResult{})
}
return nil, nil, false
}
}
// regex matching
for _, mapping := range m.Mappings {
// if a rule don't have regex matching type, the regex field is unset
if mapping.regex == nil {
continue
}
matches := mapping.regex.FindStringSubmatchIndex(statsdMetric)
if len(matches) == 0 {
continue
}
mapping.Name = string(mapping.regex.ExpandString(
[]byte{},
mapping.Name,
statsdMetric,
matches,
))
if mt := mapping.MatchMetricType; mt != "" && mt != statsdMetricType {
continue
}
labels := prometheus.Labels{}
for label, valueExpr := range mapping.Labels {
value := mapping.regex.ExpandString([]byte{}, valueExpr, statsdMetric, matches)
labels[label] = string(value)
}
r := MetricMapperCacheResult{
Mapping: &mapping,
Matched: true,
Labels: labels,
}
// Add Match to cache
if m.cache != nil {
m.cache.Add(formatKey(statsdMetric, statsdMetricType), r)
}
return &mapping, labels, true
}
// Add Miss to cache
if m.cache != nil {
m.cache.Add(formatKey(statsdMetric, statsdMetricType), MetricMapperCacheResult{})
}
return nil, nil, false
}
// make a shallow copy so that we do not overwrite name
// as multiple names can be matched by same mapping
func copyMetricMapping(in *MetricMapping) *MetricMapping {
out := *in
return &out
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,74 @@
// Copyright 2019 The Prometheus 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 mapper
import (
"github.com/prometheus/client_golang/prometheus"
)
type CacheMetrics struct {
CacheLength prometheus.Gauge
CacheGetsTotal prometheus.Counter
CacheHitsTotal prometheus.Counter
}
func NewCacheMetrics(reg prometheus.Registerer) *CacheMetrics {
var m CacheMetrics
m.CacheLength = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "statsd_metric_mapper_cache_length",
Help: "The count of unique metrics currently cached.",
},
)
m.CacheGetsTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "statsd_metric_mapper_cache_gets_total",
Help: "The count of total metric cache gets.",
},
)
m.CacheHitsTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "statsd_metric_mapper_cache_hits_total",
Help: "The count of total metric cache hits.",
},
)
if reg != nil {
reg.MustRegister(m.CacheLength)
reg.MustRegister(m.CacheGetsTotal)
reg.MustRegister(m.CacheHitsTotal)
}
return &m
}
type MetricMapperCacheResult struct {
Mapping *MetricMapping
Matched bool
Labels prometheus.Labels
}
// MetricMapperCache MUST be thread-safe and should be instrumented with CacheMetrics
type MetricMapperCache interface {
// Get a cached result
Get(metricKey string) (interface{}, bool)
// Add a statsd MetricMapperResult to the cache
Add(metricKey string, result interface{}) // Add an item to the cache
// Reset clears the cache for config reloads
Reset()
}
func formatKey(metricString string, metricType MetricType) string {
return string(metricType) + "." + metricString
}

View file

@ -0,0 +1,72 @@
// Copyright 2020 The Prometheus 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 mapper
import "time"
type MapperConfigDefaults struct {
ObserverType ObserverType `yaml:"observer_type"`
MatchType MatchType `yaml:"match_type"`
GlobDisableOrdering bool `yaml:"glob_disable_ordering"`
Ttl time.Duration `yaml:"ttl"`
SummaryOptions SummaryOptions `yaml:"summary_options"`
HistogramOptions HistogramOptions `yaml:"histogram_options"`
}
// mapperConfigDefaultsAlias is used to unmarshal the yaml config into mapperConfigDefaults and allows deprecated fields
type mapperConfigDefaultsAlias struct {
ObserverType ObserverType `yaml:"observer_type"`
TimerType ObserverType `yaml:"timer_type,omitempty"` // DEPRECATED - field only present to preserve backwards compatibility in configs
Buckets []float64 `yaml:"buckets"` // DEPRECATED - field only present to preserve backwards compatibility in configs
Quantiles []MetricObjective `yaml:"quantiles"` // DEPRECATED - field only present to preserve backwards compatibility in configs
MatchType MatchType `yaml:"match_type"`
GlobDisableOrdering bool `yaml:"glob_disable_ordering"`
Ttl time.Duration `yaml:"ttl"`
SummaryOptions SummaryOptions `yaml:"summary_options"`
HistogramOptions HistogramOptions `yaml:"histogram_options"`
}
// UnmarshalYAML is a custom unmarshal function to allow use of deprecated config keys
// observer_type will override timer_type
func (d *MapperConfigDefaults) UnmarshalYAML(unmarshal func(interface{}) error) error {
var tmp mapperConfigDefaultsAlias
if err := unmarshal(&tmp); err != nil {
return err
}
// Copy defaults
d.ObserverType = tmp.ObserverType
d.MatchType = tmp.MatchType
d.GlobDisableOrdering = tmp.GlobDisableOrdering
d.Ttl = tmp.Ttl
d.SummaryOptions = tmp.SummaryOptions
d.HistogramOptions = tmp.HistogramOptions
// Use deprecated TimerType if necessary
if tmp.ObserverType == "" {
d.ObserverType = tmp.TimerType
}
// Use deprecated quantiles if necessary
if len(tmp.SummaryOptions.Quantiles) == 0 && len(tmp.Quantiles) > 0 {
d.SummaryOptions = SummaryOptions{Quantiles: tmp.Quantiles}
}
// Use deprecated buckets if necessary
if len(tmp.HistogramOptions.Buckets) == 0 && len(tmp.Buckets) > 0 {
d.HistogramOptions = HistogramOptions{Buckets: tmp.Buckets}
}
return nil
}

1762
pkg/mapper/mapper_test.go Normal file

File diff suppressed because it is too large Load diff

102
pkg/mapper/mapping.go Normal file
View file

@ -0,0 +1,102 @@
// Copyright 2020 The Prometheus 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 xpress or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package mapper
import (
"regexp"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/statsd_exporter/pkg/mapper/fsm"
)
type MetricMapping struct {
Match string `yaml:"match"`
Name string `yaml:"name"`
nameFormatter *fsm.TemplateFormatter
regex *regexp.Regexp
Labels prometheus.Labels `yaml:"labels"`
HonorLabels bool `yaml:"honor_labels"`
labelKeys []string
labelFormatters []*fsm.TemplateFormatter
ObserverType ObserverType `yaml:"observer_type"`
TimerType ObserverType `yaml:"timer_type,omitempty"` // DEPRECATED - field only present to preserve backwards compatibility in configs. Always empty
LegacyBuckets []float64 `yaml:"buckets"`
LegacyQuantiles []MetricObjective `yaml:"quantiles"`
MatchType MatchType `yaml:"match_type"`
HelpText string `yaml:"help"`
Action ActionType `yaml:"action"`
MatchMetricType MetricType `yaml:"match_metric_type"`
Ttl time.Duration `yaml:"ttl"`
SummaryOptions *SummaryOptions `yaml:"summary_options"`
HistogramOptions *HistogramOptions `yaml:"histogram_options"`
Scale MaybeFloat64 `yaml:"scale"`
}
// UnmarshalYAML is a custom unmarshal function to allow use of deprecated config keys
// observer_type will override timer_type
func (m *MetricMapping) UnmarshalYAML(unmarshal func(interface{}) error) error {
type MetricMappingAlias MetricMapping
var tmp MetricMappingAlias
if err := unmarshal(&tmp); err != nil {
return err
}
// Copy defaults
m.Match = tmp.Match
m.Name = tmp.Name
m.Labels = tmp.Labels
m.HonorLabels = tmp.HonorLabels
m.ObserverType = tmp.ObserverType
m.LegacyBuckets = tmp.LegacyBuckets
m.LegacyQuantiles = tmp.LegacyQuantiles
m.MatchType = tmp.MatchType
m.HelpText = tmp.HelpText
m.Action = tmp.Action
m.MatchMetricType = tmp.MatchMetricType
m.Ttl = tmp.Ttl
m.SummaryOptions = tmp.SummaryOptions
m.HistogramOptions = tmp.HistogramOptions
m.Scale = tmp.Scale
// Use deprecated TimerType if necessary
if tmp.ObserverType == "" {
m.ObserverType = tmp.TimerType
}
return nil
}
type MaybeFloat64 struct {
Set bool
Val float64
}
func (m *MaybeFloat64) MarshalYAML() (interface{}, error) {
if m.Set {
return m.Val, nil
}
return nil, nil
}
func (m *MaybeFloat64) UnmarshalYAML(unmarshal func(interface{}) error) error {
var tmp float64
if err := unmarshal(&tmp); err != nil {
return err
}
m.Val = tmp
m.Set = true
return nil
}

41
pkg/mapper/match.go Normal file
View file

@ -0,0 +1,41 @@
// Copyright 2013 The Prometheus 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 mapper
import "fmt"
type MatchType string
const (
MatchTypeGlob MatchType = "glob"
MatchTypeRegex MatchType = "regex"
MatchTypeDefault MatchType = ""
)
func (t *MatchType) UnmarshalYAML(unmarshal func(interface{}) error) error {
var v string
if err := unmarshal(&v); err != nil {
return err
}
switch MatchType(v) {
case MatchTypeRegex:
*t = MatchTypeRegex
case MatchTypeGlob, MatchTypeDefault:
*t = MatchTypeGlob
default:
return fmt.Errorf("invalid match type %q", v)
}
return nil
}

46
pkg/mapper/metric_type.go Normal file
View file

@ -0,0 +1,46 @@
// Copyright 2018 The Prometheus 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 mapper
import "fmt"
type MetricType string
const (
MetricTypeCounter MetricType = "counter"
MetricTypeGauge MetricType = "gauge"
MetricTypeObserver MetricType = "observer"
MetricTypeTimer MetricType = "timer" // DEPRECATED
)
func (m *MetricType) UnmarshalYAML(unmarshal func(interface{}) error) error {
var v string
if err := unmarshal(&v); err != nil {
return err
}
switch MetricType(v) {
case MetricTypeCounter:
*m = MetricTypeCounter
case MetricTypeGauge:
*m = MetricTypeGauge
case MetricTypeObserver:
*m = MetricTypeObserver
case MetricTypeTimer:
*m = MetricTypeObserver
default:
return fmt.Errorf("invalid metric type '%s'", v)
}
return nil
}

41
pkg/mapper/observer.go Normal file
View file

@ -0,0 +1,41 @@
// Copyright 2013 The Prometheus 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 mapper
import "fmt"
type ObserverType string
const (
ObserverTypeHistogram ObserverType = "histogram"
ObserverTypeSummary ObserverType = "summary"
ObserverTypeDefault ObserverType = ""
)
func (t *ObserverType) UnmarshalYAML(unmarshal func(interface{}) error) error {
var v string
if err := unmarshal(&v); err != nil {
return err
}
switch ObserverType(v) {
case ObserverTypeHistogram:
*t = ObserverTypeHistogram
case ObserverTypeSummary, ObserverTypeDefault:
*t = ObserverTypeSummary
default:
return fmt.Errorf("invalid observer type '%s'", v)
}
return nil
}

103
pkg/mappercache/lru/lru.go Normal file
View file

@ -0,0 +1,103 @@
// Copyright 2021 The Prometheus 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 lru
import (
"sync"
"github.com/prometheus/client_golang/prometheus"
"github.com/golang/groupcache/lru"
"github.com/prometheus/statsd_exporter/pkg/mappercache"
)
type metricMapperLRUCache struct {
cache *lruCache
metrics *mappercache.CacheMetrics
}
func NewMetricMapperLRUCache(reg prometheus.Registerer, size int) (*metricMapperLRUCache, error) {
if size <= 0 {
return nil, nil
}
metrics := mappercache.NewCacheMetrics(reg)
cache := newLruCache(size)
return &metricMapperLRUCache{metrics: metrics, cache: cache}, nil
}
func (m *metricMapperLRUCache) Get(metricKey string) (interface{}, bool) {
m.metrics.CacheGetsTotal.Inc()
if result, ok := m.cache.Get(metricKey); ok {
m.metrics.CacheHitsTotal.Inc()
return result, true
} else {
return nil, false
}
}
func (m *metricMapperLRUCache) Add(metricKey string, result interface{}) {
go m.trackCacheLength()
m.cache.Add(metricKey, result)
}
func (m *metricMapperLRUCache) trackCacheLength() {
m.metrics.CacheLength.Set(float64(m.cache.Len()))
}
func (m *metricMapperLRUCache) Reset() {
m.cache.Clear()
m.metrics.CacheLength.Set(0)
}
type lruCache struct {
cache *lru.Cache
lock sync.RWMutex
}
func newLruCache(maxEntries int) *lruCache {
return &lruCache{
cache: lru.New(maxEntries),
}
}
func (l *lruCache) Get(key string) (interface{}, bool) {
l.lock.RLock()
defer l.lock.RUnlock()
return l.cache.Get(key)
}
func (l *lruCache) Add(key string, value interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
l.cache.Add(key, value)
}
func (l *lruCache) Len() int {
l.lock.RLock()
defer l.lock.RUnlock()
return l.cache.Len()
}
func (l *lruCache) Clear() {
l.lock.Lock()
defer l.lock.Unlock()
l.cache.Clear()
}

View file

@ -0,0 +1,52 @@
// Copyright 2021 The Prometheus 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 mappercache
import "github.com/prometheus/client_golang/prometheus"
type CacheMetrics struct {
CacheLength prometheus.Gauge
CacheGetsTotal prometheus.Counter
CacheHitsTotal prometheus.Counter
}
func NewCacheMetrics(reg prometheus.Registerer) *CacheMetrics {
var m CacheMetrics
m.CacheLength = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "statsd_metric_mapper_cache_length",
Help: "The count of unique metrics currently cached.",
},
)
m.CacheGetsTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "statsd_metric_mapper_cache_gets_total",
Help: "The count of total metric cache gets.",
},
)
m.CacheHitsTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "statsd_metric_mapper_cache_hits_total",
Help: "The count of total metric cache hits.",
},
)
if reg != nil {
reg.MustRegister(m.CacheLength)
reg.MustRegister(m.CacheGetsTotal)
reg.MustRegister(m.CacheHitsTotal)
}
return &m
}

View file

@ -0,0 +1,83 @@
// Copyright 2021 The Prometheus 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 randomreplacement
import (
"sync"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/statsd_exporter/pkg/mappercache"
)
type metricMapperRRCache struct {
lock sync.RWMutex
size int
items map[string]interface{}
metrics *mappercache.CacheMetrics
}
func NewMetricMapperRRCache(reg prometheus.Registerer, size int) (*metricMapperRRCache, error) {
if size <= 0 {
return nil, nil
}
metrics := mappercache.NewCacheMetrics(reg)
c := &metricMapperRRCache{
items: make(map[string]interface{}, size+1),
size: size,
metrics: metrics,
}
return c, nil
}
func (m *metricMapperRRCache) Get(metricKey string) (interface{}, bool) {
m.lock.RLock()
result, ok := m.items[metricKey]
m.lock.RUnlock()
return result, ok
}
func (m *metricMapperRRCache) Add(metricKey string, result interface{}) {
go m.trackCacheLength()
m.lock.Lock()
m.items[metricKey] = result
// evict an item if needed
if len(m.items) > m.size {
for k := range m.items {
delete(m.items, k)
break
}
}
m.lock.Unlock()
}
func (m *metricMapperRRCache) Reset() {
m.lock.Lock()
defer m.lock.Unlock()
m.items = make(map[string]interface{}, m.size+1)
m.metrics.CacheLength.Set(0)
}
func (m *metricMapperRRCache) trackCacheLength() {
m.lock.RLock()
length := len(m.items)
m.lock.RUnlock()
m.metrics.CacheLength.Set(float64(length))
}

67
pkg/metrics/metrics.go Normal file
View file

@ -0,0 +1,67 @@
// Copyright 2013 The Prometheus 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 metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
)
type MetricType int
const (
CounterMetricType MetricType = iota
GaugeMetricType
SummaryMetricType
HistogramMetricType
)
type NameHash uint64
type ValueHash uint64
type LabelHash struct {
// This is a hash over the label names
Names NameHash
// This is a hash over the label names + label values
Values ValueHash
}
type MetricHolder interface{}
type VectorHolder interface {
Delete(label prometheus.Labels) bool
}
type Vector struct {
Holder VectorHolder
RefCount uint64
}
type Metric struct {
MetricType MetricType
// Vectors key is the hash of the label names
Vectors map[NameHash]*Vector
// Metrics key is a hash of the label names + label values
Metrics map[ValueHash]*RegisteredMetric
}
type RegisteredMetric struct {
LastRegisteredAt time.Time
Labels prometheus.Labels
TTL time.Duration
Metric MetricHolder
VecKey NameHash
}

428
pkg/registry/registry.go Normal file
View file

@ -0,0 +1,428 @@
// Copyright 2013 The Prometheus 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 registry
import (
"bytes"
"fmt"
"hash"
"hash/fnv"
"sort"
"strings"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/statsd_exporter/pkg/clock"
"github.com/prometheus/statsd_exporter/pkg/mapper"
"github.com/prometheus/statsd_exporter/pkg/metrics"
)
// uncheckedCollector wraps a Collector but its Describe method yields no Desc.
// This allows incoming metrics to have inconsistent label sets
type uncheckedCollector struct {
c prometheus.Collector
}
func (u uncheckedCollector) Describe(_ chan<- *prometheus.Desc) {}
func (u uncheckedCollector) Collect(c chan<- prometheus.Metric) {
u.c.Collect(c)
}
type Registry struct {
Registerer prometheus.Registerer
Metrics map[string]metrics.Metric
Mapper *mapper.MetricMapper
// The below value and label variables are allocated in the registry struct
// so that we don't have to allocate them every time have to compute a label
// hash.
ValueBuf, NameBuf bytes.Buffer
Hasher hash.Hash64
}
func NewRegistry(reg prometheus.Registerer, mapper *mapper.MetricMapper) *Registry {
return &Registry{
Registerer: reg,
Metrics: make(map[string]metrics.Metric),
Mapper: mapper,
Hasher: fnv.New64a(),
}
}
func (r *Registry) MetricConflicts(metricName string, metricType metrics.MetricType) bool {
vector, hasMetrics := r.Metrics[metricName]
if !hasMetrics {
// No metrics.Metric with this name exists
return false
}
if vector.MetricType == metricType {
// We've found a copy of this metrics.Metric with this type, but different
// labels, so it's safe to create a new one.
return false
}
// The metrics.Metric exists, but it's of a different type than we're trying to
// create.
return true
}
func (r *Registry) StoreCounter(metricName string, hash metrics.LabelHash, labels prometheus.Labels, vec *prometheus.CounterVec, c prometheus.Counter, ttl time.Duration) {
r.Store(metricName, hash, labels, vec, c, metrics.CounterMetricType, ttl)
}
func (r *Registry) StoreGauge(metricName string, hash metrics.LabelHash, labels prometheus.Labels, vec *prometheus.GaugeVec, g prometheus.Gauge, ttl time.Duration) {
r.Store(metricName, hash, labels, vec, g, metrics.GaugeMetricType, ttl)
}
func (r *Registry) StoreHistogram(metricName string, hash metrics.LabelHash, labels prometheus.Labels, vec *prometheus.HistogramVec, o prometheus.Observer, ttl time.Duration) {
r.Store(metricName, hash, labels, vec, o, metrics.HistogramMetricType, ttl)
}
func (r *Registry) StoreSummary(metricName string, hash metrics.LabelHash, labels prometheus.Labels, vec *prometheus.SummaryVec, o prometheus.Observer, ttl time.Duration) {
r.Store(metricName, hash, labels, vec, o, metrics.SummaryMetricType, ttl)
}
func (r *Registry) Store(metricName string, hash metrics.LabelHash, labels prometheus.Labels, vh metrics.VectorHolder, mh metrics.MetricHolder, metricType metrics.MetricType, ttl time.Duration) {
metric, hasMetrics := r.Metrics[metricName]
if !hasMetrics {
metric.MetricType = metricType
metric.Vectors = make(map[metrics.NameHash]*metrics.Vector)
metric.Metrics = make(map[metrics.ValueHash]*metrics.RegisteredMetric)
r.Metrics[metricName] = metric
}
v, ok := metric.Vectors[hash.Names]
if !ok {
v = &metrics.Vector{Holder: vh}
metric.Vectors[hash.Names] = v
}
now := clock.Now()
rm, ok := metric.Metrics[hash.Values]
if !ok {
rm = &metrics.RegisteredMetric{
LastRegisteredAt: now,
Labels: labels,
TTL: ttl,
Metric: mh,
VecKey: hash.Names,
}
metric.Metrics[hash.Values] = rm
v.RefCount++
return
}
rm.LastRegisteredAt = now
// Update ttl from mapping
rm.TTL = ttl
}
func (r *Registry) Get(metricName string, hash metrics.LabelHash, metricType metrics.MetricType) (metrics.VectorHolder, metrics.MetricHolder) {
metric, hasMetric := r.Metrics[metricName]
if !hasMetric {
return nil, nil
}
if metric.MetricType != metricType {
return nil, nil
}
rm, ok := metric.Metrics[hash.Values]
if ok {
now := clock.Now()
rm.LastRegisteredAt = now
return metric.Vectors[hash.Names].Holder, rm.Metric
}
vector, ok := metric.Vectors[hash.Names]
if ok {
return vector.Holder, nil
}
return nil, nil
}
func (r *Registry) GetCounter(metricName string, labels prometheus.Labels, help string, mapping *mapper.MetricMapping, metricsCount *prometheus.GaugeVec) (prometheus.Counter, error) {
hash, labelNames := r.HashLabels(labels)
vh, mh := r.Get(metricName, hash, metrics.CounterMetricType)
if mh != nil {
return mh.(prometheus.Counter), nil
}
if r.MetricConflicts(metricName, metrics.CounterMetricType) {
return nil, fmt.Errorf("metric with name %s is already registered", metricName)
}
err := r.checkHistogramNameCollision(metricName)
if err != nil {
return nil, err
}
var counterVec *prometheus.CounterVec
if vh == nil {
metricsCount.WithLabelValues("counter").Inc()
counterVec = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: metricName,
Help: help,
}, labelNames)
if err := r.Registerer.Register(uncheckedCollector{counterVec}); err != nil {
return nil, err
}
} else {
counterVec = vh.(*prometheus.CounterVec)
}
var counter prometheus.Counter
if counter, err = counterVec.GetMetricWith(labels); err != nil {
return nil, err
}
r.StoreCounter(metricName, hash, labels, counterVec, counter, mapping.Ttl)
return counter, nil
}
func (r *Registry) checkHistogramNameCollision(metricName string) error {
histogramSuffixes := []string{"_bucket", "_count", "_sum"}
for _, suffix := range histogramSuffixes {
if strings.HasSuffix(metricName, suffix) {
if r.MetricConflicts(strings.TrimSuffix(metricName, suffix), metrics.CounterMetricType) {
return fmt.Errorf("metric with name %s is already registered", metricName)
}
}
}
return nil
}
func (r *Registry) GetGauge(metricName string, labels prometheus.Labels, help string, mapping *mapper.MetricMapping, metricsCount *prometheus.GaugeVec) (prometheus.Gauge, error) {
hash, labelNames := r.HashLabels(labels)
vh, mh := r.Get(metricName, hash, metrics.GaugeMetricType)
if mh != nil {
return mh.(prometheus.Gauge), nil
}
if r.MetricConflicts(metricName, metrics.GaugeMetricType) {
return nil, fmt.Errorf("metrics.Metric with name %s is already registered", metricName)
}
err := r.checkHistogramNameCollision(metricName)
if err != nil {
return nil, fmt.Errorf("metrics.Metric with name %s is already registered", metricName)
}
var gaugeVec *prometheus.GaugeVec
if vh == nil {
metricsCount.WithLabelValues("gauge").Inc()
gaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: metricName,
Help: help,
}, labelNames)
if err := r.Registerer.Register(uncheckedCollector{gaugeVec}); err != nil {
return nil, err
}
} else {
gaugeVec = vh.(*prometheus.GaugeVec)
}
var gauge prometheus.Gauge
if gauge, err = gaugeVec.GetMetricWith(labels); err != nil {
return nil, err
}
r.StoreGauge(metricName, hash, labels, gaugeVec, gauge, mapping.Ttl)
return gauge, nil
}
func (r *Registry) GetHistogram(metricName string, labels prometheus.Labels, help string, mapping *mapper.MetricMapping, metricsCount *prometheus.GaugeVec) (prometheus.Observer, error) {
hash, labelNames := r.HashLabels(labels)
vh, mh := r.Get(metricName, hash, metrics.HistogramMetricType)
if mh != nil {
return mh.(prometheus.Observer), nil
}
if r.MetricConflicts(metricName, metrics.HistogramMetricType) {
return nil, fmt.Errorf("metrics.Metric with name %s is already registered", metricName)
}
if r.MetricConflicts(metricName+"_sum", metrics.HistogramMetricType) {
return nil, fmt.Errorf("metrics.Metric with name %s is already registered", metricName)
}
if r.MetricConflicts(metricName+"_count", metrics.HistogramMetricType) {
return nil, fmt.Errorf("metrics.Metric with name %s is already registered", metricName)
}
if r.MetricConflicts(metricName+"_bucket", metrics.HistogramMetricType) {
return nil, fmt.Errorf("metrics.Metric with name %s is already registered", metricName)
}
var histogramVec *prometheus.HistogramVec
if vh == nil {
metricsCount.WithLabelValues("histogram").Inc()
buckets := r.Mapper.Defaults.HistogramOptions.Buckets
if mapping.HistogramOptions != nil && len(mapping.HistogramOptions.Buckets) > 0 {
buckets = mapping.HistogramOptions.Buckets
}
bucketFactor := r.Mapper.Defaults.HistogramOptions.NativeHistogramBucketFactor
if mapping.HistogramOptions != nil && mapping.HistogramOptions.NativeHistogramBucketFactor > 0 {
bucketFactor = mapping.HistogramOptions.NativeHistogramBucketFactor
}
maxBuckets := r.Mapper.Defaults.HistogramOptions.NativeHistogramMaxBuckets
if mapping.HistogramOptions != nil && mapping.HistogramOptions.NativeHistogramMaxBuckets > 0 {
maxBuckets = mapping.HistogramOptions.NativeHistogramMaxBuckets
}
histogramVec = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: metricName,
Help: help,
Buckets: buckets,
NativeHistogramBucketFactor: bucketFactor,
NativeHistogramMaxBucketNumber: maxBuckets,
}, labelNames)
if err := r.Registerer.Register(uncheckedCollector{histogramVec}); err != nil {
return nil, err
}
} else {
histogramVec = vh.(*prometheus.HistogramVec)
}
var observer prometheus.Observer
var err error
if observer, err = histogramVec.GetMetricWith(labels); err != nil {
return nil, err
}
r.StoreHistogram(metricName, hash, labels, histogramVec, observer, mapping.Ttl)
return observer, nil
}
func (r *Registry) GetSummary(metricName string, labels prometheus.Labels, help string, mapping *mapper.MetricMapping, metricsCount *prometheus.GaugeVec) (prometheus.Observer, error) {
hash, labelNames := r.HashLabels(labels)
vh, mh := r.Get(metricName, hash, metrics.SummaryMetricType)
if mh != nil {
return mh.(prometheus.Observer), nil
}
if r.MetricConflicts(metricName, metrics.SummaryMetricType) {
return nil, fmt.Errorf("metrics.Metric with name %s is already registered", metricName)
}
if r.MetricConflicts(metricName+"_sum", metrics.SummaryMetricType) {
return nil, fmt.Errorf("metrics.Metric with name %s is already registered", metricName)
}
if r.MetricConflicts(metricName+"_count", metrics.SummaryMetricType) {
return nil, fmt.Errorf("metrics.Metric with name %s is already registered", metricName)
}
var summaryVec *prometheus.SummaryVec
if vh == nil {
metricsCount.WithLabelValues("summary").Inc()
quantiles := r.Mapper.Defaults.SummaryOptions.Quantiles
if mapping != nil && mapping.SummaryOptions != nil && len(mapping.SummaryOptions.Quantiles) > 0 {
quantiles = mapping.SummaryOptions.Quantiles
}
summaryOptions := mapper.SummaryOptions{
MaxAge: r.Mapper.Defaults.SummaryOptions.MaxAge,
AgeBuckets: r.Mapper.Defaults.SummaryOptions.AgeBuckets,
BufCap: r.Mapper.Defaults.SummaryOptions.BufCap,
}
if mapping != nil && mapping.SummaryOptions != nil {
summaryOptions = *mapping.SummaryOptions
}
objectives := make(map[float64]float64)
for _, q := range quantiles {
objectives[q.Quantile] = q.Error
}
// In the case of no mapping file, explicitly define the default quantiles
if len(objectives) == 0 {
objectives = map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}
}
summaryVec = prometheus.NewSummaryVec(prometheus.SummaryOpts{
Name: metricName,
Help: help,
Objectives: objectives,
MaxAge: summaryOptions.MaxAge,
AgeBuckets: summaryOptions.AgeBuckets,
BufCap: summaryOptions.BufCap,
}, labelNames)
if err := r.Registerer.Register(uncheckedCollector{summaryVec}); err != nil {
return nil, err
}
} else {
summaryVec = vh.(*prometheus.SummaryVec)
}
var observer prometheus.Observer
var err error
if observer, err = summaryVec.GetMetricWith(labels); err != nil {
return nil, err
}
r.StoreSummary(metricName, hash, labels, summaryVec, observer, mapping.Ttl)
return observer, nil
}
func (r *Registry) RemoveStaleMetrics() {
now := clock.Now()
// delete timeseries with expired ttl
for _, metric := range r.Metrics {
for hash, rm := range metric.Metrics {
if rm.TTL == 0 {
continue
}
if rm.LastRegisteredAt.Add(rm.TTL).Before(now) {
metric.Vectors[rm.VecKey].Holder.Delete(rm.Labels)
metric.Vectors[rm.VecKey].RefCount--
delete(metric.Metrics, hash)
}
}
}
}
// Calculates a hash of both the label names and values.
func (r *Registry) HashLabels(labels prometheus.Labels) (metrics.LabelHash, []string) {
r.Hasher.Reset()
r.NameBuf.Reset()
r.ValueBuf.Reset()
labelNames := make([]string, 0, len(labels))
for labelName := range labels {
labelNames = append(labelNames, labelName)
}
sort.Strings(labelNames)
r.ValueBuf.WriteByte(model.SeparatorByte)
for _, labelName := range labelNames {
r.ValueBuf.WriteString(labels[labelName])
r.ValueBuf.WriteByte(model.SeparatorByte)
r.NameBuf.WriteString(labelName)
r.NameBuf.WriteByte(model.SeparatorByte)
}
lh := metrics.LabelHash{}
r.Hasher.Write(r.NameBuf.Bytes())
lh.Names = metrics.NameHash(r.Hasher.Sum64())
// Now add the values to the names we've already hashed.
r.Hasher.Write(r.ValueBuf.Bytes())
lh.Values = metrics.ValueHash(r.Hasher.Sum64())
return lh, labelNames
}

167
pkg/relay/relay.go Normal file
View file

@ -0,0 +1,167 @@
// Copyright 2021 The Prometheus 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 relay
import (
"bytes"
"fmt"
"net"
"strings"
"time"
"github.com/prometheus/statsd_exporter/pkg/clock"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/statsd_exporter/pkg/level"
)
type Relay struct {
addr *net.UDPAddr
bufferChannel chan []byte
conn *net.UDPConn
logger log.Logger
packetLength uint
packetsTotal prometheus.Counter
longLinesTotal prometheus.Counter
relayedLinesTotal prometheus.Counter
}
var (
relayPacketsTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "statsd_exporter_relay_packets_total",
Help: "The number of StatsD packets relayed.",
},
[]string{"target"},
)
relayLongLinesTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "statsd_exporter_relay_long_lines_total",
Help: "The number lines that were too long to relay.",
},
[]string{"target"},
)
relayLinesRelayedTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "statsd_exporter_relay_lines_relayed_total",
Help: "The number of lines that were buffered to be relayed.",
},
[]string{"target"},
)
)
// NewRelay creates a statsd UDP relay. It can be used to send copies of statsd raw
// lines to a separate service.
func NewRelay(l log.Logger, target string, packetLength uint) (*Relay, error) {
addr, err := net.ResolveUDPAddr("udp", target)
if err != nil {
return nil, fmt.Errorf("unable to resolve target %s, err: %w", target, err)
}
conn, err := net.ListenUDP("udp", nil)
if err != nil {
return nil, fmt.Errorf("unable to listen on UDP, err: %w", err)
}
c := make(chan []byte, 100)
r := Relay{
addr: addr,
bufferChannel: c,
conn: conn,
logger: l,
packetLength: packetLength,
packetsTotal: relayPacketsTotal.WithLabelValues(target),
longLinesTotal: relayLongLinesTotal.WithLabelValues(target),
relayedLinesTotal: relayLinesRelayedTotal.WithLabelValues(target),
}
// Startup the UDP sender.
go r.relayOutput()
return &r, nil
}
// relayOutput buffers statsd lines and sends them to the relay target.
func (r *Relay) relayOutput() {
var buffer bytes.Buffer
var err error
relayInterval := clock.NewTicker(1 * time.Second)
defer relayInterval.Stop()
for {
select {
case <-relayInterval.C:
err = r.sendPacket(buffer.Bytes())
if err != nil {
level.Error(r.logger).Log("msg", "Error sending UDP packet", "error", err)
return
}
// Clear out the buffer.
buffer.Reset()
case b := <-r.bufferChannel:
if uint(len(b)+buffer.Len()) > r.packetLength {
level.Debug(r.logger).Log("msg", "Buffer full, sending packet", "length", buffer.Len())
err = r.sendPacket(buffer.Bytes())
if err != nil {
level.Error(r.logger).Log("msg", "Error sending UDP packet", "error", err)
return
}
// Seed the new buffer with the new line.
buffer.Reset()
buffer.Write(b)
} else {
level.Debug(r.logger).Log("msg", "Adding line to buffer", "line", string(b))
buffer.Write(b)
}
}
}
}
// sendPacket sends a single relay line to the destination target.
func (r *Relay) sendPacket(buf []byte) error {
if len(buf) == 0 {
level.Debug(r.logger).Log("msg", "Empty buffer, nothing to send")
return nil
}
level.Debug(r.logger).Log("msg", "Sending packet", "length", len(buf), "data", string(buf))
_, err := r.conn.WriteToUDP(buf, r.addr)
r.packetsTotal.Inc()
return err
}
// RelayLine processes a single statsd line and forwards it to the relay target.
func (r *Relay) RelayLine(l string) {
lineLength := uint(len(l))
if lineLength == 0 {
level.Debug(r.logger).Log("msg", "Empty line, not relaying")
return
}
if lineLength > r.packetLength-1 {
level.Warn(r.logger).Log("msg", "line too long, not relaying", "length", lineLength, "max", r.packetLength)
r.longLinesTotal.Inc()
return
}
level.Debug(r.logger).Log("msg", "Relaying line", "line", string(l))
if !strings.HasSuffix(l, "\n") {
l = l + "\n"
}
r.relayedLinesTotal.Inc()
r.bufferChannel <- []byte(l)
}

176
pkg/relay/relay_test.go Normal file
View file

@ -0,0 +1,176 @@
// Copyright 2022 The Prometheus 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 relay
import (
"fmt"
"runtime"
"testing"
"time"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/statsd_exporter/pkg/clock"
"github.com/stvp/go-udp-testing"
)
func TestRelay_RelayLine(t *testing.T) {
type args struct {
lines []string
expected string
}
tests := []struct {
name string
args args
}{
{
name: "multiple lines",
args: args{
lines: []string{"foo5:100|c|#tag1:bar,#tag2:baz", "foo2:200|c|#tag1:bar,#tag2:baz"},
expected: "foo5:100|c|#tag1:bar,#tag2:baz\n",
},
},
}
for _, tt := range tests {
udp.SetAddr(":1160")
t.Run(tt.name, func(t *testing.T) {
tickerCh := make(chan time.Time)
clock.ClockInstance = &clock.Clock{
TickerCh: tickerCh,
}
clock.ClockInstance.Instant = time.Unix(0, 0)
logger := log.NewNopLogger()
r, err := NewRelay(
logger,
"localhost:1160",
200,
)
if err != nil {
t.Errorf("Did not expect error while creating relay.")
}
udp.ShouldReceive(t, tt.args.expected, func() {
for _, line := range tt.args.lines {
r.RelayLine(line)
}
for goSchedTimes := 0; goSchedTimes < 1000; goSchedTimes++ {
if len(r.bufferChannel) == 0 {
break
}
runtime.Gosched()
}
// Tick time forward to trigger a packet send.
clock.ClockInstance.Instant = time.Unix(1, 10)
clock.ClockInstance.TickerCh <- time.Unix(0, 0)
})
metrics, err := prometheus.DefaultGatherer.Gather()
if err != nil {
t.Fatalf("Cannot gather from DefaultGatherer: %v", err)
}
metricNames := map[string]float64{
"statsd_exporter_relay_long_lines_total": 0,
"statsd_exporter_relay_lines_relayed_total": float64(len(tt.args.lines)),
}
for metricName, expectedValue := range metricNames {
metric := getFloat64(metrics, metricName, prometheus.Labels{"target": "localhost:1160"})
if metric == nil {
t.Fatalf("Could not find time series with first label set for metric: %s", metricName)
}
if *metric != expectedValue {
t.Errorf("Expected metric %s to be %f, got %f", metricName, expectedValue, *metric)
}
}
prometheus.Unregister(relayLongLinesTotal)
prometheus.Unregister(relayLinesRelayedTotal)
})
}
}
// getFloat64 search for metric by name in array of MetricFamily and then search a value by labels.
// Method returns a value or nil if metric is not found.
func getFloat64(metrics []*dto.MetricFamily, name string, labels prometheus.Labels) *float64 {
var metricFamily *dto.MetricFamily
for _, m := range metrics {
if *m.Name == name {
metricFamily = m
break
}
}
if metricFamily == nil {
return nil
}
var metric *dto.Metric
labelStr := fmt.Sprintf("%v", labels)
for _, m := range metricFamily.Metric {
l := labelPairsAsLabels(m.GetLabel())
ls := fmt.Sprintf("%v", l)
if labelStr == ls {
metric = m
break
}
}
if metric == nil {
return nil
}
var value float64
if metric.Gauge != nil {
value = metric.Gauge.GetValue()
return &value
}
if metric.Counter != nil {
value = metric.Counter.GetValue()
return &value
}
if metric.Histogram != nil {
value = metric.Histogram.GetSampleSum()
return &value
}
if metric.Summary != nil {
value = metric.Summary.GetSampleSum()
return &value
}
if metric.Untyped != nil {
value = metric.Untyped.GetValue()
return &value
}
panic(fmt.Errorf("collected a non-gauge/counter/histogram/summary/untyped metric: %s", metric))
}
func labelPairsAsLabels(pairs []*dto.LabelPair) (labels prometheus.Labels) {
labels = prometheus.Labels{}
for _, pair := range pairs {
if pair.Name == nil {
continue
}
value := ""
if pair.Value != nil {
value = *pair.Value
}
labels[*pair.Name] = value
}
return
}

View file

@ -1,53 +0,0 @@
// Copyright 2013 The Prometheus 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 (
"github.com/prometheus/client_golang/prometheus"
)
var (
eventStats = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "statsd_bridge_events_total",
Help: "The total number of StatsD events seen.",
},
[]string{"type"},
)
networkStats = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "statsd_bridge_packets_total",
Help: "The total number of StatsD packets seen.",
},
[]string{"type"},
)
configLoads = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "statsd_bridge_config_reloads_total",
Help: "The number of configuration reloads.",
},
[]string{"outcome"},
)
mappingsCount = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "statsd_bridge_loaded_mappings_count",
Help: "The number of configured metric mappings.",
})
)
func init() {
prometheus.MustRegister(eventStats)
prometheus.MustRegister(networkStats)
prometheus.MustRegister(configLoads)
prometheus.MustRegister(mappingsCount)
}