forked from sous-chefs/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
General refactoring and automatic config accumulators (sous-chefs#403)
* Tidy up templates * Automatic config template resource generation * Test fixup for auto template resources * Resources to unified mode * Fix resource property collision * Add extra_options to grafana_config Closes sous-chefs#400 * Concat to existing settings rather than overwriting them * Add LDAP log filters to the main config file Fixes sous-chefs#392 * Start service immediately during testing * Azure AD auth needs path override * Require Chef 16 for resource partials * Kitchen allow log level to be set * Remove deprecated API resources * Refactor config file accumulation As we've removed the deprecated API resource then we don't need to worry about config writing timing so we can use a standard accumulator pattern to build the config files. * Template nil catch * Delete config_writer resource * Remove redundant sleep test recipe * Remove redundant instance_name With the migration to an standard accumulator pattern the instance_name functionality can be achieved by overriding the configuration file or directory etc. * Library refactoring * Correct config_auth default key path * Test strip global section * Remove etc/share directory creation as we use packages * Resource formatting and update options for Grafana 8.1 * Unify accumulator config method with action property * Automatic LDAP configuration accumalator template * Install deepsort gem for chefspec * Fixup plug library references * Test refactoring for api resource removal * LDAP config load_current_value support * Split log resource into separate types * Split metrics resource into separate types * Split auth resource into separate types * All resources converge_if_changed_support * Rationalise config resource action naming * Add expression, geomap, feature_toggle and date_format resources * load_current_value for extra_options property * Correct config actions * Remove redundant default values to use grafana defaults instead * Add load_existing option to init_config_template Allow the loading of the current configuration state to create a persistent accumulator pattern where configuration is not removed if the resource creating it is removed. * Move common resource actions into partial * Extract config path override to action_class method This allows us to use the common resource actions and load_current_value from the partial in 99% of cases. * Remove header comment * Load current state of config files into templates on init * Compact and deep sort ini config output * Add debug logging to ldap_config_file helper * Update LDAP resource for load current state changes * Add comments to the libraries * Remove enforce_idempotency overrides from kitchen config * Change skip property constant to method * Global documentation update * Add development guide * Refactor plugin resource to use converge_by * Common config resource delete action * Resource format fixup * Add missing grafanacom path override * Documentation update * Add jaeger and base external image resources * Add missing config resource properties * Add resource property/grafana property translation feature * Markdown link fixup * Add Okta auth resource * Allow overriding of the Grafana package name Fixes sous-chefs#380 * Update README links default branch name * Move LDAP server exist checks into resources * Fix missing prefix delete for ldap attribute resource load_current_value * Add Fedora installation support * Docs fixup * Use ternary for delete properties * Refactor helpers for a single override/translate/skip resource method Co-authored-by: Jason Field <[email protected]>
- Loading branch information
Showing
172 changed files
with
3,769 additions
and
5,767 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Developing | ||
|
||
The refactor for version 10 of this cookbook makes some major changes to the underlying method of operation of the cookbook to improve operation and maintainability. | ||
|
||
In summary: | ||
|
||
- Accumulator config hash initialisation is automatic upon initial access | ||
- Accumulator config hash paths are automatically generated from the resource name | ||
- Property enumeration is automatic so adding a property to resource will result in that property being added to the configuration Hash | ||
- Most config resource functionality has been moved to the partially-abstract `_config_file` and `_config_file_ldap` partial resources | ||
- Barring edge cases, all `config_*` resources inherit from these partials and contain only their properties | ||
- `load_current_value` has been implemented for all resources | ||
- The `extra_options` hash property has been added to allow the additional of arbitrary configuration options (all config resources) | ||
- Config files are now generated by the `inifile` and `toml-rb` gems so the templates are purely placeholders | ||
|
||
## Adding a new configuration item to an existing resource | ||
|
||
Adding a new configuration item to an existing resource is as simple as adding the required item as a property to resource representing the section of the configuration file. | ||
|
||
## Adding a new configuration section | ||
|
||
To add a new configuration section a `config_` resource should be created where the name following the `config_` prefix is the name of the configuration section to represent. Configuration items under the section are then added as properties to this resource. | ||
|
||
The configuration resource **must** then inherit from the `_config_base` partial template via the addition of | ||
|
||
```ruby | ||
use 'partial/_config_file' | ||
``` | ||
|
||
At the top of the resource declaration above the first property. | ||
|
||
See a pre-existing resource for an example of this pattern. | ||
|
||
### Overriding the automatic path | ||
|
||
If the name of the resource with the `'grafana_config_` prefix removed does not match the name of the configuration section or a nested configuration section is in use such as `section.subsection` then the automatic configuration path can be overridden by the addition of the `:resource_config_path_override` method. | ||
|
||
After the last resource property declaration, add the following code with the array contents set to the config Hash path set as you would pass to [Hash#dig](https://ruby-doc.org/core-3.0.2/Hash.html#method-i-dig) to create the required configuration path. Multiple nested Hashes are supported. | ||
|
||
```ruby | ||
def resource_config_path_override | ||
%w(external_image_storage.s3).freeze | ||
end | ||
|
||
``` | ||
|
||
### Excluding properties from the configuration | ||
|
||
If an additional property must be added for the resource to function but the property is not relevant for the Grafana config file then these properties can be marked to be skipped by the enumerator by the creation of a `:resource_config_properties_skip` method. | ||
|
||
```ruby | ||
def resource_config_properties_skip | ||
%i(host).freeze | ||
end | ||
``` | ||
|
||
### Property/configuration item name translation | ||
|
||
There are some cases where a Grafana configuration property name either conflicts with one of the base properties (`config_auth_ldap` property `:config_file`) or is a name that is disallowed by Chef (`config_external_image_storage` property `:provider`). To work around this issue there is a property translation mechanism implemented that can be used to alias the chef property name to the Grafana property name and vice-versa. | ||
|
||
This is performed by the creation of a `:resource_config_properties_translate` method as shown below. | ||
|
||
```ruby | ||
def resource_config_properties_translate | ||
{ | ||
storage_provider: 'provider', | ||
}.freeze | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.