-
Notifications
You must be signed in to change notification settings - Fork 55
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
feat: New Metrics metadata #175
Conversation
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 code looks cool but what happened to specVersion
?
config.go
Outdated
return func(o *configOption) { | ||
o.started = &startedAt | ||
} | ||
} |
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.
Should started
be configurable?
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.
Mostly for tests 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.
I would've used #[cfg(test)] here, don't know what the same is in go.
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.
Good point, I've moved it into the test file where I used it 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.
I still don't like that we're polluting our config options with something that shouldn't be user-configurable and I'm still not super convinced of its value. Maybe we can relax our tests 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.
Something like this seems to work, but maybe there's a better way:
func clientDataMatcher() func(req *http.Request, ereq *gock.Request) (bool, error) {
defaultStrategies := []string{
"default",
"applicationHostname",
"gradualRolloutRandom",
"gradualRolloutSessionId",
"gradualRolloutUserId",
"remoteAddress",
"userWithId",
"flexibleRollout",
}
return func(req *http.Request, ereq *gock.Request) (bool, error) {
var data ClientData
err := json.NewDecoder(req.Body).Decode(&data)
if err != nil {
return false, err
}
if data.Started.IsZero() {
return false, nil
}
expectedData := ClientData{
AppName: mockAppName,
InstanceID: mockInstanceId,
SDKVersion: fmt.Sprintf("%s:%s", clientName, clientVersion),
Strategies: defaultStrategies,
Interval: 0,
PlatformVersion: runtime.Version(),
PlatformName: "go",
YggdrasilVersion: nil,
SpecVersion: specVersion,
}
return data.AppName == expectedData.AppName &&
data.InstanceID == expectedData.InstanceID &&
data.SDKVersion == expectedData.SDKVersion &&
compareStringSlices(data.Strategies, expectedData.Strategies) &&
data.Interval == expectedData.Interval &&
data.PlatformVersion == expectedData.PlatformVersion &&
data.PlatformName == expectedData.PlatformName &&
data.YggdrasilVersion == expectedData.YggdrasilVersion &&
data.SpecVersion == expectedData.SpecVersion, nil
}
}
func compareStringSlices(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
func TestMetrics_ClientDataIncludesNewMetadata(t *testing.T) {
assert := assert.New(t)
defer gock.OffAll()
gock.New(mockerServer).
Post("/client/register").
AddMatcher(clientDataMatcher()).
Reply(200)
client, err := NewClient(
WithUrl(mockerServer),
WithMetricsInterval(50*time.Millisecond),
WithAppName(mockAppName),
WithInstanceId(mockInstanceId),
)
assert.Nil(err, "Client should open without a problem")
time.Sleep(100 * time.Millisecond)
err = client.Close()
assert.Nil(err, "Client should close without errors")
st.Expect(t, gock.IsDone(), true)
}
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.
Thanks. I added your suggestion
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.
And removed started from the options
Don't you come here with your facts 🥇 . Added specVersion... |
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.
Noice! LGTM
metrics.go
Outdated
started := time.Now() | ||
if options.started != nil { | ||
started = *options.started | ||
} |
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 believe this can be reverted now, and we can set started: time.Now()
like before.
} | ||
} | ||
return true | ||
} |
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.
These are helper functions, not tests. Maybe we should move them to the top of the file or somewhere else that's not 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.
Why not here, they're used immediately after?
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.
Simply readability / convention / preference. I don't have strong feelings either way, and I understand the logic of keeping them near to where they're used, so I'm happy with keeping this.
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 - Thank you for considering my comments 😄
is included in client registration and client metrics