-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
fix(inputs.opcua): Auto fan out array nodes into individual fields #16359
base: master
Are you sure you want to change the base?
Conversation
Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your fix @inhinias! I do have one comment in the code. Furthermore, I wonder if we can get rid of the reflection in here and do explicit type assertions?
Could you also please provide a unit-test so we don't run into this again?
valueArray := unpackArray(o.LastReceivedData[nodeIdx].Value) | ||
if len(valueArray) == int(o.LastReceivedData[nodeIdx].ArrayLength) { | ||
for index, value := range valueArray { | ||
var sb strings.Builder | ||
sb.WriteString(nmm.Tag.FieldName) | ||
sb.WriteString(strconv.Itoa(int(index))) | ||
fields[sb.String()] = value | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about folding the unpackArray
function into here and reuse its for
loop? This saves both allocations and loop iterations...
Summary
Reading an entire OPC-UA array results in the metric creation to fail silently and reading an individual array element result in a bad node ID.
This PR detects an array and fans it out. So a read array results in each index being collected as a separate metric e.g: MetricName + Index.
This is just a simple way to get it to work. Maybe there is a way to store entire array as a metric, but I'm not all too familiar with the codebase as a whole. Options welcome.
Also Note:
Checklist
Related issues
resolves #11898