You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/08/01 17:10:58 UTC
[plc4x] branch develop updated (7bb17deee2 -> a5a5e94834)
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
from 7bb17deee2 feat(plc4go/opcua): add more stringers to structs
new 71521ebca0 fix(plc4go/opcua): fix issues with increments
new da34d61bcf fix(plc4go/opcua): ensure right atomic initialization
new a5a5e94834 refactor(plc4go/opcua): use keyed logging
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
plc4go/internal/opcua/Configuration.go | 2 +-
plc4go/internal/opcua/Connection.go | 10 +-
plc4go/internal/opcua/Driver.go | 10 +-
plc4go/internal/opcua/EncryptionHandler.go | 2 +-
plc4go/internal/opcua/MessageCodec.go | 3 +
plc4go/internal/opcua/SecureChannel.go | 107 +++++++++++++--------
.../opcua/SecureChannelTransactionManager.go | 12 +--
plc4go/internal/opcua/Subscriber.go | 1 +
plc4go/internal/opcua/SubscriptionHandle.go | 15 ++-
plc4go/internal/opcua/common.go | 6 +-
10 files changed, 107 insertions(+), 61 deletions(-)
[plc4x] 01/03: fix(plc4go/opcua): fix issues with increments
Posted by sr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 71521ebca0336527bc1e8632641799ccafb597fd
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Aug 1 18:45:13 2023 +0200
fix(plc4go/opcua): fix issues with increments
---
plc4go/internal/opcua/Connection.go | 2 ++
plc4go/internal/opcua/MessageCodec.go | 3 +++
plc4go/internal/opcua/SecureChannel.go | 4 +++-
plc4go/internal/opcua/SecureChannelTransactionManager.go | 2 +-
plc4go/internal/opcua/Subscriber.go | 1 +
plc4go/internal/opcua/SubscriptionHandle.go | 2 +-
6 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/plc4go/internal/opcua/Connection.go b/plc4go/internal/opcua/Connection.go
index b5ea89a257..39e452abd0 100644
--- a/plc4go/internal/opcua/Connection.go
+++ b/plc4go/internal/opcua/Connection.go
@@ -232,6 +232,7 @@ func (c *Connection) startSubscriptionHandler() {
}
func (c *Connection) fireConnectionError(err error, ch chan<- plc4go.PlcConnectionConnectResult) {
+ c.log.Trace().Err(err).Msg("fire connection error")
if c.driverContext.awaitSetupComplete {
ch <- _default.NewDefaultPlcConnectionConnectResult(nil, errors.Wrap(err, "Error during connection"))
} else {
@@ -243,6 +244,7 @@ func (c *Connection) fireConnectionError(err error, ch chan<- plc4go.PlcConnecti
}
func (c *Connection) fireConnected(ch chan<- plc4go.PlcConnectionConnectResult) {
+ c.log.Trace().Msg("fire connected")
if c.driverContext.awaitSetupComplete {
ch <- _default.NewDefaultPlcConnectionConnectResult(c, nil)
} else {
diff --git a/plc4go/internal/opcua/MessageCodec.go b/plc4go/internal/opcua/MessageCodec.go
index 1114303dd2..b82b653c8f 100644
--- a/plc4go/internal/opcua/MessageCodec.go
+++ b/plc4go/internal/opcua/MessageCodec.go
@@ -77,6 +77,7 @@ func (m *MessageCodec) Connect() error {
}
func (m *MessageCodec) ConnectWithContext(ctx context.Context) error {
+ m.log.Trace().Msg("connecting")
if err := m.DefaultCodec.ConnectWithContext(ctx); err != nil {
return errors.Wrap(err, "error connecting default codec")
}
@@ -94,10 +95,12 @@ func (m *MessageCodec) ConnectWithContext(ctx context.Context) error {
}
func (m *MessageCodec) fireConnected() {
+ m.log.Trace().Msg("fire connected event")
close(m.connectEvent)
}
func (m *MessageCodec) Disconnect() error {
+ m.log.Trace().Msg("disconnecting")
m.channel.onDisconnect(context.Background(), m)
disconnectTimeout := time.NewTimer(m.disconnectTimeout)
select {
diff --git a/plc4go/internal/opcua/SecureChannel.go b/plc4go/internal/opcua/SecureChannel.go
index 46278043c1..f4ce897b67 100644
--- a/plc4go/internal/opcua/SecureChannel.go
+++ b/plc4go/internal/opcua/SecureChannel.go
@@ -267,6 +267,7 @@ func (s *SecureChannel) submit(ctx context.Context, codec *MessageCodec, errorDi
}
func (s *SecureChannel) onConnect(ctx context.Context, codec *MessageCodec) {
+ s.log.Trace().Msg("on connect")
// Only the TCP transport supports login.
s.log.Debug().Msg("Opcua Driver running in ACTIVE mode.")
s.codec = codec
@@ -280,6 +281,7 @@ func (s *SecureChannel) onConnect(ctx context.Context, codec *MessageCodec) {
s.endpoint)
requestConsumer := func(transactionId int32) {
+ s.log.Trace().Int32("transactionId", transactionId).Msg("request consumer called")
if err := codec.SendRequest(
ctx,
hello,
@@ -1392,7 +1394,7 @@ func (s *SecureChannel) keepAlive() {
// getRequestHandle returns the next request handle
func (s *SecureChannel) getRequestHandle() uint32 {
- return s.requestHandleGenerator.Add(1)
+ return s.requestHandleGenerator.Add(1) - 1
}
// getAuthenticationToken returns the authentication token for the current connection
diff --git a/plc4go/internal/opcua/SecureChannelTransactionManager.go b/plc4go/internal/opcua/SecureChannelTransactionManager.go
index 3214d79fd1..2fe77a4938 100644
--- a/plc4go/internal/opcua/SecureChannelTransactionManager.go
+++ b/plc4go/internal/opcua/SecureChannelTransactionManager.go
@@ -74,7 +74,7 @@ func (m *SecureChannelTransactionManager) submit(onSend func(transactionId int32
}
func (m *SecureChannelTransactionManager) getTransactionIdentifier() int32 {
- return m.transactionIdentifierGenerator.Add(1)
+ return m.transactionIdentifierGenerator.Add(1) - 1
}
func (m *SecureChannelTransactionManager) getActiveTransactionIdentifier() int32 {
diff --git a/plc4go/internal/opcua/Subscriber.go b/plc4go/internal/opcua/Subscriber.go
index ebf3921110..8ce354e678 100644
--- a/plc4go/internal/opcua/Subscriber.go
+++ b/plc4go/internal/opcua/Subscriber.go
@@ -195,6 +195,7 @@ func (s *Subscriber) onSubscribeCreateSubscription(ctx context.Context, cycleTim
}
func (s *Subscriber) onDisconnect(codec *MessageCodec) {
+ s.log.Trace().Msg("disconnecting")
for _, handle := range s.subscriptions {
handle.stopSubscriber()
}
diff --git a/plc4go/internal/opcua/SubscriptionHandle.go b/plc4go/internal/opcua/SubscriptionHandle.go
index 15a601267e..a921705e58 100644
--- a/plc4go/internal/opcua/SubscriptionHandle.go
+++ b/plc4go/internal/opcua/SubscriptionHandle.go
@@ -104,7 +104,7 @@ func (h *SubscriptionHandle) onSubscribeCreateMonitoredItemsRequest() (readWrite
monitoringMode = readWriteModel.MonitoringMode_monitoringModeReporting
}
- clientHandle := h.clientHandles.Add(1)
+ clientHandle := h.clientHandles.Add(1) - 1
parameters := readWriteModel.NewMonitoringParameters(
clientHandle,
[plc4x] 02/03: fix(plc4go/opcua): ensure right atomic initialization
Posted by sr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit da34d61bcf8237667f57ca3f07672788b50588a6
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Aug 1 18:47:50 2023 +0200
fix(plc4go/opcua): ensure right atomic initialization
---
plc4go/internal/opcua/SecureChannel.go | 3 +++
plc4go/internal/opcua/SubscriptionHandle.go | 1 +
2 files changed, 4 insertions(+)
diff --git a/plc4go/internal/opcua/SecureChannel.go b/plc4go/internal/opcua/SecureChannel.go
index f4ce897b67..d6fc7211ed 100644
--- a/plc4go/internal/opcua/SecureChannel.go
+++ b/plc4go/internal/opcua/SecureChannel.go
@@ -143,6 +143,9 @@ func NewSecureChannel(log zerolog.Logger, ctx DriverContext, configuration Confi
lifetime: DEFAULT_CONNECTION_LIFETIME,
log: log,
}
+ s.requestHandleGenerator.Store(1)
+ s.channelId.Store(1)
+ s.tokenId.Store(1)
ckp := configuration.ckp
if configuration.securityPolicy == "Basic256Sha256" {
//Sender Certificate gets populated during the 'discover' phase when encryption is enabled.
diff --git a/plc4go/internal/opcua/SubscriptionHandle.go b/plc4go/internal/opcua/SubscriptionHandle.go
index a921705e58..483b69f7df 100644
--- a/plc4go/internal/opcua/SubscriptionHandle.go
+++ b/plc4go/internal/opcua/SubscriptionHandle.go
@@ -66,6 +66,7 @@ func NewSubscriptionHandle(log zerolog.Logger, subscriber *Subscriber, messageCo
cycleTime: cycleTime,
log: log,
}
+ s.clientHandles.Store(1)
s.DefaultPlcSubscriptionHandle = spiModel.NewDefaultPlcSubscriptionHandleWithHandleToRegister(subscriber, s)
_, err := s.onSubscribeCreateMonitoredItemsRequest()
if err != nil {
[plc4x] 03/03: refactor(plc4go/opcua): use keyed logging
Posted by sr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit a5a5e948343d79bb7c62f62e3b84524186ac83fc
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Aug 1 19:10:51 2023 +0200
refactor(plc4go/opcua): use keyed logging
---
plc4go/internal/opcua/Configuration.go | 2 +-
plc4go/internal/opcua/Connection.go | 8 +-
plc4go/internal/opcua/Driver.go | 10 ++-
plc4go/internal/opcua/EncryptionHandler.go | 2 +-
plc4go/internal/opcua/SecureChannel.go | 100 +++++++++++++--------
.../opcua/SecureChannelTransactionManager.go | 10 +--
plc4go/internal/opcua/SubscriptionHandle.go | 12 ++-
plc4go/internal/opcua/common.go | 6 +-
8 files changed, 92 insertions(+), 58 deletions(-)
diff --git a/plc4go/internal/opcua/Configuration.go b/plc4go/internal/opcua/Configuration.go
index 850251ae50..21dcecea76 100644
--- a/plc4go/internal/opcua/Configuration.go
+++ b/plc4go/internal/opcua/Configuration.go
@@ -127,7 +127,7 @@ func getFromOptions(localLog zerolog.Logger, options map[string][]string, key st
return ""
}
if len(optionValues) > 1 {
- localLog.Warn().Msgf("Options %s must be unique", key)
+ localLog.Warn().Str("key", key).Msg("Options must be unique")
}
return optionValues[0]
}
diff --git a/plc4go/internal/opcua/Connection.go b/plc4go/internal/opcua/Connection.go
index 39e452abd0..ace4a8b69a 100644
--- a/plc4go/internal/opcua/Connection.go
+++ b/plc4go/internal/opcua/Connection.go
@@ -183,7 +183,7 @@ func (c *Connection) UnsubscriptionRequestBuilder() apiModel.PlcUnsubscriptionRe
func (c *Connection) addSubscriber(subscriber *Subscriber) {
for _, sub := range c.subscribers {
if sub == subscriber {
- c.log.Debug().Msgf("Subscriber %v already added", subscriber)
+ c.log.Debug().Msgf("Subscriber already added\n%s", subscriber)
return
}
}
@@ -214,16 +214,16 @@ func (c *Connection) startSubscriptionHandler() {
// TODO: dispatch subs
/*
for monitoredSal := range c.messageCodec.monitoredSALs {
- salLogger.Trace().Msgf("got a SAL\n%v", monitoredSal)
+ salLogger.Trace().Msg("got a SAL\n%v", monitoredSal)
handled := false
for _, subscriber := range c.subscribers {
if ok := subscriber.handleMonitoredSAL(monitoredSal); ok {
- salLogger.Debug().Msgf("\n%v handled\n%s", subscriber, monitoredSal)
+ salLogger.Debug().Msg("\n%v handled\n%s", subscriber, monitoredSal)
handled = true
}
}
if !handled {
- salLogger.Debug().Msgf("SAL was not handled:\n%s", monitoredSal)
+ salLogger.Debug().Msg("SAL was not handled:\n%s", monitoredSal)
}
}*/
}
diff --git a/plc4go/internal/opcua/Driver.go b/plc4go/internal/opcua/Driver.go
index 530d03ab6f..f5a35cdfe3 100644
--- a/plc4go/internal/opcua/Driver.go
+++ b/plc4go/internal/opcua/Driver.go
@@ -62,12 +62,16 @@ func NewDriver(_options ...options.WithOption) plc4go.PlcDriver {
}
func (m *Driver) GetConnectionWithContext(ctx context.Context, transportUrl url.URL, transports map[string]transports.Transport, driverOptions map[string][]string) <-chan plc4go.PlcConnectionConnectResult {
- m.log.Debug().Stringer("transportUrl", &transportUrl).Msgf("Get connection for transport url with %d transport(s) and %d option(s)", len(transports), len(driverOptions))
+ m.log.Debug().
+ Stringer("transportUrl", &transportUrl).
+ Int("numberTransports", len(transports)).
+ Int("numberDriverOptions", len(driverOptions)).
+ Msg("Get connection for transport url")
// Get the transport specified in the url
transport, ok := transports[transportUrl.Scheme]
if !ok {
- m.log.Error().Stringer("transportUrl", &transportUrl).Msgf("We couldn't find a transport for scheme %s", transportUrl.Scheme)
+ m.log.Error().Stringer("transportUrl", &transportUrl).Str("scheme", transportUrl.Scheme).Msg("We couldn't find a transport for scheme")
return m.reportError(errors.Errorf("couldn't find transport for given transport url %v", transportUrl))
}
@@ -80,7 +84,7 @@ func (m *Driver) GetConnectionWithContext(ctx context.Context, transportUrl url.
append(m._options, options.WithCustomLogger(m.log))...,
)
if err != nil {
- m.log.Error().Err(err).Stringer("transportUrl", &transportUrl).Msgf("We couldn't create a transport instance for port %#v", driverOptions["defaultTcpPort"])
+ m.log.Error().Err(err).Stringer("transportUrl", &transportUrl).Strs("defaultTcpPort", driverOptions["defaultTcpPort"]).Msg("We couldn't create a transport instance for port")
return m.reportError(errors.Wrapf(err, "couldn't initialize transport configuration for given transport url %s", transportUrl.String()))
}
diff --git a/plc4go/internal/opcua/EncryptionHandler.go b/plc4go/internal/opcua/EncryptionHandler.go
index e209120e88..ed32ea4370 100644
--- a/plc4go/internal/opcua/EncryptionHandler.go
+++ b/plc4go/internal/opcua/EncryptionHandler.go
@@ -123,7 +123,7 @@ func (h *EncryptionHandler) encodeMessage(ctx context.Context, pdu readWriteMode
}
func (h *EncryptionHandler) decodeMessage(ctx context.Context, pdu readWriteModel.OpcuaAPU) (readWriteModel.OpcuaAPU, error) {
- h.log.Info().Msgf("Decoding Message with Security policy %s", h.securityPolicy)
+ h.log.Info().Str("securityPolicy", h.securityPolicy).Msg("Decoding Message with Security policy")
switch h.securityPolicy {
case "None":
return pdu, nil
diff --git a/plc4go/internal/opcua/SecureChannel.go b/plc4go/internal/opcua/SecureChannel.go
index d6fc7211ed..35b02b4f21 100644
--- a/plc4go/internal/opcua/SecureChannel.go
+++ b/plc4go/internal/opcua/SecureChannel.go
@@ -235,7 +235,10 @@ func (s *SecureChannel) submit(ctx context.Context, codec *MessageCodec, errorDi
} else {
messageBuffer = opcuaResponse.GetMessage()
if !(s.senderSequenceNumber.Add(1) == (opcuaResponse.GetSequenceNumber())) {
- s.log.Error().Msgf("Sequence number isn't as expected, we might have missed a packet. - %d != %d", s.senderSequenceNumber.Add(1), opcuaResponse.GetSequenceNumber())
+ s.log.Error().
+ Int32("senderSequenceNumber", s.senderSequenceNumber.Load()).
+ Int32("responseSequenceNumber", opcuaResponse.GetSequenceNumber()).
+ Msg("Sequence number isn't as expected, we might have missed a packet. - senderSequenceNumber != responseSequenceNumber")
codec.fireDisconnected()
}
}
@@ -263,7 +266,7 @@ func (s *SecureChannel) submit(ctx context.Context, codec *MessageCodec, errorDi
}
}
- s.log.Debug().Msgf("Submitting Transaction to TransactionManager %v", transactionId)
+ s.log.Debug().Int32("transactionId", transactionId).Msg("Submitting Transaction to TransactionManager")
if err := s.channelTransactionManager.submit(requestConsumer, transactionId); err != nil {
s.log.Debug().Err(err).Msg("error submitting")
}
@@ -439,9 +442,10 @@ func (s *SecureChannel) onConnectOpenSecureChannel(ctx context.Context, codec *M
if fault, ok := extensionObject.GetBody().(readWriteModel.ServiceFaultExactly); ok {
statusCode := fault.GetResponseHeader().(readWriteModel.ResponseHeader).GetServiceResult().GetStatusCode()
statusCodeByValue, _ := readWriteModel.OpcuaStatusCodeByValue(statusCode)
- s.log.Error().Msgf("Failed to connect to opc ua server for the following reason:- %v, %v",
- statusCode,
- statusCodeByValue)
+ s.log.Error().
+ Uint32("statusCode", statusCode).
+ Stringer("statusCodeByValue", statusCodeByValue).
+ Msg("Failed to connect to opc ua server for the following reason")
} else {
s.log.Debug().Msg("Got Secure Response Connection Response")
openSecureChannelResponse := extensionObject.GetBody().(readWriteModel.OpenSecureChannelResponse)
@@ -460,7 +464,7 @@ func (s *SecureChannel) onConnectOpenSecureChannel(ctx context.Context, codec *M
s.log.Debug().Err(err).Msg("a error")
}
}
- s.log.Debug().Msgf("Submitting OpenSecureChannel with id of %d", transactionId)
+ s.log.Debug().Int32("transactionId", transactionId).Msg("Submitting OpenSecureChannel with id")
if err := s.channelTransactionManager.submit(requestConsumer, transactionId); err != nil {
s.log.Debug().Err(err).Msg("error submitting")
}
@@ -540,9 +544,10 @@ func (s *SecureChannel) onConnectCreateSessionRequest(ctx context.Context, codec
if fault, ok := message.GetBody().(readWriteModel.ServiceFaultExactly); ok {
statusCode := fault.GetResponseHeader().(readWriteModel.ResponseHeader).GetServiceResult().GetStatusCode()
statusCodeByValue, _ := readWriteModel.OpcuaStatusCodeByValue(statusCode)
- s.log.Error().Msgf("Failed to connect to opc ua server for the following reason:- %v, %v",
- statusCode,
- statusCodeByValue)
+ s.log.Error().
+ Uint32("statusCode", statusCode).
+ Stringer("statusCodeByValue", statusCodeByValue).
+ Msg("Failed to connect to opc ua server for the following reason")
} else {
s.log.Debug().Msg("Got Create Session Response Connection Response")
@@ -559,7 +564,9 @@ func (s *SecureChannel) onConnectCreateSessionRequest(ctx context.Context, codec
} else {
serviceFault := unknownExtensionObject.(readWriteModel.ServiceFault)
header := serviceFault.GetResponseHeader().(readWriteModel.ResponseHeader)
- s.log.Error().Msgf("Subscription ServiceFault returned from server with error code, '%s'", header.GetServiceResult())
+ s.log.Error().
+ Stringer("serviceResult", header.GetServiceResult()).
+ Msg("Subscription ServiceFault returned from server with error code, '%s'")
}
}
}
@@ -655,9 +662,10 @@ func (s *SecureChannel) onConnectActivateSessionRequest(ctx context.Context, cod
if fault, ok := message.GetBody().(readWriteModel.ServiceFaultExactly); ok {
statusCode := fault.GetResponseHeader().(readWriteModel.ResponseHeader).GetServiceResult().GetStatusCode()
statusCodeByValue, _ := readWriteModel.OpcuaStatusCodeByValue(statusCode)
- s.log.Error().Msgf("Failed to connect to opc ua server for the following reason:- %v, %v",
- statusCode,
- statusCodeByValue)
+ s.log.Error().
+ Uint32("statusCode", statusCode).
+ Stringer("statusCodeByValue", statusCodeByValue).
+ Msg("Failed to connect to opc ua server for the following reason")
} else {
s.log.Debug().Msg("Got Activate Session Response Connection Response")
@@ -670,7 +678,10 @@ func (s *SecureChannel) onConnectActivateSessionRequest(ctx context.Context, cod
if responseMessage, ok := unknownExtensionObject.(readWriteModel.ActivateSessionResponseExactly); ok {
returnedRequestHandle := responseMessage.GetResponseHeader().(readWriteModel.ResponseHeader).GetRequestHandle()
if !(requestHandle == returnedRequestHandle) {
- s.log.Error().Msgf("Request handle isn't as expected, we might have missed a packet. %d != %d", requestHandle, returnedRequestHandle)
+ s.log.Error().
+ Uint32("requestHandle", requestHandle).
+ Uint32("returnedRequestHandle", returnedRequestHandle).
+ Msg("Request handle isn't as expected, we might have missed a packet. requestHandle != returnedRequestHandle")
}
// Send an event that connection setup is complete.
@@ -679,7 +690,9 @@ func (s *SecureChannel) onConnectActivateSessionRequest(ctx context.Context, cod
} else {
serviceFault := unknownExtensionObject.(readWriteModel.ServiceFault)
header := serviceFault.GetResponseHeader().(readWriteModel.ResponseHeader)
- s.log.Error().Msgf("Subscription ServiceFault returned from server with error code, '%s'", header.GetServiceResult())
+ s.log.Error().
+ Stringer("serviceResult", header.GetServiceResult()).
+ Msg("Subscription ServiceFault returned from server with error code")
}
}
}
@@ -738,9 +751,10 @@ func (s *SecureChannel) onDisconnect(ctx context.Context, codec *MessageCodec) {
if fault, ok := message.GetBody().(readWriteModel.ServiceFaultExactly); ok {
statusCode := fault.GetResponseHeader().(readWriteModel.ResponseHeader).GetServiceResult().GetStatusCode()
statusCodeByValue, _ := readWriteModel.OpcuaStatusCodeByValue(statusCode)
- s.log.Error().Msgf("Failed to connect to opc ua server for the following reason:- %v, %v",
- statusCode,
- statusCodeByValue)
+ s.log.Error().
+ Uint32("statusCode", statusCode).
+ Stringer("statusCodeByValue", statusCodeByValue).
+ Msg("Failed to connect to opc ua server for the following reason")
} else {
s.log.Debug().Msg("Got Close Session Response Connection Response")
@@ -755,7 +769,9 @@ func (s *SecureChannel) onDisconnect(ctx context.Context, codec *MessageCodec) {
} else {
serviceFault := unknownExtensionObject.(readWriteModel.ServiceFault)
header := serviceFault.GetResponseHeader().(readWriteModel.ResponseHeader)
- s.log.Error().Msgf("Subscription ServiceFault returned from server with error code, '%s'", header.GetServiceResult())
+ s.log.Error().
+ Stringer("serviceResult", header.GetServiceResult()).
+ Msg("Subscription ServiceFault returned from server with error code")
}
}
}
@@ -842,7 +858,7 @@ func (s *SecureChannel) onDisconnectCloseSecureChannel(ctx context.Context, code
s.log.Debug().Err(err).Msg("a error")
}
}
- s.log.Debug().Msgf("Submitting CloseSecureChannel with id of %d", transactionId)
+ s.log.Debug().Int32("transactionId", transactionId).Msg("Submitting CloseSecureChannel with id")
if err := s.channelTransactionManager.submit(requestConsumer, transactionId); err != nil {
s.log.Debug().Err(err).Msg("error submitting")
}
@@ -993,9 +1009,10 @@ func (s *SecureChannel) onDiscoverOpenSecureChannel(ctx context.Context, codec *
if fault, ok := extensionObject.GetBody().(readWriteModel.ServiceFaultExactly); ok {
statusCode := fault.GetResponseHeader().(readWriteModel.ResponseHeader).GetServiceResult().GetStatusCode()
statusCodeByValue, _ := readWriteModel.OpcuaStatusCodeByValue(statusCode)
- s.log.Error().Msgf("Failed to connect to opc ua server for the following reason:- %v, %v",
- statusCode,
- statusCodeByValue)
+ s.log.Error().
+ Uint32("statusCode", statusCode).
+ Stringer("statusCodeByValue", statusCodeByValue).
+ Msg("Failed to connect to opc ua server for the following reason")
} else {
s.log.Debug().Msg("Got Secure Response Connection Response")
openSecureChannelResponse := extensionObject.GetBody().(readWriteModel.OpenSecureChannelResponse)
@@ -1027,7 +1044,10 @@ func (s *SecureChannel) onDiscoverGetEndpointsRequest(ctx context.Context, codec
nextRequestId := opcuaOpenResponse.GetRequestId() + 1
if !(transactionId == nextSequenceNumber) {
- s.log.Error().Msgf("Sequence number isn't as expected, we might have missed a packet. - %d != %d", transactionId, nextSequenceNumber)
+ s.log.Error().
+ Int32("transactionId", transactionId).
+ Int32("nextSequenceNumber", nextSequenceNumber).
+ Msg("Sequence number isn't as expected, we might have missed a packet. - transactionId != nextSequenceNumber")
return
}
@@ -1115,9 +1135,10 @@ func (s *SecureChannel) onDiscoverGetEndpointsRequest(ctx context.Context, codec
if fault, ok := extensionObject.GetBody().(readWriteModel.ServiceFaultExactly); ok {
statusCode := fault.GetResponseHeader().(readWriteModel.ResponseHeader).GetServiceResult().GetStatusCode()
statusCodeByValue, _ := readWriteModel.OpcuaStatusCodeByValue(statusCode)
- s.log.Error().Msgf("Failed to connect to opc ua server for the following reason:- %v, %v",
- statusCode,
- statusCodeByValue)
+ s.log.Error().
+ Uint32("statusCode", statusCode).
+ Stringer("statusCodeByValue", statusCodeByValue).
+ Msg("Failed to connect to opc ua server for the following reason")
} else {
s.log.Debug().Msg("Got Secure Response Connection Response")
response := extensionObject.GetBody().(readWriteModel.GetEndpointsResponse)
@@ -1126,7 +1147,7 @@ func (s *SecureChannel) onDiscoverGetEndpointsRequest(ctx context.Context, codec
for _, endpoint := range endpoints {
endpointDescription := endpoint.(readWriteModel.EndpointDescription)
if endpointDescription.GetEndpointUrl().GetStringValue() == (s.endpoint.GetStringValue()) && endpointDescription.GetSecurityPolicyUri().GetStringValue() == (s.securityPolicy) {
- s.log.Info().Msgf("Found OPC UA endpoint %s", s.endpoint.GetStringValue())
+ s.log.Info().Str("stringValue", s.endpoint.GetStringValue()).Msg("Found OPC UA endpoint")
s.configuration.senderCertificate = endpointDescription.GetServerCertificate().GetStringValue()
}
}
@@ -1227,7 +1248,7 @@ func (s *SecureChannel) onDiscoverCloseSecureChannel(ctx context.Context, codec
s.log.Debug().Err(err).Msg("a error")
}
}
- s.log.Debug().Msgf("Submitting CloseSecureChannel with id of %d", transactionId)
+ s.log.Debug().Int32("transactionId", transactionId).Msg("Submitting CloseSecureChannel with id")
if err := s.channelTransactionManager.submit(requestConsumer, transactionId); err != nil {
s.log.Debug().Err(err).Msg("error submitting")
}
@@ -1364,9 +1385,10 @@ func (s *SecureChannel) keepAlive() {
if fault, ok := extensionObject.GetBody().(readWriteModel.ServiceFaultExactly); ok {
statusCode := fault.GetResponseHeader().(readWriteModel.ResponseHeader).GetServiceResult().GetStatusCode()
statusCodeByValue, _ := readWriteModel.OpcuaStatusCodeByValue(statusCode)
- s.log.Error().Msgf("Failed to connect to opc ua server for the following reason:- %v, %v",
- statusCode,
- statusCodeByValue)
+ s.log.Error().
+ Uint32("statusCode", statusCode).
+ Stringer("statusCodeByValue", statusCodeByValue).
+ Msg("Failed to connect to opc ua server for the following reason")
} else {
s.log.Debug().Msg("Got Secure Response Connection Response")
openSecureChannelResponse := extensionObject.GetBody().(readWriteModel.OpenSecureChannelResponse)
@@ -1386,7 +1408,7 @@ func (s *SecureChannel) keepAlive() {
s.log.Debug().Err(err).Msg("a error")
}
}
- s.log.Debug().Msgf("Submitting OpenSecureChannel with id of %d", transactionId)
+ s.log.Debug().Int32("transactionId", transactionId).Msg("Submitting OpenSecureChannel with id")
if err := s.channelTransactionManager.submit(requestConsumer, transactionId); err != nil {
s.log.Debug().Err(err).Msg("error submitting")
}
@@ -1439,12 +1461,12 @@ func (s *SecureChannel) selectEndpoint(sessionResponse readWriteModel.CreateSess
}
if s.policyId == nil {
- s.log.Error().Msgf("Unable to find endpoint - %s", s.endpoints[0])
+ s.log.Error().Str("endpoint", s.endpoints[0]).Msg("Unable to find endpoint")
return
}
if s.tokenType == 0xffffffff { // TODO: what did we use as undefined
- s.log.Error().Msgf("Unable to find Security Policy for endpoint - %s", s.endpoints[0])
+ s.log.Error().Str("endpoint", s.endpoints[0]).Msg("Unable to find Security Policy for endpoint")
return
}
}
@@ -1458,10 +1480,14 @@ func (s *SecureChannel) isEndpoint(endpoint readWriteModel.EndpointDescription)
// Split up the connection string into its individual segments.
matches := utils.GetSubgroupMatches(URI_PATTERN, endpoint.GetEndpointUrl().GetStringValue())
if len(matches) == 0 {
- s.log.Error().Msgf("Endpoint returned from the server doesn't match the format '{protocol-code}:({transport-code})?//{transport-host}(:{transport-port})(/{transport-endpoint})'")
+ s.log.Error().Msg("Endpoint returned from the server doesn't match the format '{protocol-code}:({transport-code})?//{transport-host}(:{transport-port})(/{transport-endpoint})'")
return false
}
- s.log.Trace().Msgf("Using Endpoint %s %s %s", matches["transportHost"], matches["transportPort"], matches["transportEndpoint"])
+ s.log.Trace().
+ Str("transportHost", matches["transportHost"]).
+ Str("transportPort", matches["transportPort"]).
+ Str("transportEndpoint", matches["transportEndpoint"]).
+ Msg("Using Endpoint")
if s.configuration.discovery && !slices.Contains(s.endpoints, matches["transportHost"]) {
return false
diff --git a/plc4go/internal/opcua/SecureChannelTransactionManager.go b/plc4go/internal/opcua/SecureChannelTransactionManager.go
index 2fe77a4938..13a38bdf6a 100644
--- a/plc4go/internal/opcua/SecureChannelTransactionManager.go
+++ b/plc4go/internal/opcua/SecureChannelTransactionManager.go
@@ -49,16 +49,16 @@ func NewSecureChannelTransactionManager(log zerolog.Logger) *SecureChannelTransa
func (m *SecureChannelTransactionManager) submit(onSend func(transactionId int32), transactionId int32) error {
m.lock.Lock()
defer m.lock.Unlock()
- m.log.Info().Msgf("Active transaction Number %d", m.activeTransactionId.Load())
+ m.log.Info().Int32("activeTransactionId", m.activeTransactionId.Load()).Msg("Active transaction Number")
if m.activeTransactionId.Load() == transactionId {
onSend(transactionId)
newTransactionId := m.getActiveTransactionIdentifier()
if len(m.queue) > 0 {
t, ok := m.queue[newTransactionId]
if !ok {
- m.log.Info().Msgf("Length of Queue is %d", len(m.queue))
- m.log.Info().Msgf("Transaction ID is %d", newTransactionId)
- m.log.Info().Msgf("Map is %v", m.queue)
+ m.log.Info().Int("queueLength", len(m.queue)).Msg("Length of Queue")
+ m.log.Info().Int32("newTransactionId", newTransactionId).Msg("Transaction ID")
+ m.log.Info().Interface("map", m.queue).Msg("Map is")
return errors.Errorf("Transaction Id not found in queued messages %v", m.queue)
}
delete(m.queue, newTransactionId)
@@ -67,7 +67,7 @@ func (m *SecureChannelTransactionManager) submit(onSend func(transactionId int32
}
}
} else {
- m.log.Info().Msgf("Storing out of order transaction %d", transactionId)
+ m.log.Info().Int32("transactionId", transactionId).Msg("Storing out of order transaction")
m.queue[transactionId] = SecureChannelTransactionManagerTransaction{consumer: onSend, transactionId: transactionId}
}
return nil
diff --git a/plc4go/internal/opcua/SubscriptionHandle.go b/plc4go/internal/opcua/SubscriptionHandle.go
index 483b69f7df..f4cb2bf394 100644
--- a/plc4go/internal/opcua/SubscriptionHandle.go
+++ b/plc4go/internal/opcua/SubscriptionHandle.go
@@ -193,9 +193,9 @@ func (h *SubscriptionHandle) onSubscribeCreateMonitoredItemsRequest() (readWrite
for index, arrayLength := 0, len(array); index < arrayLength; index++ {
result := array[index]
if code, ok := readWriteModel.OpcuaStatusCodeByValue(result.GetStatusCode().GetStatusCode()); !ok || code != readWriteModel.OpcuaStatusCode_Good {
- h.log.Error().Msgf("Invalid Tag %s, subscription created without this tag", h.tagNames[index])
+ h.log.Error().Str("tag", h.tagNames[index]).Msg("Invalid Tag, subscription created without this tag")
} else {
- h.log.Debug().Msgf("Tag %s was added to the subscription", h.tagNames[index])
+ h.log.Debug().Str("tag", h.tagNames[index]).Msg("Tag was added to the subscription")
}
}
responseChan <- responseMessage
@@ -313,7 +313,9 @@ func (h *SubscriptionHandle) startSubscriber() {
case readWriteModel.ServiceFault:
serviceFault = unknownExtensionObject
header := serviceFault.GetResponseHeader().(readWriteModel.ResponseHeader)
- h.log.Debug().Msgf("Subscription ServiceFault returned from server with error code, '%s', ignoring as it is probably just a result of a Delete Subscription Request", header.GetServiceResult())
+ h.log.Debug().
+ Stringer("serviceResult", header.GetServiceResult()).
+ Msg("Subscription ServiceFault returned from server with error code, ignoring as it is probably just a result of a Delete Subscription Request")
//h.plcSubscriber.onDisconnect(context);
return
}
@@ -427,7 +429,9 @@ func (h *SubscriptionHandle) stopSubscriber() {
case readWriteModel.ServiceFault:
serviceFault := unknownExtensionObject
header := serviceFault.GetResponseHeader().(readWriteModel.ResponseHeader)
- h.log.Debug().Msgf("Subscription ServiceFault returned from server with error code, '%s', ignoring as it is probably just a result of a Delete Subscription Request", header.GetServiceResult())
+ h.log.Debug().
+ Stringer("serviceResult", header.GetServiceResult()).
+ Msg("Subscription ServiceFault returned from server with error code, ignoring as it is probably just a result of a Delete Subscription Request")
return
}
h.log.Debug().Msgf("Received response\n%s", responseMessage)
diff --git a/plc4go/internal/opcua/common.go b/plc4go/internal/opcua/common.go
index afde71adc6..3e2bc26624 100644
--- a/plc4go/internal/opcua/common.go
+++ b/plc4go/internal/opcua/common.go
@@ -79,7 +79,7 @@ func readResponse(localLog zerolog.Logger, readRequestIn apiModel.PlcReadRequest
var value apiValues.PlcValue
if results[count].GetValueSpecified() {
variant := results[count].GetValue()
- localLog.Trace().Msgf("Response of type %T", variant)
+ localLog.Trace().Type("type", variant).Msg("Response of type")
switch variant := variant.(type) {
case readWriteModel.VariantBooleanExactly:
array := variant.GetValue()
@@ -240,7 +240,7 @@ func readResponse(localLog zerolog.Logger, readRequestIn apiModel.PlcReadRequest
value = spiValues.NewPlcList(statusCodeValues)
default:
responseCode = apiModel.PlcResponseCode_UNSUPPORTED
- localLog.Error().Msgf("Data type - %T is not supported ", variant)
+ localLog.Error().Type("variant", variant).Msg("Data type is not supported ")
}
} else {
if results[count].GetStatusCode().GetStatusCode() == uint32(readWriteModel.OpcuaStatusCode_BadNodeIdUnknown) {
@@ -248,7 +248,7 @@ func readResponse(localLog zerolog.Logger, readRequestIn apiModel.PlcReadRequest
} else {
responseCode = apiModel.PlcResponseCode_UNSUPPORTED
}
- localLog.Error().Msgf("Error while reading value from OPC UA server error code:- %s", results[count].GetStatusCode())
+ localLog.Error().Stringer("statusCode", results[count].GetStatusCode()).Msg("Error while reading value from OPC UA server error code")
}
count++
responseCodes[tagName] = responseCode