Tutorial
This tutorial is not yet complete, but here is an example of using the healthcheck functionality with Suave
.
In each of these examples, it is presumed that your existing Suave
application is bound to myApp
.
1: 2: 3: 4: 5: |
|
You can also choose the endpoint at which you would like your healthchecks reported, as in the following example:
1: 2: 3: |
|
By using prefixWithHealthcheck
or prefixWithHealthcheckAt
, the healthcheck functions will attach as a prefix to myApp
.
This means that if there is any request to the healthcheck endpoint, it will be handled by the healthcheck service. Requests
to this endpoint that are invalid (such as POST
s) will be handled by returning an appropriate response (such as a 405 METHOD NOT ALLOWED
)
instead of passing the context to myApp
.
In this way, you can choose to attach multiple healthchecks for services hosted by the same instance:
1: 2: 3: 4: 5: 6: 7: |
|
If you'd prefer to have greater control where in your routing table the healthcheck handler appears, you can use
handleHealthcheck
or handleHealthcheckAt
instead.
1: 2: 3: 4: |
|
Healthcheck evaluation
When a healthcheck is evaluated it will return a result indicating the current health of the service:
1:
|
|
|
If we then disable the main server switch and re-evaluate the healthcheck that check will now evaluate to Unhealthy
.
1: 2: |
|
|
The evaluation of a set of healthchecks together creates an aggregate healthcheck result:
1: 2: 3: 4: 5: 6: 7: |
|
|
This result gets serialized to JSON and returned to the client with the appropriate HTTP status
|
from Suave
from Cimfu.Suave
Full name: Tutorial.myApp
Full name: Tutorial.hcMap
module Map
from Microsoft.FSharp.Collections
--------------------
type Map<'Key,'Value (requires comparison)> =
interface IEnumerable
interface IComparable
interface IEnumerable<KeyValuePair<'Key,'Value>>
interface ICollection<KeyValuePair<'Key,'Value>>
interface IDictionary<'Key,'Value>
new : elements:seq<'Key * 'Value> -> Map<'Key,'Value>
member Add : key:'Key * value:'Value -> Map<'Key,'Value>
member ContainsKey : key:'Key -> bool
override Equals : obj -> bool
member Remove : key:'Key -> Map<'Key,'Value>
...
Full name: Microsoft.FSharp.Collections.Map<_,_>
--------------------
new : elements:seq<'Key * 'Value> -> Map<'Key,'Value>
Full name: Microsoft.FSharp.Collections.Map.ofList
from Cimfu.Suave.Healthcheck
Full name: Cimfu.Suave.Healthcheck.Checks.serverMain
Full name: Tutorial.app
Full name: Cimfu.Suave.Healthcheck.prefixWithHealthcheck
Full name: Tutorial.appAtAltAddress
Full name: Cimfu.Suave.Healthcheck.prefixWithHealthcheckAt
Full name: Tutorial.service1Hc
Full name: Cimfu.Suave.Healthcheck.Checks.alwaysHealthy
Full name: Tutorial.service2Hc
Full name: Cimfu.Suave.Healthcheck.Checks.alwaysUnhealthy
Full name: Tutorial.appWithTwoServices
Full name: Tutorial.appUsingHandler
Full name: Cimfu.Suave.Healthcheck.handleHealthcheckAt
Full name: Tutorial.result
type Async
static member AsBeginEnd : computation:('Arg -> Async<'T>) -> ('Arg * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * (IAsyncResult -> unit)
static member AwaitEvent : event:IEvent<'Del,'T> * ?cancelAction:(unit -> unit) -> Async<'T> (requires delegate and 'Del :> Delegate)
static member AwaitIAsyncResult : iar:IAsyncResult * ?millisecondsTimeout:int -> Async<bool>
static member AwaitTask : task:Task -> Async<unit>
static member AwaitTask : task:Task<'T> -> Async<'T>
static member AwaitWaitHandle : waitHandle:WaitHandle * ?millisecondsTimeout:int -> Async<bool>
static member CancelDefaultToken : unit -> unit
static member Catch : computation:Async<'T> -> Async<Choice<'T,exn>>
static member FromBeginEnd : beginAction:(AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg:'Arg1 * beginAction:('Arg1 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg1:'Arg1 * arg2:'Arg2 * beginAction:('Arg1 * 'Arg2 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg1:'Arg1 * arg2:'Arg2 * arg3:'Arg3 * beginAction:('Arg1 * 'Arg2 * 'Arg3 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromContinuations : callback:(('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) -> unit) -> Async<'T>
static member Ignore : computation:Async<'T> -> Async<unit>
static member OnCancel : interruption:(unit -> unit) -> Async<IDisposable>
static member Parallel : computations:seq<Async<'T>> -> Async<'T []>
static member RunSynchronously : computation:Async<'T> * ?timeout:int * ?cancellationToken:CancellationToken -> 'T
static member Sleep : millisecondsDueTime:int -> Async<unit>
static member Start : computation:Async<unit> * ?cancellationToken:CancellationToken -> unit
static member StartAsTask : computation:Async<'T> * ?taskCreationOptions:TaskCreationOptions * ?cancellationToken:CancellationToken -> Task<'T>
static member StartChild : computation:Async<'T> * ?millisecondsTimeout:int -> Async<Async<'T>>
static member StartChildAsTask : computation:Async<'T> * ?taskCreationOptions:TaskCreationOptions -> Async<Task<'T>>
static member StartImmediate : computation:Async<unit> * ?cancellationToken:CancellationToken -> unit
static member StartWithContinuations : computation:Async<'T> * continuation:('T -> unit) * exceptionContinuation:(exn -> unit) * cancellationContinuation:(OperationCanceledException -> unit) * ?cancellationToken:CancellationToken -> unit
static member SwitchToContext : syncContext:SynchronizationContext -> Async<unit>
static member SwitchToNewThread : unit -> Async<unit>
static member SwitchToThreadPool : unit -> Async<unit>
static member TryCancelled : computation:Async<'T> * compensation:(OperationCanceledException -> unit) -> Async<'T>
static member CancellationToken : Async<CancellationToken>
static member DefaultCancellationToken : CancellationToken
Full name: Microsoft.FSharp.Control.Async
--------------------
type Async<'T>
Full name: Microsoft.FSharp.Control.Async<_>
type HealthSwitch =
new : unit -> HealthSwitch
new : disabledMsg:string -> HealthSwitch
new : enabledMsg:string option * disabledMsg:string option -> HealthSwitch
new : getTime:(unit -> Instant) * enabledMsg:string option * disabledMsg:string option -> HealthSwitch
private new : getTime:(unit -> Instant) * enabledMsg:string option * disabledMsg:string option * dummy:unit -> HealthSwitch
member Disable : unit -> unit
member Disable : msg:string option -> unit
member Enable : unit -> unit
member Enable : msg:string option -> unit
member Check : Healthcheck
...
Full name: Cimfu.Suave.Healthcheck.HealthSwitch
--------------------
new : unit -> HealthSwitch
new : disabledMsg:string -> HealthSwitch
new : enabledMsg:string option * disabledMsg:string option -> HealthSwitch
new : getTime:(unit -> NodaTime.Instant) * enabledMsg:string option * disabledMsg:string option -> HealthSwitch
member HealthSwitch.Disable : msg:string option -> unit
Full name: Tutorial.newResult
member HealthSwitch.Enable : msg:string option -> unit
Full name: Tutorial.aggregateResult
Full name: Cimfu.Suave.Healthcheck.evaluateHealthchecks
Full name: Tutorial.serializedResult
module Json
from Chiron.Mapping
--------------------
module Json
from Chiron.Formatting
--------------------
module Json
from Chiron.Parsing
--------------------
module Json
from Chiron.Optics
--------------------
module Json
from Chiron.Functional
--------------------
type Json =
| Array of Json list
| Bool of bool
| Null of unit
| Number of decimal
| Object of Map<string,Json>
| String of string
static member Array_ : Prism<Json,Json list>
static member private Array__ : (Json -> Json list option) * (Json list -> Json)
static member Bool_ : Prism<Json,bool>
static member private Bool__ : (Json -> bool option) * (bool -> Json)
static member Null_ : Prism<Json,unit>
static member private Null__ : (Json -> unit option) * (unit -> Json)
static member Number_ : Prism<Json,decimal>
static member private Number__ : (Json -> decimal option) * (decimal -> Json)
static member Object_ : Prism<Json,Map<string,Json>>
static member private Object__ : (Json -> Map<string,Json> option) * (Map<string,Json> -> Json)
static member String_ : Prism<Json,string>
static member private String__ : (Json -> string option) * (string -> Json)
Full name: Chiron.Json
--------------------
type Json<'a> = Json -> JsonResult<'a> * Json
Full name: Chiron.Functional.Json<_>
Full name: Chiron.Mapping.Json.serialize
Full name: Chiron.Formatting.Json.formatWith
{Spacing: StringBuilder -> StringBuilder;
NewLine: int -> StringBuilder -> StringBuilder;}
static member Compact : JsonFormattingOptions
static member Pretty : JsonFormattingOptions
static member SingleLine : JsonFormattingOptions
Full name: Chiron.Formatting.JsonFormattingOptions