snapshotMetricsRegistryForTesting snapshots the global data of the metrics registry. Returns a cleanup function that sets the metrics registry to its original state.
()
| 325 | // registry. Returns a cleanup function that sets the metrics registry to its |
| 326 | // original state. |
| 327 | func snapshotMetricsRegistryForTesting() func() { |
| 328 | oldDefaultMetrics := DefaultMetrics |
| 329 | oldRegisteredMetrics := registeredMetrics |
| 330 | oldMetricsRegistry := metricsRegistry |
| 331 | |
| 332 | registeredMetrics = make(map[string]bool) |
| 333 | metricsRegistry = make(map[string]*MetricDescriptor) |
| 334 | maps.Copy(registeredMetrics, registeredMetrics) |
| 335 | maps.Copy(metricsRegistry, metricsRegistry) |
| 336 | |
| 337 | return func() { |
| 338 | DefaultMetrics = oldDefaultMetrics |
| 339 | registeredMetrics = oldRegisteredMetrics |
| 340 | metricsRegistry = oldMetricsRegistry |
| 341 | } |
| 342 | } |