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

fix: Add support for opcua datetime values #12101

Merged
merged 8 commits into from
Nov 7, 2022

Conversation

vsinha
Copy link
Contributor

@vsinha vsinha commented Oct 25, 2022

Resolves #12006

This PR adds support for returning OPCUA DateTime values via the opc-ua input plugin. Prior to this PR, we silently drop those values. Reopened because I made a mistake in #12020.

Details

The gopcua library returns these values as the time.Time type, which telegraf doesn't handle in metric.go:convertField. To make the smallest change possible, we simply convert the datetime value to a string in the default golang format before returning the updated value.

Example

Example telegraf.toml

[inputs.opcua]
  # Authentication details redacted
  nodes = [
  {name="TimeEnded", namespace="4", identifier_type="s", identifier="TimeEnded"},
  ]

Before:

Notice the TimeEnded value has Quality=OK but the time value itself has failed to parse or be returned. This is because it falls into the default case in metric.go:convertField

❯ go run ./cmd/telegraf --config ~/telegraf-config-file.toml --test
...
2022-10-14T17:42:28Z D! [agent] Starting service inputs
> MACHINE123,host=HOST123,id=ns\=4;s\=TimeEnded Quality="OK (0x0)" 1665769360000000000
2022-10-14T17:42:40Z D! [agent] Stopping service inputs
2022-10-14T17:42:40Z D! [agent] Input channel closed
2022-10-14T17:42:40Z D! [agent] Stopped Successfully

After:

We return the time as a string as intended

❯ go run ./cmd/telegraf --config ~/telegraf-config-file.toml --test
...
2022-10-14T17:46:49Z D! [agent] Starting service inputs
> MACHINE123,host=HOST123,id=ns\=4;s\=TimeEnded "2022-10-18 02:13:29.222 +0000 UTC",Quality="OK (0x0)" 1665769610000000000
2022-10-14T17:46:50Z D! [agent] Stopping service inputs
2022-10-14T17:46:50Z D! [agent] Input channel closed
2022-10-14T17:46:50Z D! [agent] Stopped Successfully

@telegraf-tiger telegraf-tiger bot added the fix pr to fix corresponding bug label Oct 25, 2022
@vsinha
Copy link
Contributor Author

vsinha commented Oct 25, 2022

the windows test failed for a seemingly unrelated reason -- perhaps a flaky test?

=== FAIL: plugins/inputs/snmp TestGetSNMPConnectionTCP (unknown)
listen tcp 127.0.0.1:56789: bind: An attempt was made to access a socket in a way forbidden by its access permissions.panic: runtime error: invalid memory address or nil pointer dereference
	panic: sync: negative WaitGroup counter
[signal 0xc0000005 code=0x0 addr=0x0 pc=0xbed5b7]

goroutine 78 [running]:
sync.(*WaitGroup).Add(0xc0003a4dd0, 0xffffffffffffffff)
	C:/Program Files/Go/src/sync/waitgroup.go:83 +0x205
sync.(*WaitGroup).Done(0x0?)
	C:/Program Files/Go/src/sync/waitgroup.go:108 +0x36
panic({0xc646c0, 0x11fd670})
	C:/Program Files/Go/src/runtime/panic.go:890 +0x262
github.com/influxdata/telegraf/plugins/inputs/snmp.stubTCPServer(0xc0003a4dd0)
	C:/Users/circleci.PACKER-633B1A5A/project/plugins/inputs/snmp/snmp_test.go:327 +0x277
created by github.com/influxdata/telegraf/plugins/inputs/snmp.TestGetSNMPConnectionTCP
	C:/Users/circleci.PACKER-633B1A5A/project/plugins/inputs/snmp/snmp_test.go:292 +0xdb

@MyaLongmire
Copy link
Contributor

@vsinha maybe flaky, I have retriggered the test

@vsinha
Copy link
Contributor Author

vsinha commented Oct 25, 2022

@LarsStegman do you know where i should leave a test to make sure DateTimes serialize properly? The test as specified here is failing

@LarsStegman
Copy link
Contributor

Are you sure the NodeId is correct? Maybe the identifier type should be i instead of s, since the identifier is an integer.

@LarsStegman
Copy link
Contributor

That fixed the opcua tests, you can apply the same fix for the opcua_listener tests.

@MyaLongmire
Copy link
Contributor

@LarsStegman Thank you for your work and continued help with the opcua plugins!

@vsinha
Copy link
Contributor Author

