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

Fixes #31521 - structured plugin information in statuses API #8207

Merged
merged 1 commit into from
Jan 12, 2021

Conversation

evgeni
Copy link
Member

@evgeni evgeni commented Dec 16, 2020

No description provided.

@theforeman-bot
Copy link
Member

Issues: #31521

app/services/ping.rb Outdated Show resolved Hide resolved
ekohl
ekohl previously approved these changes Dec 16, 2020
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

👍 for an explicit way. I do wonder about API compatibility here.

@ofedoren mind taking a look?

name: plugin.name,
version: plugin.version,
author: plugin.author,
description: plugin.description,
Copy link
Member

Choose a reason for hiding this comment

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

Curious your thoughts on why send out author and description on a status API?

Copy link
Member Author

Choose a reason for hiding this comment

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

it was there before

def to_s
"Foreman plugin: #{id}, #{version}, #{author}, #{description}"
end

and I didn't want to loose that data.

personally I only need id and version :)

Copy link
Member

Choose a reason for hiding this comment

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

Well, I doubt that someone would require those data... On hammer side we only show name and version anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Speaking of name… the Foreman::Plugin object has both, name and id attributes, but both seem to be the same?

Copy link
Member

Choose a reason for hiding this comment

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

Hm.. what could be id of the plugin except its name anyway?.. AFAIK it's not possible to install two versions of a plugin and use both at the same time. I'd expect that id == name.

But apparently there can be such thing as id != name:

plugin = new(id)
if (gem = Gem.loaded_specs[id.to_s])
plugin.name gem.name

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, name is the name of the gem, while id is what you put in when you register the plugin, so I'd actually say the id is the name and the name is worthless 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

That said, let's make the data {name: plugin.id, version: plugin.version} and be done with it?

Copy link
Member

Choose a reason for hiding this comment

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

@evgeni +1

@evgeni
Copy link
Member Author

evgeni commented Dec 16, 2020

we could also add it as a new entry, "plugin_data" or whatever, to keep it backwards compatible

@evgeni
Copy link
Member Author

evgeni commented Dec 16, 2020

ofedoren
ofedoren previously approved these changes Dec 17, 2020
Copy link
Member

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

@evgeni, surely this looks and is better to work with, thanks :)

@ekohl, about backward compatibility: currently information about plugins is being sent as an array of strings (which was quite dumb from my side to let it that way) as

{ "plugins" =>
  [ "plugin_a, version, etc",
    "plugin_b, version, etc"
  ]
}

To actually save compatibility we would need to add a new entry such as plugins_structured with this new data. This wouldn't break any automation (if there is any for such response), but will lead to data duplicity. Which is not so horrible for such amount, but.. is not so okay also.

I'd take a risk and change to @evgeni's version, but if others are okay with solution above I'm totally okay with having both entries.

name: plugin.name,
version: plugin.version,
author: plugin.author,
description: plugin.description,
Copy link
Member

Choose a reason for hiding this comment

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

Well, I doubt that someone would require those data... On hammer side we only show name and version anyway.

@evgeni
Copy link
Member Author

evgeni commented Dec 17, 2020

I too would prefer not to duplicate the data, unless someone really wants that :)

ofedoren
ofedoren previously approved these changes Dec 18, 2020
Copy link
Member

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

LGTM, @evgeni :) Can't merge though :(

@@ -365,7 +365,12 @@ def test_register_status_extension
api: {
version: Apipie.configuration.default_version,
},
plugins: [Foreman::Plugin.find(:foo)],
plugins: [
Copy link
Member

Choose a reason for hiding this comment

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

To be more accurate, I think it should be something like:

...
plugin = Foreman::Plugin.find(:foo)
...
plugins: [ { name: plugin.id, version: plugin.version } ]
...

Copy link
Member

Choose a reason for hiding this comment

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

I think it's a good practice to have exact values in your expected results. Otherwise you may miss a situation where a property may be nil for example. Essentially there is no assertion then.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had the dynamic version before, and then had the same thought as Ewoud: lets test explicit values.

@ekohl
Copy link
Member

ekohl commented Dec 18, 2020

@tbrisker can I ask you what you think about the API compatibility here?

@ofedoren
Copy link
Member

@evgeni, now test fails are related :(

@evgeni
Copy link
Member Author

evgeni commented Dec 18, 2020

Hah, that's because the version is taken from the Gem, but in the tests we mock the plugin and have no gem. Will have a thought how to fix that on Monday.

@ares
Copy link
Member

ares commented Dec 19, 2020

The plugins info was introduced in Foreman 1.24. That's 3 versions already. I can imagine people use /ping endpoint to monitor Foreman. However I don't think people would monitor plugin versions specifically. I think it's a safe change for the better, but it is breaking backwards compatibility. If we decide to go with the duplication of the information, can we deprecate the existing way in release notes and drop it in Foreman 3.0? The problem is, we can't easily display the deprecation to the user, since we have no idea if they use this piece of the response. The other option is to be less dogmatic, ask on community or use RSS notification and drop it in e.g. one minor release if no one objects.

@evgeni
Copy link
Member Author

evgeni commented Dec 19, 2020

[test foreman]

@evgeni
Copy link
Member Author

evgeni commented Dec 19, 2020

`<class:ApplicationRecord>': uninitialized constant ApplicationRecord::ApipieDSL (NameError)

Looks unrelated?!

@evgeni
Copy link
Member Author

evgeni commented Dec 19, 2020

Yeah, it is unrelated. See https://projects.theforeman.org/issues/31533

@evgeni
Copy link
Member Author

evgeni commented Dec 20, 2020

[test foreman]
[test katello]

Copy link
Member

@tbrisker tbrisker left a comment

Choose a reason for hiding this comment

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

I'd be fine with modifying the existing API with an upgrade warning in this case. One could even argue that the previous response was a bug, calling to_s on the plugins instead of returning the hash of installed plugins. Perhaps we could also keep the authors and description so we can reuse it in the ui about page, but that's not crucial.

@evgeni
Copy link
Member Author

evgeni commented Dec 21, 2020

I can add the details back in (my original version had them, but the feedback so far was "nobody needs that").

By upgrade warning you mean release notes in the docs? Can open a PR for that.

@ekohl
Copy link
Member

ekohl commented Dec 21, 2020

Perhaps we could also keep the authors and description so we can reuse it in the ui about page, but that's not crucial.

I'm not sure if the about page should use ping. It reaches out to all backend services so if all you need to do is retrieve installed plugins, it's too heavy.

@tbrisker
Copy link
Member

Perhaps we could also keep the authors and description so we can reuse it in the ui about page, but that's not crucial.

I'm not sure if the about page should use ping. It reaches out to all backend services so if all you need to do is retrieve installed plugins, it's too heavy.

good point, perhaps in the future we would want to use it so you can see that status in a nice ui, but we're getting ahead of ourselves. we can always add it later.

@ofedoren
Copy link
Member

Perhaps we could also keep the authors and description so we can reuse it in the ui about page, but that's not crucial.

I'm not sure if the about page should use ping. It reaches out to all backend services so if all you need to do is retrieve installed plugins, it's too heavy.

AFAIU we use ping on the about page already.. Or you meant that the current way is not so good?

@evgeni
Copy link
Member Author

evgeni commented Jan 4, 2021

upgrade warning in theforeman/theforeman.org#1752

Copy link
Member

@tbrisker tbrisker left a comment

Choose a reason for hiding this comment

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

Thanks @evgeni, @ofedoren - can you take a look at the hammer side please? I'm assuming we'll need to merge theforeman/hammer-cli-foreman#553 at the same time as this one?

@ofedoren
Copy link
Member

ofedoren commented Jan 4, 2021

@tbrisker, sure thing.

@evgeni
Copy link
Member Author

evgeni commented Jan 4, 2021

Technically? Yes. Realistically, no, as hammer status (vs hammer ping) is IIRC not part of the pipelines ;)

@ekohl
Copy link
Member

ekohl commented Jan 8, 2021

Technically? Yes. Realistically, no, as hammer status (vs hammer ping) is IIRC not part of the pipelines ;)

Was this intended for another PR?

@evgeni
Copy link
Member Author

evgeni commented Jan 8, 2021

Technically? Yes. Realistically, no, as hammer status (vs hammer ping) is IIRC not part of the pipelines ;)

Was this intended for another PR?

No, it was an answer to tomers question whether it needs to go together with the hammer change

@ekohl
Copy link
Member

ekohl commented Jan 11, 2021

Ok, but the Katello pipeline does call hammer ping (https://github.com/theforeman/forklift/blob/dbce1cfec5f658128518379679ed26f199724930/bats/fb-test-katello.bats#L9-L30), although technically nowadays that's generic for Foreman nowadays.

@evgeni
Copy link
Member Author

evgeni commented Jan 11, 2021

Ok, but the Katello pipeline does call hammer ping (https://github.com/theforeman/forklift/blob/dbce1cfec5f658128518379679ed26f199724930/bats/fb-test-katello.bats#L9-L30), although technically nowadays that's generic for Foreman nowadays.

hammer ping != hammer status and the later is what's affected by the change here ;)

@evgeni
Copy link
Member Author

evgeni commented Jan 12, 2021

hammer is merged now.

@tbrisker
Copy link
Member

Thanks @evgeni et al!

@tbrisker tbrisker merged commit 2bc006f into theforeman:develop Jan 12, 2021
evgeni added a commit to evgeni/foreman-ansible-modules that referenced this pull request Mar 10, 2021
Foreman 2.4 [1] started to return plugin information in a structured
way, let's be nice and support that too :-)

[1] theforeman/foreman#8207
evgeni added a commit to theforeman/foreman-ansible-modules that referenced this pull request Mar 11, 2021
Foreman 2.4 [1] started to return plugin information in a structured
way, let's be nice and support that too :-)

[1] theforeman/foreman#8207
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants