This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
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.
lib/msp: new clients library with recommended dial options (#64500)
These have worked pretty well for Cody Gateway - this change exports these from the MSP lib so that they can be used elsewhere. Closes https://linear.app/sourcegraph/issue/CORE-203 ## Test plan n/a
- Loading branch information
Showing
5 changed files
with
47 additions
and
25 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
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,12 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "clients", | ||
srcs = ["clients.go"], | ||
importpath = "github.com/sourcegraph/sourcegraph/lib/managedservicesplatform/clients", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@org_golang_google_grpc//:go_default_library", | ||
"@org_golang_google_grpc//keepalive", | ||
], | ||
) |
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,31 @@ | ||
package clients | ||
|
||
import ( | ||
"time" | ||
|
||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/keepalive" | ||
) | ||
|
||
// NewRecommendedGRPCDialOptions provides additional networking options tailored | ||
// for connecting to typical MSP environments over gRPC (Cloud Run services | ||
// behind Cloudflare). | ||
func NewRecommendedGRPCDialOptions() []grpc.DialOption { | ||
return []grpc.DialOption{ | ||
grpc.WithKeepaliveParams(keepalive.ClientParameters{ | ||
// Keep idle connections alive by pinging in this interval. | ||
// Default: Infinity. | ||
Time: 20 * time.Second, | ||
// Keepalive timeout duration. | ||
// Default: 20 seconds. | ||
Timeout: 10 * time.Second, | ||
// Ensure idle connections remain alive even if there is no traffic. | ||
// Default: False. | ||
PermitWithoutStream: true, | ||
}), | ||
// Ensure idle connections are not retained for a long time, to avoid | ||
// potential networking issues. | ||
// Default: 30 minutes | ||
grpc.WithIdleTimeout(1 * time.Minute), | ||
} | ||
} |
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