Skip to content

refactor: try to refactor the load config code to 2 clear pathes#814

Merged
jackchenjc merged 2 commits intoedgexfoundry:mainfrom
tuxiot:refactor/load-config
Feb 2, 2025
Merged

refactor: try to refactor the load config code to 2 clear pathes#814
jackchenjc merged 2 commits intoedgexfoundry:mainfrom
tuxiot:refactor/load-config

Conversation

@qs-wang
Copy link
Contributor

@qs-wang qs-wang commented Jan 11, 2025

  • split loadConfigByProvider to a separate method to make if/else statement clearer
  • split loadPrivateConfigFromFile to a separate method for reuse in if/else branches

I tried to make some changes for my own purpose. While I read the code although the code works perfectly, it a little bit hard to understand and change because the config loading logic from the provider and file are mixed. I refactored it to split the loading logic , i.e. loading from provider and file, to 2 methods, which made my changes easier. Later on I found other solution so the changes got dropped, but I am trying to push the refactor to see if anyone is interested.

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/go-mod-bootstrap/blob/main/.github/Contributing.md

PR Checklist

Please check if your PR fulfills the following requirements:

  • [y] I am not introducing a breaking change (if you are, flag in conventional commit message with BREAKING CHANGE: describing the break)
  • [y] I am not introducing a new dependency (add notes below if you are)
  • [n] I have added unit tests for the new feature or bug fix (if not, why?) refactoring the code, should not change any logic, passed all existing test
  • [y] I have fully tested (add details below) this the new feature or bug fix (if not, why?)
  • [n] I have opened a PR for the related docs change (if not, why?) refactoring code, no doc change is needed

Testing Instructions

New Dependency Instructions (If applicable)

@qs-wang qs-wang force-pushed the refactor/load-config branch 5 times, most recently from d3f9d8c to f6565fc Compare January 11, 2025 11:05
@cloudxxx8 cloudxxx8 requested a review from jackchenjc January 23, 2025 02:23
Copy link
Contributor

@jackchenjc jackchenjc left a comment

Choose a reason for hiding this comment

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

Hi @qs-wang,

Thanks for the refactoring. I've left a comment below about a minor detail I noticed.

@qs-wang qs-wang force-pushed the refactor/load-config branch from 6a77bba to 91d412a Compare January 27, 2025 07:45
…th clearly

- split loadConfigByProvider to a separate method to make if/else statemtn clearer
- split loadPrivateConfigFromFile to a separate method for reuse in if/else branches

Signed-off-by: Q.s <wangqs_eclipse@yahoo.com>
@qs-wang qs-wang force-pushed the refactor/load-config branch from 91d412a to 7123958 Compare January 27, 2025 08:56
@codecov-commenter
Copy link

codecov-commenter commented Jan 27, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 0% with 78 lines in your changes missing coverage. Please review.

Project coverage is 46.20%. Comparing base (53b414d) to head (f4834ce).

Files with missing lines Patch % Lines
bootstrap/config/config.go 0.00% 78 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #814      +/-   ##
==========================================
- Coverage   46.51%   46.20%   -0.31%     
==========================================
  Files          62       62              
  Lines        3603     3627      +24     
==========================================
  Hits         1676     1676              
- Misses       1805     1829      +24     
  Partials      122      122              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@qs-wang qs-wang force-pushed the refactor/load-config branch from 7123958 to 989def7 Compare January 27, 2025 09:20
Signed-off-by: Q.s <wangqs_eclipse@yahoo.com>
@qs-wang qs-wang force-pushed the refactor/load-config branch from 989def7 to f4834ce Compare January 27, 2025 09:20
@qs-wang qs-wang requested a review from jackchenjc January 27, 2025 22:21
@qs-wang qs-wang changed the title refactor: try to refactor the load config coode to 2 clear pathes refactor: try to refactor the load config code to 2 clear pathes Jan 28, 2025
Copy link
Contributor

@jackchenjc jackchenjc left a comment

Choose a reason for hiding this comment

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

LGTM

@jackchenjc jackchenjc merged commit 8cac255 into edgexfoundry:main Feb 2, 2025
1 check passed
@qs-wang qs-wang deleted the refactor/load-config branch February 3, 2025 03:05
judehung added a commit to judehung/go-mod-bootstrap that referenced this pull request Jun 13, 2025
fixes edgexfoundry#872

The send on close channel panic are occasionally observed when a service is terminated.
The root cause is that go-mod-bootstrap implements listensForChanges by creating sender
channel in the side of receiver, and close the sender channel in the side of receiver
will cause the panic.

The simplest solution with least code refactor is to not defer close(updateStream) and
defer close(errorStream) in listenForPrivateChanges, listenForCommonChanges, and
ListenForCustomChanges since there is no need to close the channels.

Moreover, edgexfoundry#814 accidentally adds
reduandant calls to listen for changes on Writable.
As the `cp.loadConfigByProvider` will listen for changes on Writable at https://github.com/edgexfoundry/go-mod-bootstrap/pull/814/files#diff-5346c73553fe1e8350deb1a29ed066b1202c1ea35e57d206adbb6f359ed1d299R332-R343, there is no need to do it again at https://github.com/edgexfoundry/go-mod-bootstrap/pull/814/files#diff-5346c73553fe1e8350deb1a29ed066b1202c1ea35e57d206adbb6f359ed1d299R181-R192.

This fix also removes this redundant calls.

Signed-off-by: Jude Hung <jude@iotechsys.com>
judehung added a commit to judehung/go-mod-bootstrap that referenced this pull request Jun 13, 2025
fixes edgexfoundry#872

The send on close channel panic are occasionally observed when a service is terminated.
The root cause is that go-mod-bootstrap implements listensForChanges by creating sender
channel in the side of receiver, and close the sender channel in the side of receiver
will cause the panic.

The simplest solution with least code refactor is to not defer close(updateStream) and
defer close(errorStream) in listenForPrivateChanges, listenForCommonChanges, and
ListenForCustomChanges since there is no need to close the channels.

Moreover, edgexfoundry#814 accidentally adds
reduandant calls to listen for changes on Writable.
As the `cp.loadConfigByProvider` will listen for changes on Writable at https://github.com/edgexfoundry/go-mod-bootstrap/pull/814/files#diff-5346c73553fe1e8350deb1a29ed066b1202c1ea35e57d206adbb6f359ed1d299R332-R343, there is no need to do it again at https://github.com/edgexfoundry/go-mod-bootstrap/pull/814/files#diff-5346c73553fe1e8350deb1a29ed066b1202c1ea35e57d206adbb6f359ed1d299R181-R192.

This fix also removes this redundant calls.

Signed-off-by: Jude Hung <jude@iotechsys.com>
FelixTing pushed a commit to FelixTing/go-mod-bootstrap that referenced this pull request Oct 14, 2025
fixes edgexfoundry#872

The send on close channel panic are occasionally observed when a service is terminated.
The root cause is that go-mod-bootstrap implements listensForChanges by creating sender
channel in the side of receiver, and close the sender channel in the side of receiver
will cause the panic.

The simplest solution with least code refactor is to not defer close(updateStream) and
defer close(errorStream) in listenForPrivateChanges, listenForCommonChanges, and
ListenForCustomChanges since there is no need to close the channels.

Moreover, edgexfoundry#814 accidentally adds
reduandant calls to listen for changes on Writable.
As the `cp.loadConfigByProvider` will listen for changes on Writable at https://github.com/edgexfoundry/go-mod-bootstrap/pull/814/files#diff-5346c73553fe1e8350deb1a29ed066b1202c1ea35e57d206adbb6f359ed1d299R332-R343, there is no need to do it again at https://github.com/edgexfoundry/go-mod-bootstrap/pull/814/files#diff-5346c73553fe1e8350deb1a29ed066b1202c1ea35e57d206adbb6f359ed1d299R181-R192.

This fix also removes this redundant calls.

Signed-off-by: Jude Hung <jude@iotechsys.com>
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.

3 participants