-
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
feat(inputs.opcua_listener): OPC UA Event subscriptions #11786
Conversation
0a2719d
to
1c00277
Compare
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.
Not yet reviewed all files, but already some minor comments..
9714607
to
0357699
Compare
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.
First of all thanks @LarsStegman for the huge undertaking to clean this up. Much appreciated! Before going into a more detailed review I have some more general questions:
- Can you please more
internal/opcua
toplugins/common/opcua
as this is where we should keep plugin related things. - Is it possible to mimick the behavior of the HTTP common part (in
plugins/common/http
) with a shared config and a defined way to create a client from it? This client would then provide the interface functions you define. - Does it make sense to split the opcu plugin into one actively querying part (named
opcu
) and a listening part namedopcua_listener
oropcua_consumer
? This way, you don't need to deal with partially overlapping config options and stuff but rather move common things to the common part and keep distictive code in the corresponding plugin.
Looking forward to hearing your opinion!
internal/opcua/client.go
Outdated
type OpcUAClient struct { | ||
Config *OpcUAClientConfig | ||
Log telegraf.Logger | ||
|
||
State ConnectionState | ||
Client *opcua.Client | ||
|
||
opts []opcua.Option | ||
codes []ua.StatusCode | ||
} |
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.
I guess both State
and Client
don't need to be exported, do they? Furthermore, you probably want to generate the client from a given config (similar to http's common part) and do not need to store it internaly...
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.
Client and State need to be exported, because the OpcUAClient is now in the common package and SubscribeClient and ReadClient need access to it.
I do not entirely understand what you mean with generating the Client from a config and not needing to store it internally. We need the client in memory, because we need to maintain a connection to the server.
internal/opcua/client.go
Outdated
|
||
switch u.Scheme { | ||
case "opc.tcp": | ||
o.State = Connecting |
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.
Why do we need this state-tracking? Isn't the state encoded in the existence of the client?
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.
This was already in the original code.
There was some discussion on it here, so I'm hesitant to remove it.
Yes, I will do this.
I think this should be possible. I will look into it. I wasn't very happy with how the client creation was done anyway, but I hadn't found a better solution.
This might be a good idea. This will be much easier now that the new configuration loading structure has been adopted everywhere. When I implemented this, that wasn't the case yet, so loading the configuration would have been much more of a hassle. I am a bit worried about having to maintain two example configs, but I think this is not that big of a problem. |
I will fix the build failing tomorrow |
a6bf8d5
to
07249c9
Compare
@Hipska any idea what is triggering the CI? I can't find it. |
07249c9
to
fb0fce0
Compare
28eb435
to
81e6856
Compare
81e6856
to
87e82ff
Compare
87e82ff
to
cffcd9b
Compare
cffcd9b
to
b802134
Compare
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 driving this!
Download PR build artifacts for linux_amd64.tar.gz, darwin_amd64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
🎉 |
Required for all PRs
resolves #8083
Refactored the opc ua plugin to use a more generic structure. This allows easy injection of either the read client or a subscription client.
I extracted the logic for an opc ua client into an
/internal/opcua
package, as the same client logic could be reused for creating an opcua client output plugin.It has become quite a big pull request, so please be thorough with your reviews.
There should be no breaking changes, as by default the
request
service is used. This PR is purely additive.