Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: Move UI to API v2 #1560

Closed
wants to merge 1 commit into from
Closed

ui: Move UI to API v2 #1560

wants to merge 1 commit into from

Conversation

mxinden
Copy link
Member

@mxinden mxinden commented Sep 26, 2018

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

//CC @stuartnelson3 as discussed via e-mail.

ui/app/elm.json Outdated
@@ -15,7 +15,8 @@
"elm/regex": "1.0.0",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"rtfeldman/elm-iso8601-date-strings": "1.1.2"
"rtfeldman/elm-iso8601-date-strings": "1.1.2",
"NoRedInk/elm-json-decode-pipeline": "1.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

the alignment on this looks funny, this was added automatically?

-}


module Data.InlineResponse200 exposing (InlineResponse200, inlineResponse200Decoder, inlineResponse200Encoder)
Copy link
Contributor

Choose a reason for hiding this comment

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

funny, looks like a github syntax highlighting bug?

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.

Only question I have right now is about how to use the generated methods for making HTTP requests to endpoints, since it looks like localhost is hardcoded in as the baseUrl.

Awesome to see this, thanks for pushing openapi through!

@mxinden
Copy link
Member Author

mxinden commented Sep 26, 2018

Only question I have right now is about how to use the generated methods for making HTTP requests to endpoints, since it looks like localhost is hardcoded in as the baseUrl.

I am still trying to figure this out. So far I have only used the generated data models and decoders due to that. But using the generated request logic would also be nice.

@mxinden
Copy link
Member Author

mxinden commented Sep 28, 2018

Relates to: OpenAPITools/openapi-generator#1140

@mxinden
Copy link
Member Author

mxinden commented Oct 18, 2018

@stuartnelson3 @w0rm I refactored all of the UI code to use the new API v2 with the generated model logic. This is still in work-in-progress but I would love your feedback. Especially everything marked with TODO. As my elm skills are a bit rusty feedback is very welcome.

@mxinden
Copy link
Member Author

mxinden commented Oct 18, 2018

From my side this is the last thing missing before we can cut the first alpha or beta in #1553.


Nothing ->
-- TODO: What to return here? This case should never happen.
Copy link
Member

Choose a reason for hiding this comment

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

If this should never happen, then why is status a maybe type?

Copy link
Member Author

Choose a reason for hiding this comment

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

The definition of Silence is generated based on the new OpenAPI specification of the API v2. I would prefer not to have an additional internal type which converts to the generated one.

Why does the specification not enforce the status property: E.g. when creating a silence that status property is not yet known. Thereby the API does not enforce the property.

Is that enough context? What are your thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I see, shouldn't a silence to be created and a silence that we retrieve be two different types?

in
editUrl =
-- TODO: silence.id should always be set. Can this be done nicer?
String.join "/" [ "#/silences", Maybe.withDefault "" silence.id, "edit" ]
Copy link
Member

Choose a reason for hiding this comment

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

If the id is undefined, we could maybe generate a link to create a new silence?

Copy link
Member Author

Choose a reason for hiding this comment

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

The id would never be undefined, as Alertmanager can only return Silences with ids.

@w0rm
Copy link
Member

w0rm commented Oct 18, 2018

My only concern is about introducing Maybes, why do we need them if the values are guaranteed to be there?

@mxinden mxinden force-pushed the api-v2-ui branch 2 times, most recently from bd221ab to 963986e Compare October 26, 2018 12:34
@mxinden mxinden changed the title [WIP] ui: Move UI to API v2 ui: Move UI to API v2 Oct 26, 2018
@mxinden
Copy link
Member Author

mxinden commented Oct 26, 2018

My only concern is about introducing Maybes, why do we need them if the values are guaranteed to be there?

That is a valid point. I guess we have two options here:

  1. Current situation: Have one type silence which is both used to create silences (id can not be required) as well as retrieve silences. This means, that retrieved silences would have a Maybe id property.

  2. Use two different types. One type creatableSilence (id is not required) to create a silence. One type gettableSilence (id is always defined) to retrieve silences.

While is see the benefit of option two for the UI, reducing the noise with less Maybe operations, I would also like to point out the extra complexity for external users that now need to differentiate between the two in their client. Thereby I am voting for the first approach, having a single silence type but also having more noise in the code via Maybe handle logic.

@stuartnelson3 @w0rm What are your thoughts?

@wing328 and @trenneman from the https://github.com/OpenAPITools/openapi-generator project: Are there any best practices around this?

@eriktim
Copy link

eriktim commented Oct 26, 2018

Hi @mxinden, I do not know what the community's best practice is on this (maybe ask around on Elm Discourse. I often keep it as a Maybe as my application typically doesn't care about the id. Later when saving the resource I can decide whether I need to PUT or POST it, depending on the state of the Maybe. But I do not know your application and I can imagine there are use cases where it is better to split them.

@mxinden mxinden force-pushed the api-v2-ui branch 3 times, most recently from e95bf61 to 80853e2 Compare October 26, 2018 13:22
This patch makes the Alertmanager UI 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>
, generatorURL : Maybe String
, labels : Dict String String
, annotations : Maybe (Dict String String)
, receivers : Maybe (List Receiver)
Copy link
Member

@w0rm w0rm Oct 29, 2018

Choose a reason for hiding this comment

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

Why does Alert have so many Maybe fields? For example, what is the difference between Nothing and Just [] for receivers?

@w0rm
Copy link
Member

w0rm commented Oct 29, 2018

@mxinden as far as I see it is not only about an id, but also a status of a silence. Maybe we need one type for the data, that we PUT / POST to the api, and a type of a silence that we fetch to display. Anyway, the Silence type doesn't seem like a blocker to me.

I wonder about the Alert type. It looks confusing, because almost every field is a Maybe. Is this really what the api may return?

@mxinden
Copy link
Member Author

mxinden commented Nov 5, 2018

The only required properties of an alert are labels (@stuartnelson3 please correct me if I am wrong).

  • Annotations, UpdatedAt and generator URL don't need to be set in general
  • EndsAt doesn't need to be set e.g. when an alert is firing
  • StartsAt doesn't need to be set e.g. when an alert is resolved
  • Receivers don't need to be set when creating an alert (PUT)
  • Status and Fingerprint is generated server side, hence does not need to be set when creating an alert

Having an internal and an external representation of an alert, or having two different representations in the OpenAPI specification, or having multiple Maybes (current state) all adds complexity. In my opinion the laster (Maybes) is the least confusing one. What do you think @stuartnelson3 @w0rm ?

@stuartnelson3
Copy link
Contributor

I suppose I'm not sure. The idea that I really like about OpenAPI is that we can have a single definition file, and then generate many different language's clients from that.

From that perspective, having the additional OpenAPI definition for querying the API (one without all the maybe/optional values) would end up being much simpler, since each client would be simpler as a result.

I agree with @mxinden that it's probably less confusing to have the single definition, but I think if we can properly indicate that one of the definitions is for ingesting, and the other for consuming, the resulting clients will be much simpler to work with.

I'm not convinced one way or the other, but I am leaning towards the (hopefully) onetime creation of the second definition and supporting documentation which then results in a simpler client to work with.

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.

At work, we usually have different types for the update/create payload and for the get response in the Scala backend. Conceptually it may be the same entity, but the payloads and use cases differ. I don't think types are any helpful when any field can be a Maybe.

I don't want to block the progress, as I am going on vacation. But maybe we can revisit this in the future?

@mxinden
Copy link
Member Author

mxinden commented Nov 8, 2018

I don't think types are any helpful when any field can be a Maybe.

@w0rm I think you have a very good point.

How about I split this PR up into two so that we can move forward with parts of this patch:

  1. Move status and silences to API v2 (as is in this PR)

  2. Split Alert type into GettableAlert and PostableAlert (better name suggestions welcome)

What do you think?

@w0rm
Copy link
Member

w0rm commented Nov 8, 2018

@mxinden sounds good to me! As for naming, I prefer a simple Alert for the gettable alert and something different for creating an alert, maybe AlertCreate.

@stuartnelson3
Copy link
Contributor

This compromise sounds good to me 👍

@mxinden
Copy link
Member Author

mxinden commented Nov 9, 2018

Closing here in favour of #1613.

@mxinden mxinden closed this Nov 9, 2018
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.

4 participants