sensu / sensu-go

Simple. Scalable. Multi-cloud monitoring.
https://sensu.io
MIT License
1.03k stars 175 forks source link

sensuctl [resource] create [resource-name] does not automatically add sensu.io/managed_by: sensuctl label #4220

Open hillaryfraley opened 3 years ago

hillaryfraley commented 3 years ago

Expected Behavior

We've documented that for resources created with sensuctl, Sensu automatically adds the sensu.io/managed_by: sensuctl label in the resource definition. It seems reasonable to expect that both methods of adding a resource via sensuctl will automatically create the sensu.io/managed_by: sensuctl label:

sensuctl create --file resource.yml (see https://docs.sensu.io/sensu-go/latest/sensuctl/create-manage-resources/#create-resources for an example) sensuctl resource create resource-name \ (see https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-schedule/collect-metrics-with-checks/#create-a-check-to-collect-metrics for an example)

For an example of how we have documented this, see the first NOTE under https://docs.sensu.io/sensu-go/latest/sensuctl/create-manage-resources/#sensuctl-prune

Current Behavior

Sensu automatically adds the sensu.io/managed_by: sensuctl label in the resource definition only if you use the sensuctl create --file resource.yml option and create resources from a file.

We use the other method sensuctl resource create resource-name \ to create resources in much of our documentation, and this does not automatically add the label to the resource definition.

Possible Solution

Fix the multi-line method of creating a resource with sensuctl so that it also automatically adds the sensu.io/managed_by: sensuctl label in the resource definition. This way, the behavior is consistent for both methods.

Steps to Reproduce (for bugs)

  1. Use the multi-line command example at https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-schedule/collect-metrics-with-checks/#create-a-check-to-collect-metrics to create the collect-metrics check with sensuctl.
  2. Run sensuctl check info collect-metrics --format yaml or GET http://127.0.0.1:8080/api/core/v2/namespaces/default/checks/collect-metrics
  3. The response body does not include the sensu.io/managed_by: sensuctl label
  4. Save the following resource definition to a file metrics.yml:
    type: CheckConfig
    api_version: core/v2
    metadata:
    name: collect-metrics
    spec:
    check_hooks: null
    command: metrics-disk-usage.rb
    env_vars: null
    handlers: []
    high_flap_threshold: 0
    interval: 60
    low_flap_threshold: 0
    output_metric_format: nagios_perfdata
    output_metric_handlers: null
    proxy_entity_name: ""
    publish: true
    round_robin: false
    runtime_assets:
    - sensu-plugins/sensu-plugins-disk-checks
    - sensu/sensu-ruby-runtime
    secrets: null
    stdin: false
    subdue: null
    subscriptions:
    - linux
    timeout: 0
    ttl: 0
  5. Run sensuctl create --file metrics.yml
  6. Run sensuctl check info collect-metrics --format yaml or GET http://127.0.0.1:8080/api/core/v2/namespaces/default/checks/collect-metrics
  7. The response body does include the sensu.io/managed_by: sensuctl label

Context

Slack discussion: https://sensu.slack.com/archives/C60EEQFH8/p1615327340399800

Your Environment

portertech commented 3 years ago

Changing the behaviour may go against our intent while designing the Prune feature.

portertech commented 3 years ago

@calebhailey I'd like to cover this one on our product review this friday.