mirror of
https://github.com/lukaszraczylo/oss-telemetry.git
synced 2026-10-12 00:45:30 +00:00
fix: make internals yaegi-interpretable for traefik plugin consumers
Swap atomic.Pointer[string] for a mutex-guarded string, atomic.Bool for the function-based sync/atomic int32 API, two range-over-int loops for classic index loops, and drop the init() that seeded the endpoint pointer. No public API or runtime behaviour change; go test, go vet, and golangci-lint all pass. Rationale: the traefikoidc Traefik plugin vendors and interprets dependency source via Yaegi, which on several Traefik runtimes cannot interpret generic stdlib types or range-over-int. This keeps the package importable from that plugin without altering what it does.
This commit is contained in:
+8
-9
@@ -25,22 +25,21 @@ type pingPayload struct {
|
||||
// each other. Tests share `disabled`, `endpoint`, and `inflight`.
|
||||
func resetState(t *testing.T) {
|
||||
t.Helper()
|
||||
disabled.Store(false)
|
||||
atomic.StoreInt32(&disabled, 0)
|
||||
t.Cleanup(func() {
|
||||
disabled.Store(false)
|
||||
atomic.StoreInt32(&disabled, 0)
|
||||
})
|
||||
}
|
||||
|
||||
// setEndpoint atomically retargets the ingest URL for the duration of a test
|
||||
// and restores it on cleanup. Safe even if Send goroutines outlive the test.
|
||||
// setEndpoint retargets the ingest URL for the duration of a test and restores
|
||||
// it on cleanup. Safe even if Send goroutines outlive the test (the setter is
|
||||
// mutex-guarded).
|
||||
func setEndpoint(t *testing.T, url string) {
|
||||
t.Helper()
|
||||
prev := *endpoint.Load()
|
||||
s := url
|
||||
endpoint.Store(&s)
|
||||
prev := currentEndpoint()
|
||||
setEndpointURL(url)
|
||||
t.Cleanup(func() {
|
||||
p := prev
|
||||
endpoint.Store(&p)
|
||||
setEndpointURL(prev)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user