sensu / sensu-go

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

Resource wrapping in Sensu 7.x #5018

Closed echlebek closed 1 year ago

echlebek commented 1 year ago

Sensu 7 will change how so-called "wrapped resources" are portrayed and worked with.

In Sensu 6, users can create resources of any type by wrapping them and handing them to sensuctl. The wrapper includes type information so that sensuctl can determine the correct resource URL to apply them to.

To facilitate things like dump/restore, and editing, we decided to allow dumping wrapped resources as well.

But this lead to confusion, since the resource URLs themselves didn't support wrapping. This inconsistency became a common question about how Sensu's API worked.

For Sensu 7, we're going to wrap all resources when they are returned from APIs, instead of wrapping them client side. All APIs will accept wrapped resources as well.

In Sensu 6, the wrapper could house object metadata like labels and annotations. This metadata was then aliased in the resource itself, creating a confusing scenario for users that necessitated weird hacks internally. In Sensu 7, this aliasing will be removed. Object metadata will only exist in the resources themselves, not the wrapper bearing their type information.

For example, here is a Sensu 6 wrapped resource document.

type: Entity
api_version: core/v2
metadata:
  name: raspi
  namespace: default
spec:
  deregister: false
  entity_class: agent
  last_seen: 1685563628
  sensu_agent_version: 6.9.1
  subscriptions:
  - entity:raspi
  system:
    arch: arm64
    hostname: raspi
    libc_type: glibc
    network: (redacted)
    os: linux
    platform: raspbian
    platform_family: debian
    platform_version: "11.5"
  user: agent

Here is the same document converted to work with Sensu 7. Note that the metadata is now nested underneath the "spec" object.

type: Entity
api_version: core/v2
spec:
  deregister: false
  entity_class: agent
  last_seen: 1685563628
  metadata:
    name: raspi
    namespace: default
  sensu_agent_version: 6.9.1
  subscriptions:
  - entity:raspi
  system:
    arch: arm64
    hostname: raspi
    libc_type: glibc
    network: (redacted)
    os: linux
    platform: raspbian
    platform_family: debian
    platform_version: "11.5"
  user: agent

Why do this? Well internally, the metadata is already represented in the resource, and in fact is rendered in there when the resource isn't wrapped. This makes things really confusing when a user is trying to do an HTTP PATCH on a document or something similar.

~Sensu will be providing tooling to convert the Sensu 6 definitions into Sensu 7 definitions, so that users don't have to manually edit all of their existing configuration.~

Unfortunately Sensu will not be providing tooling for this, or, in fact, existing. :cry: