Skip to content

Commit

Permalink
Add labels for metrics (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
polomani authored Nov 9, 2021
1 parent a042b07 commit f961a5d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/HttpHandler/Fetch.fs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ module Fetch =
try
use request = buildRequest client ctx
timer.Start()
ctx.Request.Metrics.Counter Metric.FetchInc Map.empty 1L
ctx.Request.Metrics.Counter Metric.FetchInc ctx.Request.Labels 1L

let! response = client.SendAsync(request, ctx.Request.CompletionMode, cancellationToken)
timer.Stop()

ctx.Request.Metrics.Gauge
Metric.FetchLatencyUpdate
Map.empty
ctx.Request.Labels
(float timer.ElapsedMilliseconds)

let items =
Expand Down
4 changes: 4 additions & 0 deletions src/HttpHandler/HttpContext.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Oryx

open System
open System.Collections
open System.Diagnostics
open System.Net
open System.Net.Http
Expand Down Expand Up @@ -83,6 +84,8 @@ and HttpRequest =
LogFormat: string
/// Optional Metrics for recording metrics.
Metrics: IMetrics
/// Optional Labels to label the request
Labels: Generic.IDictionary<string, string>
/// Extra state used to e.g build the URL. Clients are free to utilize this property for adding extra
/// information to the context.
Items: Map<string, Value>
Expand Down Expand Up @@ -129,6 +132,7 @@ module HttpContext =
LogLevel = LogLevel.None
LogFormat = defaultLogFormat
Metrics = EmptyMetrics()
Labels = dict []
Items = Map.empty
CompletionMode = HttpCompletionOption.ResponseContentRead }

Expand Down
6 changes: 3 additions & 3 deletions src/HttpHandler/HttpHandler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ module HttpHandler =
let item = parser stream
return! next.OnNextAsync(ctx, item)
with ex ->
ctx.Request.Metrics.Counter Metric.DecodeErrorInc Map.empty 1L
ctx.Request.Metrics.Counter Metric.DecodeErrorInc ctx.Request.Labels 1L
return! next.OnErrorAsync(ctx, ex)
}

Expand All @@ -126,7 +126,7 @@ module HttpHandler =
let! item = parser stream
return! next.OnNextAsync(ctx, item)
with ex ->
ctx.Request.Metrics.Counter Metric.DecodeErrorInc Map.empty 1L
ctx.Request.Metrics.Counter Metric.DecodeErrorInc ctx.Request.Labels 1L
return! next.OnErrorAsync(ctx, ex)
}

Expand Down Expand Up @@ -315,7 +315,7 @@ module HttpHandler =
match response.IsSuccessStatusCode with
| true -> return! next.OnNextAsync(ctx, content = content)
| false ->
ctx.Request.Metrics.Counter Metric.FetchErrorInc Map.empty 1L
ctx.Request.Metrics.Counter Metric.FetchErrorInc ctx.Request.Labels 1L

let! err = errorHandler response content
return! next.OnErrorAsync(ctx, err)
Expand Down

0 comments on commit f961a5d

Please sign in to comment.