-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
Metric.make
to support ad hoc metrics
- Loading branch information
Showing
5 changed files
with
50 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,20 @@ | ||
type t = Yojson.Safe.t | ||
|
||
let to_nonbreaking s = | ||
s |> String.split_on_char ' ' |> String.concat " " (* a non-breaking space *) | ||
|
||
let name ~metric ~config = to_nonbreaking (metric ^ "/" ^ config) | ||
|
||
let make ~metric ~config ~value ?units ?trend ?description () = | ||
let[@inline] ( @: ) x_opt xs = | ||
match x_opt with None -> xs | Some x -> x :: xs | ||
in | ||
`Assoc | ||
(Some ("name", `String (name ~metric ~config)) | ||
@: Some ("value", `Float value) | ||
@: Option.map (fun units -> ("units", `String units)) units | ||
@: Option.map (fun trend -> ("trend", Trend.to_json trend)) trend | ||
@: Option.map | ||
(fun description -> ("description", `String description)) | ||
description | ||
@: []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type t = [ `Lower_is_better | `Higher_is_better ] | ||
|
||
let to_json = function | ||
| `Lower_is_better -> `String "lower-is-better" | ||
| `Higher_is_better -> `String "higher-is-better" |