Skip to content

Commit

Permalink
array of tags instead of enumerable
Browse files Browse the repository at this point in the history
  • Loading branch information
hunter1703 committed May 10, 2023
1 parent 6d1bf1a commit 92297cc
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/EventStore.Core.XUnit.Tests/Index/IndexTrackerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class IndexTrackerTests : IDisposable {
_listener = new TestMeterListener<long>(meter);

var eventMetric = new CounterMetric(meter, "eventstore-io", "events");
_sut = new IndexTracker(new CounterSubmetric(eventMetric, new[] {new KeyValuePair<string, object>("activity", "written")}));
_sut = new IndexTracker(new CounterSubMetric(eventMetric, new[] {new KeyValuePair<string, object>("activity", "written")}));
}

public void Dispose() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class TFChunkTrackerTests : IDisposable {

var readTag = new KeyValuePair<string, object>("activity", "read");
_sut = new TFChunkTracker(
readBytes: new CounterSubmetric(byteMetric, new[] {readTag}),
readEvents: new CounterSubmetric(eventMetric, new[] {readTag}));
readBytes: new CounterSubMetric(byteMetric, new[] {readTag}),
readEvents: new CounterSubMetric(eventMetric, new[] {readTag}));
}

public void Dispose() {
Expand Down
4 changes: 2 additions & 2 deletions src/EventStore.Core/Index/IndexTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public interface IIndexTracker {
}

public class IndexTracker : IIndexTracker {
private readonly CounterSubmetric _indexedEvents;
private readonly CounterSubMetric _indexedEvents;

public IndexTracker(CounterSubmetric indexedEvents) {
public IndexTracker(CounterSubMetric indexedEvents) {
_indexedEvents = indexedEvents;
}

Expand Down
6 changes: 3 additions & 3 deletions src/EventStore.Core/MetricsBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ public static class MetricsBootstrapper {
if (conf.Events.TryGetValue(Conf.EventTracker.Read, out var readEnabled) && readEnabled) {
var readTag = new KeyValuePair<string, object>("activity", "read");
trackers.TransactionFileTracker = new TFChunkTracker(
readBytes: new CounterSubmetric(byteMetric, new[] {readTag}),
readEvents: new CounterSubmetric(eventMetric, new[] {readTag}));
readBytes: new CounterSubMetric(byteMetric, new[] {readTag}),
readEvents: new CounterSubMetric(eventMetric, new[] {readTag}));
}

// from a users perspective an event is written when it is indexed: thats when it can be read.
if (conf.Events.TryGetValue(Conf.EventTracker.Written, out var writtenEnabled) && writtenEnabled) {
trackers.IndexTracker = new IndexTracker(new CounterSubmetric(
trackers.IndexTracker = new IndexTracker(new CounterSubMetric(
eventMetric,
new[] {new KeyValuePair<string, object>("activity", "written")}));
}
Expand Down
10 changes: 5 additions & 5 deletions src/EventStore.Core/Telemetry/CounterMetric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

namespace EventStore.Core.Telemetry {
public class CounterMetric {
private readonly List<CounterSubmetric> _submetrics = new();
private readonly List<CounterSubMetric> _subMetrics = new();
private readonly object _lock = new();

public CounterMetric(Meter meter, string name, string unit = null) {
meter.CreateObservableCounter(name, Observe, unit);
}

public void Add(CounterSubmetric submetric) {
public void Add(CounterSubMetric subMetric) {
lock (_lock) {
_submetrics.Add(submetric);
_subMetrics.Add(subMetric);
}
}

private IEnumerable<Measurement<long>> Observe() {
lock (_lock) {
foreach (CounterSubmetric submetric in _submetrics) {
yield return submetric.Observe();
foreach (CounterSubMetric subMetric in _subMetrics) {
yield return subMetric.Observe();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

namespace EventStore.Core.Telemetry;

public class CounterSubmetric {
private readonly IEnumerable<KeyValuePair<string, object>> _tags;
public class CounterSubMetric {
private readonly KeyValuePair<string, object>[] _tags;
private long _counter;

public CounterSubmetric(CounterMetric metric, IEnumerable<KeyValuePair<string, object>> tags) {
public CounterSubMetric(CounterMetric metric, KeyValuePair<string, object>[] tags) {
_tags = tags;
metric.Add(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace EventStore.Core.TransactionLog.Chunks;

public class TFChunkTracker : ITransactionFileTracker {
private readonly CounterSubmetric _readBytes;
private readonly CounterSubmetric _readEvents;
private readonly CounterSubMetric _readBytes;
private readonly CounterSubMetric _readEvents;

public TFChunkTracker(
CounterSubmetric readBytes,
CounterSubmetric readEvents) {
CounterSubMetric readBytes,
CounterSubMetric readEvents) {

_readBytes = readBytes;
_readEvents = readEvents;
Expand Down

0 comments on commit 92297cc

Please sign in to comment.