-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add api support to PluginUsageView #18
Conversation
Allow the exported data in PluginUsageModel and JobsPerPlugin to be served over the json/xml api.
Hi @froque, would you be in favor of adding an api to this plugin? |
Hi @sghill. This is a fine addition. I didn't get any email for the pull request creation, so sorry for the delay. Why not also exposing My only concern is that we now have an API to maintain and will be harder to detect breaking changes. Do you think you can create a unit test with some basic information: plugin name, plugin version, job name ? |
No worries, thanks for the quick response here.
I didn't have a need for it, but can add the annotation if you'd prefer. The built-in plugin manager does have an api that can be used to get installed plugins. Here's an example of {
"_class": "hudson.LocalPluginManager",
"plugins": [
{
"active": true,
"backupVersion": "2.11.2",
"bundled": false,
"deleted": false,
"dependencies": [
{
"optional": false,
"shortName": "snakeyaml-api",
"version": "1.26.4"
}
],
"detached": false,
"downgradable": true,
"enabled": true,
"hasUpdate": true,
"longName": "Jackson 2 API Plugin",
"minimumJavaVersion": "1.8",
"pinned": false,
"requiredCoreVersion": "2.222.4",
"shortName": "jackson2-api",
"supportsDynamicLoad": "YES",
"url": "https://plugins.jenkins.io/jackson2-api",
"version": "2.11.3"
}
]
}
I like this idea. I've been trying to create a test, but it's more difficult than expected. I think it comes down the TestPluginManager not being aware of any installed plugins, so the test is going to have to install them first. I'll keep going down this path, and hopefully will have something soon. |
This test ensures the ant plugin and its transitives are installed before running. The job is created through XML and the api response is deserialized into classes that mirror the expected structure of the response. A change in model structure would cause this test to fail. It's important to create the job through XML instead of creating a project through the JenkinsRule with an Ant builder. If the ant plugin's classes are used directly, the plugin manager detects `hudson.tasks.Ant` was loaded through the test's class loader instead of the plugin's class loader - which results in the plugin under test not finding the ant plugin. These versions of ant and structs were chosen because they're the most recent that are compatible with the version of Jenkins core.
Hi @froque, I added a test and some supporting classes for deserialization that ensures only the correct jobs are returned for an example plugin. Is this aligned with what you had in mind? I tried a couple things before landing on this implementation --
|
Hi @froque, are there any changes you'd like me to make to this PR? |
everything looks fine |
Thank you! |
Is there an api call present to list the number of jobs a plugin is being used? |
Hi @kad-meedel. It's exposing the existing data structure which does include this information as you mentioned. Here's an example of turning this response into a usage count (subject to all the same caveats as the UI version):
// response from request above
const json = {
"_class": "org.jenkinsci.plugins.pluginusage.PluginUsageModel",
"jobsPerPlugin": [
{
"plugin": {
"shortName": "branch-api"
},
"projects": [
{
"_class": "hudson.model.FreeStyleProject",
"fullName": "abcd"
}
]
},
{
"plugin": {
"shortName": "docker-workflow"
},
"projects": []
}
]
};
// count jobs by plugin
const jobCountByPlugin = json.jobsPerPlugin.reduce((acc, x) => {
acc[x.plugin.shortName] = x.projects.length;
return acc;
}, {});
// returns { "branch-api": 1, "docker-workflow": 0 } |
Hi,
Thanks for this plugin. It helps determine which plugins can be easily removed. Would it be possible to add api support?
My use case is I have several Jenkins controllers with different plugins that I'd like to standardize. As a first pass, I'm checking which plugins are installed but not used by any jobs in order to uninstall them. Having api support would allow easily checking which plugins are not used in jobs without visiting the UI on each controller.
Below is an example of what this change will serve from
/pluginusage/api/json?depth=2
.It also supports the
tree
query parameter to customize what is returned. Here is an example for/pluginusage/api/json?tree=jobsPerPlugin[plugin[shortName],projects[fullName]]
: