-
Notifications
You must be signed in to change notification settings - Fork 83
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: improper use of secretAddedSignal channel #1054
Conversation
On a second thought, for code readability, conciseness, and maintainability, it might be worth eliminating the use of channel and simplifying the retry mechanism in the MqttFactory.Create function (e.g. periodic retry) |
@FelixTing , yes I agree. This is simpler and less impact on other areas. Needs to have a duration that if exceeded it fails out. |
I also prefer to switch to retry mechanism instead of using a channel. In the channel approach of #1047, the only receiver of the channel is MqttFactory itself, and the channel should be closed or ditched right after MqttFactory passes the secrets validation. However, per golang's suggestion, only the sender should close a channel, never the receiver, so it's against channel closing principle to close the channel by MqttFactory. Moreover, given that #1047 is to ensure that external MQTT trigger can retrieve secrets during initialization, the impact of code changes should apply to the case of using external MQTT trigger only. Putting a channel in the PostSecrets controller have broader impact and may lead to unintentional behaviors that we fail to consider right now. As a result, implementing a retry mechanism inside the external MQTT trigger may be a better approach to fix #1046. |
ok, it's too complicated in this simple case. let's use the retry mechanism instead. |
c232fbe
to
0d3f1dc
Compare
This reverts commit 6bcd8b5. Signed-off-by: Felix Ting <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #1054 +/- ##
==========================================
+ Coverage 68.22% 68.25% +0.03%
==========================================
Files 35 35
Lines 2867 2848 -19
==========================================
- Hits 1956 1944 -12
+ Misses 800 793 -7
Partials 111 111
Continue to review full report at Codecov.
|
79d8fa5
to
70ff995
Compare
- Start webserver before trigger initialization - Add retry mechanism for External MQTT Trigger initialization Signed-off-by: Felix Ting <[email protected]>
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.
LGTM
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.
A couple minor things
internal/trigger/mqtt/mqtt.go
Outdated
timer := startup.NewTimer(brokerConfig.RetryDuration, brokerConfig.RetryInterval) | ||
for timer.HasNotElapsed() { | ||
if mqttClient, err = createMqttClient(sp, lc, brokerConfig, opts); err != nil { | ||
lc.Errorf("%s. Attempt to create MQTT client again after %d seconds...", err.Error(), brokerConfig.RetryInterval) |
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.
lc.Errorf("%s. Attempt to create MQTT client again after %d seconds...", err.Error(), brokerConfig.RetryInterval) | |
lc.Warnf("%s. Attempt to create MQTT client again after %d seconds...", err.Error(), brokerConfig.RetryInterval) |
internal/trigger/mqtt/mqtt.go
Outdated
return nil, fmt.Errorf("unable to create secure MQTT Client: %s", err.Error()) | ||
} | ||
|
||
brokerUrl, err := url.Parse(config.Url) |
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.
Remove. This is already verified in Initialize()
Signed-off-by: Felix Ting <[email protected]>
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.
LGTM
Revert #1047
Implement the retry mechanism inside the External MQTT Trigger.
fix: #1052 #1053
Signed-off-by: Felix Ting [email protected]
If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/app-functions-sdk-go/blob/main/.github/CONTRIBUTING.md
PR Checklist
Please check if your PR fulfills the following requirements:
BREAKING CHANGE:
describing the break)fix: Update External MQTT Trigger Docs edgex-docs#710
Testing Instructions
Download this Docker Compose file
Edit the Docker Compose file to add the custom App Service's service key to EdgeX service secretstore-setup's
ADD_SECRETSTORE_TOKENS
environment variable.Run EdgeX Foundry
docker-compose -f docker-compose.yml up -d
Download this App Service configuration
Modify
[Trigger]
section with the following settings:Run App Service with the configuration and
EDGEX_SECURITY_SECRET_STORE=true
Verify logs contain following messages
Wait 30 seconds and verify logs contain following messages
Restart App Service.
Generate a TLS client certificate for test.mosquitto.org, refer to https://test.mosquitto.org/ssl/
Add
clientcert
to Secret Store using this App Service APIVerify logs contain following messages
Add
clientcert
andclientkey
to Secret StoreVerify logs contain following messages
New Dependency Instructions (If applicable)