Skip to content

Commit

Permalink
Display constraints for configuration parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ngaumont committed Oct 24, 2024
1 parent a05c5da commit c829232
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- `cb config-param list-supported` now returns `min_value`, `max_value`, and
`enum` constraints for each parameters, if applicable.

## [3.6.0] - 2024-07-26
### Added
Expand Down
38 changes: 30 additions & 8 deletions spec/cb/config_param_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ Spectator.describe ConfigurationParameterGet do
"parameters": [
{
"component": "postgres",
"enum": [],
"min_value": "100",
"max_value": "2000",
"name": "postgres:max_connections",
"parameter_name": "max_connections",
"requires_restart": false,
Expand Down Expand Up @@ -104,9 +107,21 @@ Spectator.describe ConfigurationParameterListSupported do
Factory.configuration_parameter(value: nil),
Factory.configuration_parameter(
component: "pgbouncer",
name: "pgbouncer:default_pool_size",
parameter_name: "default_pool_size",
value: nil
name: "pgbouncer:auth_type",
parameter_name: "auth_type",
value: nil,
min_value: nil,
max_value: nil,
enum: ["cert", "md5", "trust"]
),
Factory.configuration_parameter(
component: "pgbouncer",
name: "pgbouncer:fake",
parameter_name: "fake",
value: nil,
min_value: nil,
max_value: nil,
enum: [] of String
),
]
}
Expand All @@ -115,9 +130,10 @@ Spectator.describe ConfigurationParameterListSupported do
action.call

expected = <<-EXPECTED
Component Name Requires Restart
postgres max_connections no
pgbouncer default_pool_size no
Component Name Requires Restart Constraints
postgres max_connections no min: 100, max: 2000
pgbouncer auth_type no enum: cert, md5, trust
pgbouncer fake no
EXPECTED

expect(&.output).to look_like expected
Expand All @@ -128,8 +144,8 @@ Spectator.describe ConfigurationParameterListSupported do
action.call

expected = <<-EXPECTED
Component Name Requires Restart
postgres max_connections no
Component Name Requires Restart Constraints
postgres max_connections no min: 100, max: 2000
EXPECTED

expect(&.output).to look_like expected
Expand Down Expand Up @@ -179,6 +195,9 @@ Spectator.describe ConfigurationParameterSet do
"parameters": [
{
"component": "postgres",
"enum": [],
"min_value": "100",
"max_value": "2000",
"name": "postgres:max_connections",
"parameter_name": "max_connections",
"requires_restart": false,
Expand Down Expand Up @@ -242,6 +261,9 @@ Spectator.describe ConfigurationParameterReset do
"parameters": [
{
"component": "postgres",
"enum": [],
"min_value": "100",
"max_value": "2000",
"name": "postgres:max_connections",
"parameter_name": "max_connections",
"requires_restart": false,
Expand Down
3 changes: 3 additions & 0 deletions spec/support/factory.cr
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ module Factory
parameter_name: "max_connections",
requires_restart: false,
value: "100",
enum: [] of String,
min_value: "100",
max_value: "2000",
}.merge(params)

CB::Model::ConfigurationParameter.new **params
Expand Down
13 changes: 12 additions & 1 deletion src/cb/config_param.cr
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,19 @@ module CB
add "Component"
add "Name"
add "Requires Restart"
add "Constraints"
end

header unless no_header

rows parameters.map { |p| [p.component, p.parameter_name, p.requires_restart ? "yes" : "no"] }
rows parameters.map { |p|
constraints = [] of String
constraints << "enum: #{p.enum.join(", ")}" if p.enum.size > 0
constraints << "min: #{p.min_value}" if p.min_value && p.min_value != ""
constraints << "max: #{p.max_value}" if p.max_value && p.max_value != ""

[p.component, p.parameter_name, p.requires_restart ? "yes" : "no", constraints.join(", ")]
}
end

output << table.render << '\n'
Expand All @@ -106,6 +114,9 @@ module CB
"parameters": parameters.map do |p|
{
"component": p.component,
"enum": p.enum,
"min_value": p.min_value,
"max_value": p.max_value,
"name": p.name,
"parameter_name": p.parameter_name,
"require_restart": p.requires_restart,
Expand Down
4 changes: 3 additions & 1 deletion src/models/config_param.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
module CB::Model
jrecord ConfigurationParameter,
component : String? = nil,
enum : Array(String) = [] of String,
min_value : String? = nil,
max_value : String? = nil,
name : String = "",
parameter_name : String? = nil,
requires_restart : Bool = false,
value : String? = nil do
@[JSON::Field(key: "parameter_name", emit_null: false)]
def to_s(io : IO)
io << name.colorize.t_name << '=' << value
end
Expand Down

0 comments on commit c829232

Please sign in to comment.