-
Notifications
You must be signed in to change notification settings - Fork 176
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
[Metrics] Fix issue with collecting REST Metrics #4452
Merged
bors
merged 13 commits into
onflow:master
from
Guitarheroua:guitarheroua/fix-3971-fix-rest-api-metrics
Jun 29, 2023
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
01d21df
Fixed isse with rest metrics reports each request path as unique coll…
Guitarheroua fd160d4
Renamed arguments with proper naming.
Guitarheroua b76dc85
Merge branch 'master' into guitarheroua/fix-3971-fix-rest-api-metrics
Guitarheroua f2e8a3d
Merge branch 'master' into guitarheroua/fix-3971-fix-rest-api-metrics
Guitarheroua 87da372
Merge branch 'master' into guitarheroua/fix-3971-fix-rest-api-metrics
Guitarheroua 4646bcb
[Access] Add parsing logic for REST urls for metrics
peterargue f9181f6
Merge branch 'petera/add-rest-url-parser' of github.com:onflow/flow-g…
Guitarheroua 1b48569
changed rest metrics handler logic.
Guitarheroua 1ec7a2e
Merge branch 'master' of github.com:Guitarheroua/flow-go into guitarh…
Guitarheroua 4b3383a
linted
Guitarheroua 69a84a7
Merge branch 'master' into guitarheroua/fix-3971-fix-rest-api-metrics
Guitarheroua a3b4bd5
Fixed cyclic dependency and regexp lint.
Guitarheroua 2f94bd6
Change error handling in rest metrics.
Guitarheroua 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
package rest | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParseURL(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
url string | ||
expected string | ||
}{ | ||
{ | ||
name: "/v1/transactions", | ||
url: "/v1/transactions", | ||
expected: "createTransaction", | ||
}, | ||
{ | ||
name: "/v1/transactions/{id}", | ||
url: "/v1/transactions/53730d3f3d2d2f46cb910b16db817d3a62adaaa72fdb3a92ee373c37c5b55a76", | ||
expected: "getTransactionByID", | ||
}, | ||
{ | ||
name: "/v1/transaction_results/{id}", | ||
url: "/v1/transaction_results/53730d3f3d2d2f46cb910b16db817d3a62adaaa72fdb3a92ee373c37c5b55a76", | ||
expected: "getTransactionResultByID", | ||
}, | ||
{ | ||
name: "/v1/blocks", | ||
url: "/v1/blocks", | ||
expected: "getBlocksByHeight", | ||
}, | ||
{ | ||
name: "/v1/blocks/{id}", | ||
url: "/v1/blocks/53730d3f3d2d2f46cb910b16db817d3a62adaaa72fdb3a92ee373c37c5b55a76", | ||
expected: "getBlocksByIDs", | ||
}, | ||
{ | ||
name: "/v1/blocks/{id}/payload", | ||
url: "/v1/blocks/53730d3f3d2d2f46cb910b16db817d3a62adaaa72fdb3a92ee373c37c5b55a76/payload", | ||
expected: "getBlockPayloadByID", | ||
}, | ||
{ | ||
name: "/v1/execution_results/{id}", | ||
url: "/v1/execution_results/53730d3f3d2d2f46cb910b16db817d3a62adaaa72fdb3a92ee373c37c5b55a76", | ||
expected: "getExecutionResultByID", | ||
}, | ||
{ | ||
name: "/v1/execution_results", | ||
url: "/v1/execution_results", | ||
expected: "getExecutionResultByBlockID", | ||
}, | ||
{ | ||
name: "/v1/collections/{id}", | ||
url: "/v1/collections/53730d3f3d2d2f46cb910b16db817d3a62adaaa72fdb3a92ee373c37c5b55a76", | ||
expected: "getCollectionByID", | ||
}, | ||
{ | ||
name: "/v1/scripts", | ||
url: "/v1/scripts", | ||
expected: "executeScript", | ||
}, | ||
{ | ||
name: "/v1/accounts/{address}", | ||
url: "/v1/accounts/6a587be304c1224c", | ||
expected: "getAccount", | ||
}, | ||
{ | ||
name: "/v1/events", | ||
url: "/v1/events", | ||
expected: "getEvents", | ||
}, | ||
{ | ||
name: "/v1/network/parameters", | ||
url: "/v1/network/parameters", | ||
expected: "getNetworkParameters", | ||
}, | ||
{ | ||
name: "/v1/node_version_info", | ||
url: "/v1/node_version_info", | ||
expected: "getNodeVersionInfo", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := URLToRoute(tt.url) | ||
require.NoError(t, err) | ||
assert.Equal(t, tt.expected, got) | ||
}) | ||
} | ||
} | ||
|
||
func TestBenchmarkParseURL(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
url string | ||
expected string | ||
}{ | ||
{ | ||
name: "/v1/transactions", | ||
url: "/v1/transactions", | ||
expected: "createTransaction", | ||
}, | ||
{ | ||
name: "/v1/transactions/{id}", | ||
url: "/v1/transactions/53730d3f3d2d2f46cb910b16db817d3a62adaaa72fdb3a92ee373c37c5b55a76", | ||
expected: "getTransactionByID", | ||
}, | ||
{ | ||
name: "/v1/transaction_results/{id}", | ||
url: "/v1/transaction_results/53730d3f3d2d2f46cb910b16db817d3a62adaaa72fdb3a92ee373c37c5b55a76", | ||
expected: "getTransactionResultByID", | ||
}, | ||
{ | ||
name: "/v1/blocks", | ||
url: "/v1/blocks", | ||
expected: "getBlocksByHeight", | ||
}, | ||
{ | ||
name: "/v1/blocks/{id}", | ||
url: "/v1/blocks/53730d3f3d2d2f46cb910b16db817d3a62adaaa72fdb3a92ee373c37c5b55a76", | ||
expected: "getBlocksByIDs", | ||
}, | ||
{ | ||
name: "/v1/blocks/{id}/payload", | ||
url: "/v1/blocks/53730d3f3d2d2f46cb910b16db817d3a62adaaa72fdb3a92ee373c37c5b55a76/payload", | ||
expected: "getBlockPayloadByID", | ||
}, | ||
{ | ||
name: "/v1/execution_results/{id}", | ||
url: "/v1/execution_results/53730d3f3d2d2f46cb910b16db817d3a62adaaa72fdb3a92ee373c37c5b55a76", | ||
expected: "getExecutionResultByID", | ||
}, | ||
{ | ||
name: "/v1/execution_results", | ||
url: "/v1/execution_results", | ||
expected: "getExecutionResultByBlockID", | ||
}, | ||
{ | ||
name: "/v1/collections/{id}", | ||
url: "/v1/collections/53730d3f3d2d2f46cb910b16db817d3a62adaaa72fdb3a92ee373c37c5b55a76", | ||
expected: "getCollectionByID", | ||
}, | ||
{ | ||
name: "/v1/scripts", | ||
url: "/v1/scripts", | ||
expected: "executeScript", | ||
}, | ||
{ | ||
name: "/v1/accounts/{address}", | ||
url: "/v1/accounts/6a587be304c1224c", | ||
expected: "getAccount", | ||
}, | ||
{ | ||
name: "/v1/events", | ||
url: "/v1/events", | ||
expected: "getEvents", | ||
}, | ||
{ | ||
name: "/v1/network/parameters", | ||
url: "/v1/network/parameters", | ||
expected: "getNetworkParameters", | ||
}, | ||
{ | ||
name: "/v1/node_version_info", | ||
url: "/v1/node_version_info", | ||
expected: "getNodeVersionInfo", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
start := time.Now() | ||
for i := 0; i < 100_000; i++ { | ||
_, _ = URLToRoute(tt.url) | ||
} | ||
t.Logf("%s: %v", tt.name, time.Since(start)/100_000) | ||
}) | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
looks like there are a few REST unittests failing with empty responses. I'm guessing it's related to this return since it effectively drops the request. Can you take a look?
most likely, the tests just need to be updated to use more valid urls/inputs, but not 100% sure.
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.
Could I, for example, on error just fill routeName with an "unknown" or "invalid" string? Because this function anyway supposes to return http.Handler
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.
yea, that sounds good. Let's go with
unknown