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

Feature/benchmarking #56

Merged
merged 11 commits into from
Aug 22, 2019
Merged

Feature/benchmarking #56

merged 11 commits into from
Aug 22, 2019

Conversation

anbsky
Copy link
Collaborator

@anbsky anbsky commented Aug 15, 2019

  1. Mask account_id in SDK query logs

  2. Improve metrics collector. Documentation for metrics collector is provided in the package source files, hope it is clear enough!

Copy link
Contributor

@tiger5226 tiger5226 left a comment

Choose a reason for hiding this comment

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

I don't see anything blocking. Very clean and organized as usual. I added a few comments. A bigger question though, is that it appears that you are monitoring the queries, and that you have built everything needed to make this happen. Why not use something that already exists? We use new relic in internal-apis. It seems more straight forward than reimplementing this sort of thing. Either way it appears that its already built but maybe something to consider in the future to use other libraries.

Another note, your channels in the collector are all blocking. I just wanted to make sure that was your intention.

paramsMap[k] = v
}
return paramsMap
} else if paramsMap, ok := q.Params().(map[string]interface{}); ok {
Copy link
Contributor

@tiger5226 tiger5226 Aug 21, 2019

Choose a reason for hiding this comment

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

won't this always be true? if you are returning a map[string]interface{} always why would we ever try to do map[string]string? Obviously, you did it for a reason. More of a curiosity for my own knowledge.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it wouldn't be true in two cases:

  1. params is nil
  2. if map[string]string{}{"account_id": id} was attached to params later. which I was doing. but I've changed that and now the first clause is no longer needed. thanks for prompting me to think more about this piece of code, I think it's improved now.


if r.Error == nil {
c.service.logger.LogSuccessfulQuery(q.Method(), execTime, q.Params())
c.service.logger.LogSuccessfulQuery(q.Method(), execTime, q.paramsForLog())
Copy link
Contributor

Choose a reason for hiding this comment

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

A better convention for go is to check if r.Error != nil and remove the else altogether.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there is a non-returning pathway for when there is an error as well, so if/else is required. but yeah, replaced this with more familiar != nil

hook := logrus_test.NewLocal(svc.logger.Logger())
c.Call(request)

assert.Equal(t, map[string]interface{}{"account_id": "****"}, hook.LastEntry().Data["params"])
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the meaning of ***? Is that a default account of sorts? I would probably put this into a constant so the code reads better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's just a masked value so we see the field is there but the value is not revealed. It is defined as a constant in the code, just double-checking its value here in the test.

"response": errorResponse,
"params": params,
Copy link
Contributor

Choose a reason for hiding this comment

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

why the move? alphabetical order is better.

@anbsky
Copy link
Collaborator Author

anbsky commented Aug 22, 2019

Why not use something that already exists?

I'm actually using prometheus and its libraries. This code is to decouple main logic from those libraries so they can be replaced with something entirely else in the future, like new relic or metabase.

@anbsky anbsky merged commit 4f2638b into master Aug 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants