Skip to content
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.

Commit

Permalink
#112 escaping tag values in es reporter, this should move to part of …
Browse files Browse the repository at this point in the history
…the payload builder
  • Loading branch information
alhardy committed Apr 15, 2017
1 parent 8fa338c commit 6847781
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public void Add(MetricsDocument document)
{
if (document == null)
{
throw new ArgumentNullException(nameof(document));
return;
}

_documents.Add(document);
}

public void Write(TextWriter textWriter)
public void Format(TextWriter textWriter)
{
if (textWriter == null)
{
throw new ArgumentNullException(nameof(textWriter));
return;
}

foreach (var document in _documents)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void Pack(string name, object value, MetricTags tags)
public string PayloadFormatted()
{
var result = new StringWriter();
_payload.Write(result);
_payload.Format(result);
return result.ToString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class ElasticSearchBulkClient
}

var writer = new StringWriter();
payload.Write(writer);
payload.Format(writer);
var content = new StringContent(writer.ToString(), Encoding.UTF8, "application/json");

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public ElasticSearchReporterSettings()
MetricNameFormatter = (metricContext, metricName) => string.IsNullOrWhiteSpace(metricContext)
? $"{metricName}".Replace(' ', '_').ToLowerInvariant()
: $"{metricContext}__{metricName}".Replace(' ', '_').ToLowerInvariant();
MetricTagValueFormatter = tagValue => tagValue.Replace(' ', '_');
MetricTagValueFormatter = tagValue => tagValue.Replace("=", "\\=")
.Replace(" ", "\\ ")
.Replace(@"\", @"\\\")
.Replace(",", "\\,");
}

/// <summary>
Expand Down

0 comments on commit 6847781

Please sign in to comment.