Skip to content

cli: add hidden command-line flag for overriding settings #17582

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yaauie
Copy link
Member

@yaauie yaauie commented Apr 23, 2025

Release notes

[rn: skip]

What does this PR do?

When invoking Logstash in test, it is often necessary to override a setting, but cumbersome to provide a whole logstash.yml (or to append specific overrides to a fixture-provided one) when there is no provided command-line option paired with the setting.

This feature adds a hidden --setting option with an -S shortname, whose value is a colon- or equals-separated key-value pair.

  • long-form single arg: --setting=queue.type:persisted
  • long-form arg-pair: --setting node.name:myname
  • short-form: -Squeue.type=persisted

Why is it important/What is the impact to the user?

No user impact; improved testability.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files (and/or docker env variables)
  • I have added tests that prove my fix is effective or that my feature works

How to test this PR locally

  • Invoke logstash with any setting in any of the supported formats and observe that the modified setting value is in the debug output:

    • short-form -Skey=value:

      bin/logstash --log.level=debug -Snode.name=banana | grep 'node.name'
      
      [2025-04-23T16:39:57,851][DEBUG][logstash.runner          ] *node.name: banana (default: perhaps)
      
    • long-form arg pair --setting key:value:

      bin/logstash --log.level=debug --setting node.name:orange | grep 'node.name'
      
      [2025-04-23T16:40:01,001][DEBUG][logstash.runner          ] *node.name: orange (default: perhaps)
      
    • long-form single arg --setting=key:value:

      bin/logstash --log.level=debug --setting=node.name:grape | grep 'node.name'
      
      [2025-04-23T16:40:04,571][DEBUG][logstash.runner          ] *node.name: grape (default: perhaps)
      
  • Invoke with a non-coercible value to observe a helpful error message:

    bin/logstash --log.level=debug -Sapi.enabled=banana
    
    ERROR: failed to apply setting `api.enabled=banana`: Cannot coerce `banana` to boolean (api.enabled)
    
  • Invoke with an unregistered setting name to observe a helpful error message:

    bin/logstash --log.level=debug -Sfruit.favorite=banana
    
    ERROR: failed to apply setting `fruit.favorite=banana`: unknown setting `fruit.favorite`
    

Use cases

Simplifies testing by allowing integration test invocation to include any setting without needing to override the settings.yml that may or may not be provided by a fixture.

Logs

      arbitrary settings
        --setting=key:value formatted options
          when specifying `--setting=node.name:my-fancy-node-name --setting=api.enabled:false`
            overrides setting `node.name` to `my-fancy-node-name`
            overrides setting `api.enabled` to `false`
          when specifying `--setting=api.enabled:false`
            overrides setting `api.enabled` to `false`
          when specifying uncoercible `--setting=api.enabled:yellow`
            raises a helpful usage error about failed coercion
          when specifying unregistered `--setting=banana:yellow`
            raises a helpful usage error about the unknown setting
          when specifying `--setting=node.name:my-fancy-node-name`
            overrides setting `node.name` to `my-fancy-node-name`
        -Skey=value formatted options
          when specifying unregistered `-Sbanana=yellow`
            raises a helpful usage error about the unknown setting
          when specifying `-Snode.name=my-fancy-node-name -Sapi.enabled=false`
            overrides setting `node.name` to `my-fancy-node-name`
            overrides setting `api.enabled` to `false`
          when specifying uncoercible `-Sapi.enabled=yellow`
            raises a helpful usage error about failed coercion
          when specifying `-Snode.name=my-fancy-node-name`
            overrides setting `node.name` to `my-fancy-node-name`
          when specifying `-Sapi.enabled=false`
            overrides setting `api.enabled` to `false`
        --setting key:value formatted options
          when specifying `--setting api.enabled:false`
            overrides setting `api.enabled` to `false`
          when specifying `--setting node.name:my-fancy-node-name --setting api.enabled:false`
            overrides setting `api.enabled` to `false`
            overrides setting `node.name` to `my-fancy-node-name`
          when specifying unregistered `--setting banana:yellow`
            raises a helpful usage error about the unknown setting
          when specifying `--setting node.name:my-fancy-node-name`
            overrides setting `node.name` to `my-fancy-node-name`
          when specifying uncoercible `--setting api.enabled:yellow`
            raises a helpful usage error about failed coercion

When invoking Logstsh in test, it is often necessary to override a setting,
but cumbersome to provide a whole `logstash.yml` when there is no provided
command-line option paired with the setting.

This feature adds a _hidden_ `--setting` option with an `-S` shortname, whose
value is a colon- or equals-separated key-value pair.

 - long-form single arg: `--setting=queue.type:persisted`
 - long-form arg-pair: `--setting node.name:myname`
 - short-form: `-Squeue.type=persisted`

~~~
      arbitrary settings
        --setting=key:value formatted options
          when specifying `--setting=node.name:my-fancy-node-name --setting=api.enabled:false`
            overrides setting `node.name` to `my-fancy-node-name`
            overrides setting `api.enabled` to `false`
          when specifying `--setting=api.enabled:false`
            overrides setting `api.enabled` to `false`
          when specifying uncoercible `--setting=api.enabled:yellow`
            raises a helpful usage error about failed coercion
          when specifying unregistered `--setting=banana:yellow`
            raises a helpful usage error about the unknown setting
          when specifying `--setting=node.name:my-fancy-node-name`
            overrides setting `node.name` to `my-fancy-node-name`
        -Skey=value formatted options
          when specifying unregistered `-Sbanana=yellow`
            raises a helpful usage error about the unknown setting
          when specifying `-Snode.name=my-fancy-node-name -Sapi.enabled=false`
            overrides setting `node.name` to `my-fancy-node-name`
            overrides setting `api.enabled` to `false`
          when specifying uncoercible `-Sapi.enabled=yellow`
            raises a helpful usage error about failed coercion
          when specifying `-Snode.name=my-fancy-node-name`
            overrides setting `node.name` to `my-fancy-node-name`
          when specifying `-Sapi.enabled=false`
            overrides setting `api.enabled` to `false`
        --setting key:value formatted options
          when specifying `--setting api.enabled:false`
            overrides setting `api.enabled` to `false`
          when specifying `--setting node.name:my-fancy-node-name --setting api.enabled:false`
            overrides setting `api.enabled` to `false`
            overrides setting `node.name` to `my-fancy-node-name`
          when specifying unregistered `--setting banana:yellow`
            raises a helpful usage error about the unknown setting
          when specifying `--setting node.name:my-fancy-node-name`
            overrides setting `node.name` to `my-fancy-node-name`
          when specifying uncoercible `--setting api.enabled:yellow`
            raises a helpful usage error about failed coercion
~~~
Copy link

mergify bot commented Apr 23, 2025

This pull request does not have a backport label. Could you fix it @yaauie? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit.
  • If no backport is necessary, please add the backport-skip label

Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@elasticmachine
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Copy link
Contributor

@mashhurs mashhurs left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

@donoghuc
Copy link
Member

Looks like this handles bool, numeric, string. Are more complex setting types handled? For example can api.ssl.supported_protocols (appears to support accepting a list) be set on CLI?

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.

4 participants