vsinha commented Oct 27, 2022

@MyaLongmire all the tests are passing except the readme linter, where this PR doesn't contain any changes to any readmes. Is this something we can sidestep?

@MyaLongmire
Copy link
Contributor

@vsinha Yes we can sidestep it as it is failing on things you did not change :)

Copy link
Contributor

@MyaLongmire MyaLongmire left a comment

Choose a reason for hiding this comment

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

One other person from the team will need to also approve this before we can merge it.

@MyaLongmire MyaLongmire added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Oct 27, 2022
@powersj
Copy link
Contributor

powersj commented Oct 27, 2022

Questions before we land this:

MACHINE123,host=HOST123,id=ns=4;s=TimeEnded="2022-10-18 02:13:29.222 +0000 UTC",Quality="OK (0x0)" 1665769610000000000

Won't this increase the cardinality of a measurement greatly by having a possibly unique timestamp on every recording? If so, shouldn't this be a flag to enable this if you really want it? Or am I over estimating how often this tag value would change?

@LarsStegman
Copy link
Contributor

LarsStegman commented Oct 27, 2022

Is that valid line protocol? No additional tags should be created by this PR. DateTime values for fields should become formatted as strings instead of being dropped.

@powersj
Copy link
Contributor

powersj commented Oct 27, 2022

TIL: I can edit your comments... that is scary

Is that valid line protocol?

I didn't think it was. I was going off of what is in the initial PR comment and made me stop. Is this just a case of a missing space?

@LarsStegman
Copy link
Contributor

I think the field name is missing in the example. @vsinha can you confirm?

TIL: I can edit your comments... that is scary

😅

@vsinha
Copy link
Contributor Author

vsinha commented Oct 27, 2022

@powersj updated the comment, agreed that as it was there was a a=b=c situation going on. Must've been a mistype from redacting the details specific to our opcua host

@vsinha
Copy link
Contributor Author

vsinha commented Oct 31, 2022

@powersj @MyaLongmire anything else i should do to shepherd this PR along?

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

@vsinha looks good overall, I just added one suggestion... Can you please take a look!?

add type assertion so we don't panic if we fail to convert to a time string

Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
@vsinha
Copy link
Contributor Author

vsinha commented Nov 1, 2022

updated, thanks @srebhan

@vsinha
Copy link
Contributor Author

vsinha commented Nov 1, 2022

@srebhan @MyaLongmire any more pieces of feedback? or are we ready to merge

Copy link
Contributor

@reimda reimda left a comment

Choose a reason for hiding this comment

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

Thanks for adding this feature!

@LarsStegman
Copy link
Contributor

Nice addition for the timestamp format. A suggestion, I would put the timestamp format in the InputClientConfig, as the value is used in the InputClient, not in the Client.

@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Nov 3, 2022

@vsinha
Copy link
Contributor Author

vsinha commented Nov 3, 2022

done!

@vsinha vsinha requested a review from reimda November 3, 2022 19:26
@vsinha
Copy link
Contributor Author

vsinha commented Nov 7, 2022

Hey @srebhan @MyaLongmire @reimda -- do you think this is something we could get merged this week? Our plan is to fork telegraf to get this bug fix deployed if it's not something that can be upstreamed (via this PR) relatively quickly. I'm happy to make any more changes but I'm getting antsy.

@MyaLongmire MyaLongmire merged commit e42b083 into influxdata:master Nov 7, 2022
@vsinha
Copy link
Contributor Author

vsinha commented Nov 7, 2022

🙌

@vsinha
Copy link
Contributor Author

vsinha commented Dec 20, 2022

@powersj @MyaLongmire could I get a copy of my countersigned CCLA for this PR? We'd like it for our own records. Thanks!

@powersj
Copy link
Contributor

powersj commented Jan 5, 2023

@vsinha - the form is a google docs form, so all I have is an entry in a spreadsheet.

@vsinha
Copy link
Contributor Author

vsinha commented Jan 18, 2023

@powersj I think the individual CLA was a google form but the CCLA was a pdf we had our legal team sign and upload, am I remembering that correctly?

@powersj
Copy link
Contributor

powersj commented Jan 18, 2023

@vsinha ah yes the CCLA is different. Let me ask if I copy can get sent to you.

@powersj
Copy link
Contributor

powersj commented Jan 19, 2023

@vsinha what email did you send the signed CCLA? Can you send them a message to get a copy please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix pr to fix corresponding bug ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OPCUA should support DateTime values
7 participants