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

Refactor metrics/cloudwatch #1202

Merged
merged 2 commits into from
Nov 23, 2021
Merged

Refactor metrics/cloudwatch #1202

merged 2 commits into from
Nov 23, 2021

Conversation

sina-devel
Copy link
Contributor

@sina-devel sina-devel commented Nov 21, 2021

  • Export option type for better documentation
  • Add documentation for exported option functions
  • Use CloudWatch.apply method and remove unused Percentiles type
  • Remove unused CloudWatch.apply method and Percentiles type

- Export `option` type for better documentation
- Add documentation for exported option functions
- Use `CloudWatch.apply` method and remove unused `Percentiles` type
Comment on lines 107 to 109
for _, opt := range options {
cw.apply(opt)
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we just remove the apply method altogether?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's actually more safer than a simple function. apply cannot be called outside of the package, but with the current Option type it's possible to modify the state of Cloudwatch after the initialization.

I'd instead change the signature of Option to this:

type Option interface{
    apply(*CloudWatch)
}

Copy link
Member

@peterbourgon peterbourgon Nov 21, 2021

Choose a reason for hiding this comment

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

I'd instead change the signature of Option to this:

Strong -1. Option interfaces are an antipattern, and especially those that take this form, i.e. an exported interface with an unexported method. type Option func(*Cloudwatch) keeps the Options grouped with the type in the docs, which is important.

with the current Option type it's possible to modify the state of Cloudwatch after the initialization.

I understand your point, but I don't think this is a meaningful risk, as only Options defined in package cloudwatch have access to the unexported fields of the struct.

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 think we can remove the apply method, because cloudwatch.New(namespace, svc, nil) isn't norm.

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

@peterbourgon peterbourgon merged commit a073a09 into go-kit:master Nov 23, 2021
@sina-devel sina-devel deleted the refactor/metrics-cloudwatch branch November 23, 2021 18:36
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