-
Notifications
You must be signed in to change notification settings - Fork 906
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(analysis): Adds timeout property to NewRelic metrics provider. Resolves: #3741 #3742
Merged
zachaller
merged 18 commits into
argoproj:master
from
orlando-valdez-ck:feat/newrelic-timeout
Aug 14, 2024
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7c87f65
Add timeout property
orlando-valdez-ck 94267ba
Add option to specify nrql timeout
orlando-valdez-ck 94db104
Update newrelic docs
orlando-valdez-ck 46058d2
Indent gql query
orlando-valdez-ck 1a28ef1
Slim down GQL query
orlando-valdez-ck c6a7c34
Merge branch 'master' into feat/newrelic-timeout
orlando-valdez-ck 3bd716a
Add missing codegen output after the merge
orlando-valdez-ck 9edefc5
Merge branch 'master' into feat/newrelic-timeout
orlando-valdez-ck 4e1de80
Merge branch 'master' into feat/newrelic-timeout
orlando-valdez-ck 6643cea
Merge branch 'master' into feat/newrelic-timeout
orlando-valdez-ck 4881cd4
Merge branch 'master' into feat/newrelic-timeout
orlando-valdez-ck 33cbf3f
Add tests
orlando-valdez-ck b50ee70
Add mock client comments
orlando-valdez-ck 932c1af
Merge branch 'master' into feat/newrelic-timeout
orlando-valdez-ck 5b5f792
Fix response struct
orlando-valdez-ck 82bd2b6
Merge branch 'master' into feat/newrelic-timeout
orlando-valdez-ck d8706b9
Merge branch 'master' into feat/newrelic-timeout
orlando-valdez-ck e781f32
Codegen after merge
orlando-valdez-ck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,64 @@ | ||
package newrelic | ||
|
||
import "github.com/newrelic/newrelic-client-go/pkg/nrdb" | ||
import ( | ||
"reflect" | ||
|
||
"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1" | ||
"github.com/newrelic/newrelic-client-go/v2/pkg/nrdb" | ||
) | ||
|
||
type mockAPI struct { | ||
response []nrdb.NRDBResult | ||
err error | ||
} | ||
|
||
func (m *mockAPI) Query(query string) ([]nrdb.NRDBResult, error) { | ||
func (m *mockAPI) Query(metric v1alpha1.Metric) ([]nrdb.NRDBResult, error) { | ||
if m.err != nil { | ||
return nil, m.err | ||
} | ||
return m.response, nil | ||
} | ||
|
||
type mockNerdGraphClient struct { | ||
response []nrdb.NRDBResult | ||
lastArgs map[string]interface{} | ||
err error | ||
} | ||
|
||
func (m *mockNerdGraphClient) QueryWithResponse(query string, variables map[string]interface{}, respBody interface{}) error { | ||
m.lastArgs = variables | ||
|
||
if m.err != nil { | ||
return m.err | ||
} | ||
|
||
r := gqlNrglQueryResponse{} | ||
r.Actor.Account.NRQL.Results = m.response | ||
|
||
rVal := reflect.ValueOf(r) | ||
reflect.ValueOf(respBody).Elem().Set(rVal) | ||
|
||
return nil | ||
} | ||
|
||
// Response sets the response the mock client will return | ||
func (m *mockNerdGraphClient) Response(response []nrdb.NRDBResult) { | ||
m.response = response | ||
} | ||
|
||
// LastArgs returns the variables used when calling the NerdGraph API | ||
func (m *mockNerdGraphClient) LastArgs() map[string]any { | ||
return m.lastArgs | ||
} | ||
|
||
// Err sets the error to be returned when calling the NerdGraph API | ||
func (m *mockNerdGraphClient) Err(err error) { | ||
m.err = err | ||
} | ||
|
||
// Clear removes all configured mock behavior | ||
func (m *mockNerdGraphClient) Clear() { | ||
m.err = nil | ||
m.response = nil | ||
m.lastArgs = nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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's an equivalent function that supports passing timeout in the
nrdb
package but it pulls way more data than the current function which by itself can impact latency.That's why I switched to the NerdGraph package to send the timeout in the query without incurring in additional data over the wire. I actually slimmed down the query compared to the used in the
Query
function to just what we need for this metric provider so the GQL API has to do less work to respond (and even less data transmitted back)