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: action config update would sometimes not be reflected in connector #13077

Conversation

kjellwinblad
Copy link
Contributor

@kjellwinblad kjellwinblad commented May 20, 2024

Before this commit the following happened sometimes:

  1. action status is connected
  2. action config is updated to something that should change the status to disconnected
  3. action status is still connected and the old config is being used by the connector even though the config has been correctly updated.

The reason for this bug is that the post_config_hook runs before the global EMQX config is updated. The post config hook is adding the new config to the connector. Since the new config causes the action to get status disconnected, the adding of the action to the connector is retried when the health check runs but this time the config will be loaded from the global config which could cause the old config to be loaded (this happens when the global config has not had time to get updated).

The above problem has been fixed in this commit by only reading action configs from the global config when the connector starts/restarts and instead store the latest configs for the actions in the connector.

Fixes:
https://emqx.atlassian.net/browse/EMQX-12376

Release version: v/e5.7

Summary

PR Checklist

Please convert it to a draft if any of the following conditions are not met. Reviewers may skip over until all the items are checked:

  • Added tests for the changes
  • [] Added property-based tests for code which performs user input validation
  • [] Changed lines covered in coverage report
  • Change log has been added to changes/(ce|ee)/(feat|perf|fix|breaking)-<PR-id>.en.md files
  • For internal contributor: there is a jira ticket to track this change
  • [] Created PR to emqx-docs if documentation update is required, or link to a follow-up jira ticket
  • [] Schema changes are backward compatible

@kjellwinblad kjellwinblad requested a review from a team as a code owner May 20, 2024 14:15
thalesmg
thalesmg previously approved these changes May 20, 2024
#{
status => ?status_disconnected,
error => Reason
error => Reason,
config => ChannelConfig
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we return this channel status in the APIs. If so, we might want to redact this config in the API handlers, as it might contain sensitive data. It might be already handled there, but worth confirming it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I will check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Configs are now removed from get_channel_status calls and the lookup calls: 0f10b0b

Before this commit the following happened sometimes:

1. action status is connected
2. action config is updated to something that should change the status to
   disconnected
3. action status is still connected and the old config is being used by
   the connector even though the config has been correctly updated.

The reason for this bug is that the post_config_hook runs before the
global EMQX config is updated. The post config hook is adding the new
config to the connector. Since the new config causes the action to get
status disconnected, the adding of the action to the connector is
retried when the health check runs but this time the config will be
loaded from the global config which could cause the old config to be
loaded (this happens when the global config has not had time to get
updated).

The above problem has been fixed in this commit by only reading action
configs from the global config when the connector starts/restarts and
instead store the latest configs for the actions in the connector.

Fixes:
https://emqx.atlassian.net/browse/EMQX-12376
This commit fixes an issue found by CI test case
emqx_bridge_influxdb_SUITE:t_start_stop and others. While the channel
health check process is running, the channel could be removed or updated
which could cause a crash in the resource manager or non up-to-date
alarms being triggered.
thalesmg
thalesmg previously approved these changes May 22, 2024
Comment on lines 1493 to 1500
AddedChannelsList = maps:to_list(Data#data.added_channels),
AddedChannelsListWithoutConfigs =
[
{ChanID, maps:remove(config, Status)}
|| {ChanID, Status} <- AddedChannelsList
],
AddedChannelsWithoutConfigs =
maps:from_list(AddedChannelsListWithoutConfigs),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
AddedChannelsList = maps:to_list(Data#data.added_channels),
AddedChannelsListWithoutConfigs =
[
{ChanID, maps:remove(config, Status)}
|| {ChanID, Status} <- AddedChannelsList
],
AddedChannelsWithoutConfigs =
maps:from_list(AddedChannelsListWithoutConfigs),
AddedChannelsWithoutConfigs =
maps:map(
fun(_ChanID, Status) -> maps:remove(config, Status) end,
Data#data.added_channels
),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed 88c96e2

Also added another fix to not leak configs in alarm.

@kjellwinblad kjellwinblad merged commit 26c988f into emqx:release-57 May 23, 2024
168 checks passed
@emqxqa
Copy link

emqxqa commented May 23, 2024

TestExecution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants