diff --git a/Graphite/Base/SeriesListBase.cs b/Graphite/Base/SeriesListBase.cs
index 172ba17..fe7499d 100644
--- a/Graphite/Base/SeriesListBase.cs
+++ b/Graphite/Base/SeriesListBase.cs
@@ -964,7 +964,7 @@ public SeriesListFunction WeightedAverage(SeriesListBase seriesListWeight, param
///
/// allows the metric paths to contain named variables.
- /// Variable values can be specified or overriden in
+ /// Variable values can be specified or overriden in
///
/// default values for the template variables
///
@@ -975,7 +975,7 @@ public SeriesListFunction Template(params Tuple[] defaultValues)
///
/// allows the metric paths to contain positional variables.
- /// Variable values can be specified or overriden in
+ /// Variable values can be specified or overriden in
///
/// default values for the template variables
///
diff --git a/Graphite/GraphiteClient.cs b/Graphite/GraphiteClient.cs
index 59a3b31..1d15ad3 100644
--- a/Graphite/GraphiteClient.cs
+++ b/Graphite/GraphiteClient.cs
@@ -251,14 +251,15 @@ private void SendInternal(ICollection datapoints)
///
/// Walks the metrics tree and returns every metric found as a sorted JSON array
///
+ /// The token to monitor for cancellation requests. The default value is .
/// list of all metrics
- public async Task GetAllMetricsAsync()
+ public async Task GetAllMetricsAsync(CancellationToken cancellationToken = default(CancellationToken))
{
using (var client = new HttpClient {BaseAddress = GetHttpApiUri()})
{
- var response = await client.GetAsync("/metrics/index.json").ConfigureAwait(false);
+ var response = await client.GetAsync("/metrics/index.json", cancellationToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeAsync().ConfigureAwait(false);
- return await response.Content.ReadAsAsync().ConfigureAwait(false);
+ return await response.Content.ReadAsAsync(cancellationToken).ConfigureAwait(false);
}
}
@@ -269,8 +270,9 @@ public async Task GetAllMetricsAsync()
/// Whether to add a wildcard result at the end or not
/// timestamp from which to consider metrics
/// timestamp until which to consider metrics
+ /// The token to monitor for cancellation requests. The default value is .
///
- public async Task FindMetricsAsync(string query, bool wildcards = false, DateTime? from = null, DateTime? until = null)
+ public async Task FindMetricsAsync(string query, bool wildcards = false, DateTime? from = null, DateTime? until = null, CancellationToken cancellationToken = default(CancellationToken))
{
if (String.IsNullOrEmpty(query)) throw new ArgumentNullException(nameof(query));
@@ -287,9 +289,9 @@ public async Task FindMetricsAsync(string query, bool wildcard
var uri = String.Format("/metrics/find?query={0}&format=completer&wildcards={1}&from={2}&until={3}",
query, wildcards ? 1 : 0, fromUnix, untilUnix);
- var response = await client.GetAsync(uri).ConfigureAwait(false);
+ var response = await client.GetAsync(uri, cancellationToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeAsync().ConfigureAwait(false);
- return (await response.Content.ReadAsAsync().ConfigureAwait(false)).Metrics;
+ return (await response.Content.ReadAsAsync(cancellationToken).ConfigureAwait(false)).Metrics;
}
}
@@ -300,16 +302,28 @@ public async Task FindMetricsAsync(string query, bool wildcard
/// list of matching metric names
public Task ExpandMetricsAsync(params GraphitePath[] query)
{
- return ExpandMetricsAsync(false, query);
+ return ExpandMetricsAsync(false, CancellationToken.None, query);
+ }
+
+ ///
+ /// Expands the given query with matching paths
+ ///
+ /// The token to monitor for cancellation requests.
+ /// The metrics query
+ /// list of matching metric names
+ public Task ExpandMetricsAsync(CancellationToken cancellationToken, params GraphitePath[] query)
+ {
+ return ExpandMetricsAsync(false, cancellationToken, query);
}
///
/// Expands the given query with matching paths
///
/// Whether to only return leaves or both branches and leaves
+ /// The token to monitor for cancellation requests.
/// The metrics query
/// list of matching metric names
- public async Task ExpandMetricsAsync(bool leavesOnly, params GraphitePath[] query)
+ public async Task ExpandMetricsAsync(bool leavesOnly, CancellationToken cancellationToken, params GraphitePath[] query)
{
if (query == null || query.Length == 0) throw new ArgumentNullException(nameof(query));
@@ -325,9 +339,9 @@ public async Task ExpandMetricsAsync(bool leavesOnly, params GraphiteP
}
var body = new FormUrlEncodedContent(values);
- var response = await client.PostAsync("/metrics/expand", body).ConfigureAwait(false);
+ var response = await client.PostAsync("/metrics/expand", body, cancellationToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeAsync().ConfigureAwait(false);
- return (await response.Content.ReadAsAsync().ConfigureAwait(false)).Results;
+ return (await response.Content.ReadAsAsync(cancellationToken).ConfigureAwait(false)).Results;
}
}
@@ -347,10 +361,11 @@ private Uri GetHttpApiUri()
/// specify the relative or absolute end to graph
/// The target metrics can use a special function which allows the metric paths to contain variables
///
+ /// The token to monitor for cancellation requests. The default value is .
///
- public Task GetMetricsDataAsync(SeriesListBase target, string from = null, string until = null, IDictionary template = null, ulong? maxDataPoints = null)
+ public Task GetMetricsDataAsync(SeriesListBase target, string from = null, string until = null, IDictionary template = null, ulong? maxDataPoints = null, CancellationToken cancellationToken = default(CancellationToken))
{
- return GetMetricsDataAsync(new[] {target}, from, until, template, maxDataPoints);
+ return GetMetricsDataAsync(new[] {target}, from, until, template, maxDataPoints, cancellationToken);
}
///
@@ -361,8 +376,9 @@ public Task GetMetricsDataAsync(SeriesListBase target, str
/// specify the relative or absolute end to graph
/// The target metrics can use a special function which allows the metric paths to contain variables
///
+ /// The token to monitor for cancellation requests. The default value is .
///
- public async Task GetMetricsDataAsync(SeriesListBase[] targets, string from = null, string until = null, IDictionary template = null, ulong? maxDataPoints = null)
+ public async Task GetMetricsDataAsync(SeriesListBase[] targets, string from = null, string until = null, IDictionary template = null, ulong? maxDataPoints = null, CancellationToken cancellationToken = default(CancellationToken))
{
if (targets == null || targets.Length == 0) throw new ArgumentNullException(nameof(targets));
@@ -408,10 +424,10 @@ public async Task GetMetricsDataAsync(SeriesListBase[] tar
}
var body = new StringContent(sb.ToString(), Encoding.UTF8, "application/x-www-form-urlencoded");
- var response = await client.PostAsync("/render",body).ConfigureAwait(false);
+ var response = await client.PostAsync("/render",body, cancellationToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeAsync().ConfigureAwait(false);
- return await response.Content.ReadAsAsync().ConfigureAwait(false);
+ return await response.Content.ReadAsAsync(cancellationToken).ConfigureAwait(false);
}
}
}