Skip to content

river/vm: support decoding blocks into map[string]T#3232

Merged
rfratto merged 2 commits into
grafana:mainfrom
rfratto:blocks-to-map
Mar 10, 2023
Merged

river/vm: support decoding blocks into map[string]T#3232
rfratto merged 2 commits into
grafana:mainfrom
rfratto:blocks-to-map

Conversation

@rfratto
Copy link
Copy Markdown
Member

@rfratto rfratto commented Mar 10, 2023

This allows decoding blocks into maps instead of structs. The map type can be any map[string]T, which is useful of the map values must always be a consistent type. If map values can be anything, use map[string]any for decoding.

Additionally, if decoding into an interface{}, it will default to map[string]any when decoding.

When decoding into a map, nested blocks aren't allowed and will be rejected.

Closes #2903, and unlocks module loader components to accept arguments to propagate to the module as a block rather than an object.

This is not added to the changelog because this is not a user-facing change.

@rfratto rfratto force-pushed the blocks-to-map branch 3 times, most recently from 1225c69 to a760975 Compare March 10, 2023 00:41
This allows decoding blocks into maps instead of structs. The map type
can be any map[string]T, which is useful of the map values must always
be a consistent type. If map values can be anything, use map[string]any
for decoding.

Additionally, if decoding into an interface{}, it will default to
map[string]any when decoding.

When decoding into a map, nested blocks aren't allowed and will be
rejected.

Closes grafana#2903.
Copy link
Copy Markdown
Contributor

@erikbaranowski erikbaranowski left a comment

Choose a reason for hiding this comment

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

LGTM

@rfratto rfratto merged commit fde4f68 into grafana:main Mar 10, 2023
rfratto added a commit to rfratto/agent that referenced this pull request Apr 13, 2023
Add support for map[string]T blocks to river/encoding, first added in grafana#3232.
rfratto added a commit that referenced this pull request Apr 13, 2023
* river/encoding: support map[string]T blocks

Add support for map[string]T blocks to river/encoding, first added in #3232.

* river/encoding: address review feedback
clayton-cornell pushed a commit that referenced this pull request Aug 14, 2023
* river/encoding: support map[string]T blocks

Add support for map[string]T blocks to river/encoding, first added in #3232.

* river/encoding: address review feedback
clayton-cornell pushed a commit that referenced this pull request Aug 14, 2023
* river/encoding: support map[string]T blocks

Add support for map[string]T blocks to river/encoding, first added in #3232.

* river/encoding: address review feedback
@github-actions github-actions Bot added the frozen-due-to-age Locked due to a period of inactivity. Please open new issues or PRs if more discussion is needed. label Mar 5, 2024
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Locked due to a period of inactivity. Please open new issues or PRs if more discussion is needed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

River: permit unmarshaling blocks to maps

2 participants