Skip to content

Commit

Permalink
#143 bugfix allowing overriding metric name formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
alhardy committed May 25, 2017
1 parent bbdd780 commit fb32a7f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class AsciiMetricPayloadBuilder : IMetricPayloadBuilder<AsciiMetricPayloa
public AsciiMetricPayloadBuilder(Func<string, string, string> metricNameFormatter = null, MetricValueDataKeys dataKeys = null)
{
_payload = new AsciiMetricPayload();
if (_metricNameFormatter == null)
if (metricNameFormatter == null)
{
_metricNameFormatter = (metricContext, metricName) => metricContext.IsMissing()
? metricName
Expand Down
16 changes: 16 additions & 0 deletions test/App.Metrics.Facts/Formatting/AsciiFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,21 @@ public void can_apply_ascii_metric_formatting()
// Assert
payloadBuilder.PayloadFormatted().Should().Be("# MEASUREMENT: [test] counter1\n# TAGS:\n mtype = counter\n# FIELDS:\n value = 1\n--------------------------------------------------------------\n");
}

[Fact]
public void can_apply_ascii_metric_formatting_with_custom_name_formatter()
{
// Arrange
var counter = new CounterOptions { Context = "test", Name = "counter1" };
var formatter = new MetricDataValueSourceFormatter();
var payloadBuilder = new AsciiMetricPayloadBuilder((context, name) => $"{context}---{name}");

// Act
_fixture.Metrics.Measure.Counter.Increment(counter);
formatter.Build(_fixture.Metrics.Snapshot.Get(), payloadBuilder);

// Assert
payloadBuilder.PayloadFormatted().Should().Be("# MEASUREMENT: test---counter1\n# TAGS:\n mtype = counter\n# FIELDS:\n value = 1\n--------------------------------------------------------------\n");
}
}
}

0 comments on commit fb32a7f

Please sign in to comment.