Skip to content

Commit 1c50dbb

Browse files
jaymzhfacebook-github-bot
authored andcommitted
fb_grafana: Add support for immutable plugins (facebook#336)
Summary: Grafana has started shipping with certain core functionality as a "plugin". The plugin is extracted into the same directory as user-controlled plugins, and the CLI does not differentiate, but attempting to remove or upgrade them throws an error. This PR adds support for handling those more sanely. Signed-off-by: Phil Dibowitz <phil@ipom.com> Pull Request resolved: facebook#336 Differential Revision: D79735298 fbshipit-source-id: 2e338a84acf77a774ba04940c2158755d47cf035
1 parent 79fa8f5 commit 1c50dbb

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

cookbooks/fb_grafana/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Attributes
1313
* node['fb_grafana']['gen_selfsigned_cert']
1414
* node['fb_grafana']['plugins']
1515
* node['fb_grafana']['plugins'][$PLUGIN]
16+
* node['fb_grafana']['immutable_plugins']
17+
* node['fb_grafana']['immutable_plugins'][$PLUGIN]
1618
* node['fb_grafana']['datasources']
1719
* node['fb_grafana']['datasources'][$NAME]
1820
* node['fb_grafana']['datasources'][$NAME][$CONFIG]
@@ -57,6 +59,20 @@ version will be pinned.
5759
Note that we ensure these are managed idempotently, a plugin is never touched if
5860
it's on the desired version.
5961

62+
Note that some plugins are considered "immutable" - they are part of the
63+
distribution of Grafana itself. Since they get extracted into the same plugins
64+
directory, there is no programatic way to tell them apart. As such we keep an
65+
`immutable_plugins` hash that's the same structure as the `plugins` hash. Plugins
66+
in this list (which we attempt to keep up-to-date in `attributes/default.rb`, but
67+
you may add to if your distribution has different immutable plugins), will not be
68+
removed by this cookbook, even if they are not in the `plugins` list. Note that
69+
the _value_ is ignored, and thus should be set to `nil` for consistency. It is
70+
a hash instead of an array for easy modification.
71+
72+
If an immutable plugin appears in `plugins` at a specific version, a warning
73+
will be displayed saying that the plugin cannot be directly managed, and then
74+
that plugin will be ignored.
75+
6076
### Data Sources
6177
You can populate datasources by adding them to the hash
6278
`node['fb_grafana']['datasources']`. Note that this uses the Provisioning

cookbooks/fb_grafana/attributes/default.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
},
1313
'gen_selfsigned_cert' => false,
1414
'plugins' => {},
15+
'immutable_plugins' => {
16+
'grafana-exploretraces-app' => nil,
17+
'grafana-lokiexplore-app' => nil,
18+
'grafana-metricsdrilldown-app' => nil,
19+
'grafana-pyroscope-app' => nil,
20+
},
1521
'datasources' => {},
1622
'version' => nil,
1723
}

cookbooks/fb_grafana/resources/plugins.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
'/var/lib/grafana/plugins'
1212
basecmd = "grafana-cli --pluginsDir #{plugin_dir}"
1313
node['fb_grafana']['plugins'].each do |plugin, version|
14+
if node['fb_grafana']['immutable_plugins'].key?(plugin) && !version.nil?
15+
Chef::Log.warn(
16+
"fb_grafana: Plugin #{plugin} is configured to be installed at " +
17+
"version #{version}, but #{plugin} is a built-in/immutable plugin " +
18+
'that cannot be managed by the user.',
19+
)
20+
next
21+
end
22+
1423
# If a version is specified, see if it's installed and on that version...
1524
if version && installed[plugin] == version
1625
Chef::Log.debug(
@@ -50,7 +59,8 @@
5059
# NOTE WELL: Cannot use ruby-style
5160
# if node['fb_grafana']['plugins'][plugin]
5261
# because the value can be nil, which evaluates to false!
53-
next if node['fb_grafana']['plugins'].include?(plugin)
62+
next if node['fb_grafana']['plugins'].key?(plugin)
63+
next if node['fb_grafana']['immutable_plugins'].key?(plugin)
5464

5565
execute "Uninstall grafana plugin #{plugin}" do
5666
command "#{basecmd} plugins uninstall #{plugin}"

0 commit comments

Comments
 (0)