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

Cache collision fix #106

Merged
merged 20 commits into from
Jun 8, 2018
Merged

Cache collision fix #106

merged 20 commits into from
Jun 8, 2018

Conversation

varas
Copy link
Contributor

@varas varas commented Jun 6, 2018

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-d41479d78f43948797a5970be862f5e0R196

PR Review Checklist

Author

  • add a risk label after carefully considering the "blast radius" of your changes
  • describe the intent of your changes in the description. don't just rewrite your code in prose
  • assign at least one reviewer

Reviewer

  • review code for readability
  • verify that high risk behavior changes are well tested
  • check license for any new external dependency
  • ask questions about anything that isn't clear and obvious
  • approve the PR when you consider it's good to merge

@varas varas force-pushed the cache-collision branch 3 times, most recently from 88849fe to fc3cada Compare June 6, 2018 12:16
@varas varas changed the title [WIP] Cache collision fix Cache collision fix Jun 6, 2018
@varas varas added bug Categorizes issue or PR as related to a bug. risk:medium labels Jun 6, 2018
@varas varas requested review from mariomac, areina, smoya, MagdaPaj and xino12 and removed request for mariomac June 6, 2018 12:18
type Attributes []Attribute

// Len ...
func (a Attributes) Len() int { return len(a) }
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

mariomac
mariomac previously approved these changes Jun 7, 2018
@varas varas mentioned this pull request Jun 7, 2018
3 tasks
// NSSeparator is the metric namespace separator
NSSeparator = "::"
// NSAttributeSeparator is the metric attribute key-value separator applied to generate the metric ns.
NSAttributeSeparator = "=="
Copy link
Contributor

@smoya smoya Jun 8, 2018

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

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

// Errors
var (
ErrNonNumeric = errors.New("non-numeric value for rate/delta")
ErrNoStoreToCalcDiff = errors.New("can't use deltas nor rates without persistent store")
Copy link
Contributor

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.

Copy link
Contributor Author

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 ErrNoStoreToCalcDiffto ErrCannotCalcDiffWithoutStore?

Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Finally stopping the execution

@@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

xino12
xino12 previously approved these changes Jun 8, 2018
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
Copy link
Contributor Author

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 =)

smoya
smoya previously approved these changes Jun 8, 2018
Copy link
Contributor

@smoya smoya left a 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 !

Copy link
Contributor

@smoya smoya left a comment

Choose a reason for hiding this comment

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

💯

@smoya
Copy link
Contributor

smoya commented Jun 8, 2018

This PR fixes #48

@varas varas merged commit 1ce1d53 into master Jun 8, 2018
@varas varas deleted the cache-collision branch June 8, 2018 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants