influxdata / influxdata/telegraf

Request Metrics.go convertField to add addional array types

Open
#13,041 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request help wanted size/l
Dominant language
Go
Stars
17.8k
Forks
5.8k
Avg merge
1d 20h
Merged PRs (30d)
161

Description

### Use Case

I have an OPC UA server that provides array data as `[]int32` `[]float64` and `[]string`.

For me I changed/added metric.go (function convertField) as following:

```
+ case []int32:
+ return []int32(v)
+ case []string:
+ return []string(v)
+ case []float64:
+ return []float64(v)
case *int16:
if v != nil {
return int64(*v)
```

This works for output.File with type JSON.
I do not know the side effects, but may be it helps others... or someone could check it for side effects...

[metrics_int32_float32_string_array.patch](https://github.com/influxdata/telegraf/files/11162277/metrics_int32_float32_string_array.patch)

### Expected behavior

I want to output also array-type OPC UA data to (JSON) files. (only one I tested, may be works also with other plugins)

### Actual behavior

Without the mentioned patch it does not store the array values to the file.
The function `convertField` returns nil for `[]int32` `[]float64` and `[]string` so that the field is not written to output.

### Additional info

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in metric.go at convertField and inspect how output.File serializes fields as JSON. Compare the handling of []int32, []float64, and []string with the provided patch, then verify that array values are retained in JSON output without changing existing conversions.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, json
Domain
data
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.