-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Refactor metrics/cloudwatch #1202
Conversation
- Export `option` type for better documentation - Add documentation for exported option functions - Use `CloudWatch.apply` method and remove unused `Percentiles` type
metrics/cloudwatch/cloudwatch.go
Outdated
for _, opt := range options { | ||
cw.apply(opt) | ||
} |
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.
Can we just remove the apply method altogether?
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.
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)
}
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.
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.
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.
I think we can remove the apply
method, because cloudwatch.New(namespace, svc, nil)
isn't norm.
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.
fixed
option
type for better documentationUseCloudWatch.apply
method and remove unusedPercentiles
typeCloudWatch.apply
method andPercentiles
type