-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
ui: Move UI to API v2 #1560
Conversation
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" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this 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!
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. |
Relates to: OpenAPITools/openapi-generator#1140 |
840236d
to
8786fd0
Compare
@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 |
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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" ] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
My only concern is about introducing Maybes, why do we need them if the values are guaranteed to be there? |
bd221ab
to
963986e
Compare
That is a valid point. I guess we have two options here:
While is see the benefit of option two for the UI, reducing the noise with less @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? |
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 |
e95bf61
to
80853e2
Compare
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) |
There was a problem hiding this comment.
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?
@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? |
The only required properties of an alert are
Having an internal and an external representation of an alert, or having two different representations in the OpenAPI specification, or having multiple |
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. |
There was a problem hiding this 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?
@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:
What do you think? |
@mxinden sounds good to me! As for naming, I prefer a simple |
This compromise sounds good to me 👍 |
Closing here in favour of #1613. |
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.