promhttp: add regression test for concurrent map writes (#1274) (#2000)
- promhttp: add regression test for concurrent map writes (#1274)
Without the fix in #1318, instrumenting a metric vec partitioned only by labels supplied via WithLabelFromCtx (i.e. with no “code” or “method” label) would cause concurrent requests to share and mutate a single ‘emptyLabels’ map, producing ‘fatal error: concurrent map writes’ under load. The fix made labels() allocate a fresh map per call but no regression test was added at the time.
This adds a test that exercises both InstrumentHandlerCounter and InstrumentHandlerDuration from many goroutines so the bug would be caught either by the race detector or the runtime’s concurrent-map- writes detection.
Verified: the test fails (DATA RACE / concurrent map writes panic) when the pre-#1318 labels() implementation is reintroduced, and passes on current main with ‘go test -race’.
Closes #1274
Signed-off-by: Pedram pedram@arpdigital.io
- Update prometheus/promhttp/instrument_server_test.go
Co-authored-by: Bartlomiej Plotka bwplotka@gmail.com Signed-off-by: Pedram Pd eragon.pedy@gmail.com
Signed-off-by: Pedram pedram@arpdigital.io Signed-off-by: Pedram Pd eragon.pedy@gmail.com Co-authored-by: Pedram pedram@arpdigital.io Co-authored-by: Bartlomiej Plotka bwplotka@gmail.com
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
Prometheus Go client library
This is the Go client library for Prometheus. It has two separate parts, one for instrumenting application code, and one for creating clients that talk to the Prometheus HTTP API.
Version Compatibility
This library supports the two most recent major releases of Go. While it may function with older versions, we only provide fixes and support for the currently supported Go releases.
Important note about releases and stability
This repository generally follows Semantic Versioning. However, the API client in
prometheus/client_golang/api/…is still considered experimental. Breaking changes of the API client will not trigger a new major release. The same is true for selected other new features explicitly marked as EXPERIMENTAL in CHANGELOG.md.Features that require breaking changes in the stable parts of the repository are being batched up and tracked in the v2 milestone, but plans for further development of v2 at the moment.
Instrumenting applications
The
prometheusdirectory contains the instrumentation library. See the guide on the Prometheus website to learn more about instrumenting applications.The
examplesdirectory contains simple examples of instrumented code.Client for the Prometheus HTTP API
The
api/prometheusdirectory contains the client for the Prometheus HTTP API. It allows you to write Go applications that query time series data from a Prometheus server. It is still in alpha stage.Where is
model,extraction, andtext?The
modelpackages has been moved toprometheus/common/model.The
extractionandtextpackages are now contained inprometheus/common/expfmt.Contributing and community
See the contributing guidelines and the Community section of the homepage.
client_golangcommunity is also present on the CNCF Slack#prometheus-client_golang.