diff --git a/tests/MySqlConnector.Tests/Metrics/MetricsTestsBase.cs b/tests/MySqlConnector.Tests/Metrics/MetricsTestsBase.cs index 3d2549e1e..f35753d93 100644 --- a/tests/MySqlConnector.Tests/Metrics/MetricsTestsBase.cs +++ b/tests/MySqlConnector.Tests/Metrics/MetricsTestsBase.cs @@ -1,7 +1,5 @@ #nullable enable -using System.Diagnostics.Metrics; - namespace MySqlConnector.Tests.Metrics; public abstract class MetricsTestsBase : IDisposable @@ -13,18 +11,6 @@ public MetricsTestsBase() Server = new FakeMySqlServer(); Server.Start(); - - m_meterListener = new MeterListener - { - InstrumentPublished = (instrument, listener) => - { - if (instrument.Meter.Name == "MySqlConnector") - listener.EnableMeasurementEvents(instrument); - } - }; - m_meterListener.SetMeasurementEventCallback(OnMeasurementRecorded); - m_meterListener.SetMeasurementEventCallback(OnMeasurementRecorded); - m_meterListener.Start(); } public void Dispose() @@ -37,7 +23,6 @@ protected virtual void Dispose(bool disposing) { if (disposing) { - m_meterListener.Dispose(); Server.Stop(); } } @@ -68,50 +53,6 @@ protected List GetAndClearMeasurements(string name) return list; } - private void OnMeasurementRecorded(Instrument instrument, int measurement, ReadOnlySpan> tags, object? state) - { - var (poolName, stateTag) = GetTags(tags); - if (poolName != PoolName) - return; - - lock (m_measurements) - { - m_measurements[instrument.Name] = m_measurements.GetValueOrDefault(instrument.Name) + measurement; - if (stateTag.Length != 0) - m_measurements[$"{instrument.Name}|{stateTag}"] = m_measurements.GetValueOrDefault($"{instrument.Name}|{stateTag}") + measurement; - } - } - - private void OnMeasurementRecorded(Instrument instrument, float measurement, ReadOnlySpan> tags, object? state) - { - var (poolName, stateTag) = GetTags(tags); - if (poolName != PoolName) - return; - - lock (m_timeMeasurements) - { - if (!m_timeMeasurements.TryGetValue(instrument.Name, out var list)) - list = m_timeMeasurements[instrument.Name] = new List(); - list.Add(measurement); - } - } - - private (string PoolName, string State) GetTags(ReadOnlySpan> tags) - { - var poolName = ""; - var state = ""; - foreach (var tag in tags) - { - if (tag.Key == "pool.name" && tag.Value is string s1) - poolName = s1; - else if (tag.Key == "state" && tag.Value is string s2) - state = s2; - } - return (poolName, state); - } - - private readonly Dictionary m_measurements; private readonly Dictionary> m_timeMeasurements; - private readonly MeterListener m_meterListener; }