Skip to content

refactor remotecfg.go #4034

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

refactor remotecfg.go #4034

wants to merge 5 commits into from

Conversation

erikbaranowski
Copy link
Contributor

PR Description

Organize the remotecfg.go for maintainability. Increase unit test coverage which was missing prior due to too much in one file.

Which issue(s) this PR fixes

Notes to the Reviewer

PR Checklist

  • CHANGELOG.md updated
  • Documentation added
  • Tests updated
  • Config converters updated

@CLAassistant
Copy link

CLAassistant commented Jul 22, 2025

CLA assistant check
All committers have signed the CLA.

Signed-off-by: Erik Baranowski <[email protected]>
@erikbaranowski erikbaranowski changed the title move metrics and agentInterceptor out of remotecfg.go refactor remotecfg.go Jul 23, 2025
}()

for {
select {
case <-s.ticker.C:
err := s.fetchRemote()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm unclear why we only fetchRemote here. The new code handles fetching remote with the fallback to local included.

Copy link
Contributor

Choose a reason for hiding this comment

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

Because cached local config is checked on service startup, there's no need to check for cached config every time you query the API because if it's changed from what it was on startup it only changed due to a successful fetchRemote?

Comment on lines +38 to +45
// newAPIClientWithClient creates a metrics-wrapped apiClient from an existing CollectorServiceClient.
// This is primarily used for testing with mock clients.
func newAPIClientWithClient(client collectorv1connect.CollectorServiceClient, metrics *metrics) *apiClient {
return &apiClient{
client: client,
metrics: metrics,
}
}
Copy link
Member

Choose a reason for hiding this comment

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

small nit: can't we simply define a package-level mock client that tests will share? Is there an issue with reuse? Or a newMockClient()?

var mockClient = &apiClient{
  client: &mockCollectorClient{},
  metrics: registerMetrics(prometheus.NewRegistry())
}

// This file contains functionality that is used by custom code external to the
// remotecfg package. These functions provide public APIs for accessing remotecfg
// service data and are intended for use by other packages and components.
package remotecfg
Copy link
Member

Choose a reason for hiding this comment

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

nit: I'm on the fence, but should we pull Data() here as well?

Also, let's make it consistent remotecfg on the logs as well.

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.

4 participants