-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 5.1] grpc: add interceptor that tracks the sizes of all mes…
…sages sent by servers/clients (#55495) Follow up to https://github.com/sourcegraph/sourcegraph/pull/55209 and https://github.com/sourcegraph/sourcegraph/pull/55242. This PR adds interceptors that records Prometheus metrics that observe: - the individual size of each **sent** protobuf message by a server or client - the total amount data sent over the course a single RPC by a server (responses) or client (requests) This allows us to track the total amount of a data returned by any of our RPCs. In some cases, this can reveal opportunities for future performance / stability improvements (Example: symbols' [LocalCodeIntel method returning ~gigabyte sized responses that has to be held all at once in memory](https://github.com/sourcegraph/sourcegraph/pull/55242)). This PR also provides new grafana dashboards that track this metric for every gRPC service. See below for a screenshot of what this looks like when I run the symbols service locally. Co-authored-by: Geoffrey Gilmore <geoffrey@sourcegraph.com>
- Loading branch information
1 parent
71efffe
commit aa4f838
Showing
21 changed files
with
2,025 additions
and
140 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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.
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,14 @@ | ||
package grpcutil | ||
|
||
import "strings" | ||
|
||
// SplitMethodName splits a full gRPC method name (e.g. "/package.service/method") in to its individual components (service, method) | ||
// | ||
// Copied from github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/reporter.go | ||
func SplitMethodName(fullMethod string) (string, string) { | ||
fullMethod = strings.TrimPrefix(fullMethod, "/") // remove leading slash | ||
if i := strings.Index(fullMethod, "/"); i >= 0 { | ||
return fullMethod[:i], fullMethod[i+1:] | ||
} | ||
return "unknown", "unknown" | ||
} |
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,59 @@ | ||
package grpcutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestSplitMethodName(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
|
||
fullMethod string | ||
wantService string | ||
wantMethod string | ||
}{ | ||
{ | ||
name: "full method with service and method", | ||
|
||
fullMethod: "/package.service/method", | ||
wantService: "package.service", | ||
wantMethod: "method", | ||
}, | ||
{ | ||
name: "method without leading slash", | ||
|
||
fullMethod: "package.service/method", | ||
wantService: "package.service", | ||
wantMethod: "method", | ||
}, | ||
{ | ||
name: "service without method", | ||
|
||
fullMethod: "/package.service/", | ||
wantService: "package.service", | ||
wantMethod: "", | ||
}, | ||
{ | ||
name: "empty input", | ||
|
||
fullMethod: "", | ||
wantService: "unknown", | ||
wantMethod: "unknown", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
service, method := SplitMethodName(tc.fullMethod) | ||
if diff := cmp.Diff(service, tc.wantService); diff != "" { | ||
t.Errorf("splitMethodName(%q) service (-want +got):\n%s", tc.fullMethod, diff) | ||
} | ||
|
||
if diff := cmp.Diff(method, tc.wantMethod); diff != "" { | ||
t.Errorf("splitMethodName(%q) method (-want +got):\n%s", tc.fullMethod, diff) | ||
} | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.