-
Notifications
You must be signed in to change notification settings - Fork 294
SDI-2115: remove metric.String() in plugin-lib-go #1301
Conversation
@candysmurf, why metric.String() has been removed from plugin-lib-go? Should it has both methods String() and Strings() as snap's core.Namespace? Could you explain the motivation of removing this? I prefer to avoid creating private "toString" function in each package if it's possible - regarding https://github.com/intelsdi-x/snap-plugin-lib-go/pull/38. |
@IzabellaRaulin, thanks for your concern. Please refer to this issue intelsdi-x/snap-plugin-lib-go#34 opened in plugin-lib-go. That's the decision made in our backlog grooming. |
@IzabellaRaulin: I think the goal is to remove the implied guarantee that lives behind offering a String() method. With the work that has gone into arbitrary separators now the implementation behind a String() method would be decently complex and subject to future change. We don't want to provide a guarantee that it will work in a specific way. |
@candysmurf, as for the plugin lib PR, I suggest you replace string "ShouldEqual" by slice "ShouldResemble":
Doing this avoid creating a "toString" function as @IzabellaRaulin mentioned it. |
@IRCody & @kindermoumoute, if not comparing strings but array of strings, it requires comparison of each array element or using reflect.DeepEqual(). An additional function "stringsEqual" will need to be added. Please confirm you prefer "stringEqual" over "toString". Should we run a benchmark? :-) |
@IRCody, I can see the good use of doing array comparison if we like to recommend this way to all plugins and if it has no performance penalty, I would be glad to change it. |
@IRCody, thanks for doing the benchmark! We agreed to not use toString() method for two reasons:
|
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
@@ -96,7 +96,7 @@ func TestCollectMetric(t *testing.T) { | |||
|
|||
// only one metric for this specific hostname should be returned | |||
So(len(mts), ShouldEqual, 1) | |||
So(mts[0].Namespace.String(), ShouldEqual, "/intel/mock/host0/baz") | |||
So(mts[0].Namespace.Strings(), ShouldResemble, plugin.NewNamespace("intel", "mock", "host0", "baz").Strings()) |
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 to write a slice of string directly?
plugin.NewNamespace("intel", "mock", "host0", "baz").Strings()
==> []string{"intel", "mock", "host0", "baz"}
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.
not sure why it was like that. Probably make sure the correct library is used. Not core.NewNamespace
LGTM |
Summary of changes:
Testing done:
@intelsdi-x/snap-maintainers