-
Notifications
You must be signed in to change notification settings - Fork 23
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
Cache collision fix #106
Cache collision fix #106
Conversation
88849fe
to
fc3cada
Compare
type Attributes []Attribute | ||
|
||
// Len ... | ||
func (a Attributes) Len() int { return len(a) } |
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.
What are Len
, Swap
and Less
used for?
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 on the comment above: https://github.com/newrelic/infra-integrations-sdk/pull/106/files#diff-83416e4d39b0688a4bec5f4a2c076486R196
Required for Go < v.18, as these do not include sort.Slice
you can see that change isolated in the commit 7da0608
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.
Hmm ok. I forgot the implicit implementation of interfaces in Go.
This reverts commit 3c254fe.
data/metric/metrics.go
Outdated
// NSSeparator is the metric namespace separator | ||
NSSeparator = "::" | ||
// NSAttributeSeparator is the metric attribute key-value separator applied to generate the metric ns. | ||
NSAttributeSeparator = "==" |
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.
Minor: Shall we use |
just to keep consistency with our entity GUID spec?
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.
This is just a disk-storage implementation detail. Nothing related to be managed by user, neither to be pushed to agent. So entity naming here would be indeed misleading.
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.
👍
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.
What I'd do is privatize these consts
data/metric/metrics.go
Outdated
// Errors | ||
var ( | ||
ErrNonNumeric = errors.New("non-numeric value for rate/delta") | ||
ErrNoStoreToCalcDiff = errors.New("can't use deltas nor rates without persistent store") |
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.
Avoid using contractions on error messages. You can use cannot
instead.
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.
what's the gain on switching ErrNoStoreToCalcDiff
to ErrCannotCalcDiffWithoutStore
?
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'm talking about the error message.
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.
ops, sure 👍
@@ -14,6 +15,12 @@ import ( | |||
// each one. | |||
type SourceType int | |||
|
|||
// Attribute represents an attribute metric in key-value pair format. | |||
type Attribute 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.
Why not declaring Attribute as map[string]string
? Or why not using directly a map as users will not need to use that custom type?
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.
Oh I see. You want to keep the previous interface with no attributes specified.
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.
If we don't enforce users to set those values, they will have eventually the same issue we are trying to fix here.
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.
The point on types (besides safety) is expressing intention. So you understand what that data is and what is aimed to do.
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.
The point on enforcing that was discussed with @areina.
We agreed that there is no need for that as most of the users won't need the feature, so enforcing them to solve a problem they don't have is adding undesired complexity.
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.
IMHO we should enforce it since the user is not aware of the real problem when using RATE and DELTA: they may be facing the issue without even being aware of it.
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.
The big issue here, and what I consider we must fix asap is How to friendly let the user know that the metric sets should be unique.
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.
Added error as a warning (does not breaks the logic) when SetMetric on rate/gauge in a metric-set without attributes
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.
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.
Finally stopping the execution
data/metric/metrics.go
Outdated
@@ -82,44 +116,98 @@ func (ms *Set) SetMetric(name string, value interface{}, sourceType SourceType) | |||
return nil | |||
} | |||
|
|||
func castToNumeric(value interface{}) (float64, error) { | |||
func castToFloat(value interface{}) (float64, error) { |
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.
👍
storer: storer, | ||
// NewSet creates new metrics set, optionally related to a list of attributes. These attributes makes the metric-set unique. | ||
// If related attributes are used, then new attributes are added. | ||
// TODO remove obsolete returned error |
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.
This is a BC from previous beta, but really nice to have as it removes a BC from SDKv2 =)
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.
LGTM 👍 Good job @varas !
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.
💯
This PR fixes #48 |
Description of the changes
Fixes cache collision on the store for rate&deltas when a same metric name is used.
Attributes are supported to namespace the metric name on the NewSet constructor.
Fix test at
TestNewSet_Attr_SolvesCacheCollision
https://github.com/newrelic/infra-integrations-sdk/pull/106/files#diff-d41479d78f43948797a5970be862f5e0R196PR Review Checklist
Author
Reviewer