open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
3.08k stars 2.38k forks source link

[pkg/ottl] Allow indexing any slice type #29441

Open TylerHelmuth opened 11 months ago

TylerHelmuth commented 11 months ago

I was just shown the scenario

set(resource.attributes["my.environment.2"], Split(resource.attributes["host.name"],"-")[1])

that produces an error:

{"kind": "processor", "name": "transform", "pipeline": "logs", "error": "type, []string, does not support int indexing", "statement": "set(resource.attributes[\"my.environment.2\"], Split(resource.attributes[\"host.name\"],\"-\")[1])"}

Although the language does support indexing the return value of the Converter, it only supports indexing pcommon.Slice and []any, but Split returns a []string. We need to make indexing slices more generic. This might need to be its own issue. Related code: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/60430e1f4c2bdb8579fc080d5f3a6c8f15730a4b/pkg/ottl/expression.go#L98-L112

Originally posted by @TylerHelmuth in https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/26108#issuecomment-1821560835

github-actions[bot] commented 9 months ago

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

SplitThePotCyrus commented 8 months ago

Yes please, fix for this would be great.

I've been trying to figure out this issue for a half a day, until I found this just now. 😓 Now I have to figure out how to accomplish what I need in a different way.

TylerHelmuth commented 8 months ago

The workaround for this issue is to use cache. set(resource.attributes["my.environment.2"], Split(resource.attributes["host.name"],"-")[1]) becomes:

set(cache["temp"], Split(resource.attributes["host.name"],"-"))
set(resource.attributes["my.environment.2"], cache["temp"][1])
github-actions[bot] commented 6 months ago

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

github-actions[bot] commented 4 months ago

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

evan-bradley commented 4 months ago

At a minimum, we should achieve type coverage for all types that OTTL supports. If possible, a generic solution would be nice, assuming we can do this with either reflection or some creative type casting.

evan-bradley commented 1 month ago

35581 only added support for string slices, we still need support for slices of types that OTTL supports.