Skip to content
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

[pkg/ottl] Add flatten function #30455

Merged
merged 8 commits into from
Jan 17, 2024

Conversation

TylerHelmuth
Copy link
Member

@TylerHelmuth TylerHelmuth commented Jan 11, 2024

Description:
Adds a flatten function that allows flattening maps.

I went with an editor instead of a converter, but I'm open to debate. Using an editor means that a user can do flatten(body) where IsMap(body) instead of `set(body, Flatten(body)) where IsMap(body). When using ParseJson you have to do:

- merge_maps(cache, ParseJSON(body), "upsert")
- flatten(cache)

instead of merge_maps(cache, Flatten(ParseJSON(body)), "upsert"). Ultimately I went with an editor for similar reasons that merge_maps is an editor: chaining too many functions together is messy and updating maps is very fast with pdata.

The function supports 2 optional parameters, prefix and depth. Use prefix to add a "namespace" to the values that are being flattened. Use depth to prevent trying to flatten maps that are too deep. See the function doc for examples.

Link to tracking Issue:

Closes #29283

Testing:
Added new unit and e2e tests. Please scrutinize.

Documentation:
Added function doc.

Copy link
Contributor

@evan-bradley evan-bradley left a comment

Choose a reason for hiding this comment

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

Looks good to me overall. I'm good with this being an Editor for the same reasons you called out.

pkg/ottl/ottlfuncs/README.md Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/README.md Outdated Show resolved Hide resolved
pkg/ottl/e2e/e2e_test.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_flatten.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_flatten_test.go Outdated Show resolved Hide resolved
Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
@TylerHelmuth TylerHelmuth merged commit ec21173 into open-telemetry:main Jan 17, 2024
85 checks passed
@TylerHelmuth TylerHelmuth deleted the ottl-flatten-function branch January 17, 2024 18:48
@github-actions github-actions bot added this to the next release milestone Jan 17, 2024
mfyuce pushed a commit to mfyuce/opentelemetry-collector-contrib that referenced this pull request Jan 18, 2024
**Description:**
Adds a `flatten` function that allows flattening maps.

I went with an editor instead of a converter, but I'm open to debate.
Using an editor means that a user can do `flatten(body) where
IsMap(body)` instead of `set(body, Flatten(body)) where IsMap(body).
When using ParseJson you have to do:

```
- merge_maps(cache, ParseJSON(body), "upsert")
- flatten(cache)
```

instead of `merge_maps(cache, Flatten(ParseJSON(body)), "upsert")`.
Ultimately I went with an editor for similar reasons that `merge_maps`
is an editor: chaining too many functions together is messy and updating
maps is very fast with pdata.

The function supports 2 optional parameters, `prefix` and `depth`. Use
`prefix` to add a "namespace" to the values that are being flattened.
Use `depth` to prevent trying to flatten maps that are too deep. See the
function doc for examples.

**Link to tracking Issue:** <Issue number if applicable>

Closes
open-telemetry#29283

**Testing:** <Describe what testing was performed and which tests were
added.>
Added new unit and e2e tests.  Please scrutinize.

**Documentation:** <Describe the documentation added.>
Added function doc.

---------

Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
cparkins pushed a commit to AmadeusITGroup/opentelemetry-collector-contrib that referenced this pull request Feb 1, 2024
**Description:**
Adds a `flatten` function that allows flattening maps.

I went with an editor instead of a converter, but I'm open to debate.
Using an editor means that a user can do `flatten(body) where
IsMap(body)` instead of `set(body, Flatten(body)) where IsMap(body).
When using ParseJson you have to do:

```
- merge_maps(cache, ParseJSON(body), "upsert")
- flatten(cache)
```

instead of `merge_maps(cache, Flatten(ParseJSON(body)), "upsert")`.
Ultimately I went with an editor for similar reasons that `merge_maps`
is an editor: chaining too many functions together is messy and updating
maps is very fast with pdata.

The function supports 2 optional parameters, `prefix` and `depth`. Use
`prefix` to add a "namespace" to the values that are being flattened.
Use `depth` to prevent trying to flatten maps that are too deep. See the
function doc for examples.

**Link to tracking Issue:** <Issue number if applicable>

Closes
open-telemetry#29283

**Testing:** <Describe what testing was performed and which tests were
added.>
Added new unit and e2e tests.  Please scrutinize.

**Documentation:** <Describe the documentation added.>
Added function doc.

---------

Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
anthoai97 pushed a commit to anthoai97/opentelemetry-collector-contrib that referenced this pull request Feb 12, 2024
**Description:**
Adds a `flatten` function that allows flattening maps.

I went with an editor instead of a converter, but I'm open to debate.
Using an editor means that a user can do `flatten(body) where
IsMap(body)` instead of `set(body, Flatten(body)) where IsMap(body).
When using ParseJson you have to do:

```
- merge_maps(cache, ParseJSON(body), "upsert")
- flatten(cache)
```

instead of `merge_maps(cache, Flatten(ParseJSON(body)), "upsert")`.
Ultimately I went with an editor for similar reasons that `merge_maps`
is an editor: chaining too many functions together is messy and updating
maps is very fast with pdata.

The function supports 2 optional parameters, `prefix` and `depth`. Use
`prefix` to add a "namespace" to the values that are being flattened.
Use `depth` to prevent trying to flatten maps that are too deep. See the
function doc for examples.

**Link to tracking Issue:** <Issue number if applicable>

Closes
open-telemetry#29283

**Testing:** <Describe what testing was performed and which tests were
added.>
Added new unit and e2e tests.  Please scrutinize.

**Documentation:** <Describe the documentation added.>
Added function doc.

---------

Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pkg/ottl] Support json flatten operations
4 participants