Skip to content

Comments

ui: Move /status & /silences to API v2#1613

Merged
mxinden merged 3 commits intoprometheus:masterfrom
mxinden:api-v2-silences-status
Nov 15, 2018
Merged

ui: Move /status & /silences to API v2#1613
mxinden merged 3 commits intoprometheus:masterfrom
mxinden:api-v2-silences-status

Conversation

@mxinden
Copy link
Member

@mxinden mxinden commented Nov 9, 2018

This patch makes the Alertmanager UI (/status & /silences) use the
api/v2 endpoint. In addition it adds logic to generate the elm side data
model based on the OpenAPI specification.

In addition requesting alerts from api v1 is done in a separate commit to be
able to revert it once alerts also come from api v2.

@mxinden mxinden requested review from stuartnelson3 and w0rm November 9, 2018 12:02
@mxinden mxinden mentioned this pull request Nov 9, 2018
Copy link
Contributor

@stuartnelson3 stuartnelson3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these maybe's (like for silence ID) represent (to me) not trusting the API, or having a strong contract of what will or won't be there. If we can guarantee these values will be present when retrieved from the API, a model with types that represent this would make the code much cleaner. Given that we have strongly typed decoding, we would also catch such errors early.

Can we be confident in this contract and represent it in the code?

url =
String.join "/" [ apiUrl, "silence", silence.id ]
-- TODO: Maybe.withDefault is not perfect. Silences should always
-- have an id, what should we do?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API should fail and provide a good error message, which we can render? I don't think we can get to this branch without having a valid silence with an ID, so I don't think this can happen, as you stated




{-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed?

@stuartnelson3
Copy link
Contributor

Thanks for doing all this. We haven't touched the elm code in a while, but it's really nice coming back to this language and feeling confident in the changes we make thanks to the type system :)

This patch makes the Alertmanager UI (/status & /silences) use the
api/v2 endpoint. In addition it adds logic to generate the elm side data
model based on the OpenAPI specification.

Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
With the previous patch /status and /silences were requested from api
v2. Requesting alerts from api v1 is done in a separate commit to be
able to revert it once alerts also come from api v2.

Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
@mxinden mxinden force-pushed the api-v2-silences-status branch 4 times, most recently from 82fef5f to 111ce11 Compare November 15, 2018 12:42
Copy link
Member Author

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenAPI has the allOf keyword to achieve composition, similar to Golangs composition.

Instead of having one type Silence for both GET and POST, we now have one base type Silence. In addition we have the GettableSilence and PostableSilence which are composed off the base type Silence and all additional fields.

type alias PostableSilence =
    { matchers : Matchers
    , startsAt : DateTime
    , endsAt : DateTime
    , createdBy : String
    , comment : String
    -- Needs to be of type `Maybe` to update existing silences.
    , id : Maybe String
    }


type alias GettableSilence =
    { matchers : Matchers
    , startsAt : DateTime
    , endsAt : DateTime
    , createdBy : String
    , comment : String
    , id : String
    , status : SilenceStatus
    , updatedAt : DateTime
    }

This leaves us with a single Maybe. Thanks @w0rm & @stuartnelson3, I like this
much better. Any further thoughts?



type alias Alert =
{ startsAt : Maybe DateTime
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will change once I move /alerts to the new API as well.

@stuartnelson3
Copy link
Contributor

Looks good to me!

Copy link
Member

@w0rm w0rm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for iterating on this!

Copy link
Contributor

@stuartnelson3 stuartnelson3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 once the build is green

Instead of having one general silence, differentiate between postable
and gettable silence, hence making more fields required.

Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
@mxinden mxinden force-pushed the api-v2-silences-status branch from 111ce11 to b4b8b75 Compare November 15, 2018 15:21
@mxinden mxinden merged commit 7ff1a61 into prometheus:master Nov 15, 2018
@mxinden
Copy link
Member Author

mxinden commented Nov 15, 2018

Thanks @w0rm and @stuartnelson3. I will follow up with moving the /alerts page as well to API v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants