snapshot of https://github.com/grpc/grpc-go.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
codecov / upload (push) Failing after 13m59s
CodeQL / Analyze (push) Failing after 1s
Testing / vet-proto (push) Failing after 1s
Testing / tests (arm, latest) (push) Waiting to run
Testing / extras (latest) (push) Failing after 1s
Testing / static checks (latest-1) (push) Failing after 1s
Testing / tests (-race, latest) (push) Failing after 1s
Testing / tests (i386, latest) (push) Failing after 1s
Testing / tests (latest) (push) Failing after 1s
Testing / tests (latest-1) (push) Failing after 1s
Lock Threads / lock (push) Failing after 1s
govulncheck / govulncheck (.) (push) Failing after 1s
govulncheck / govulncheck (./cmd/protoc-gen-go-grpc) (push) Failing after 1s
govulncheck / govulncheck (./gcp/observability) (push) Failing after 1s
govulncheck / govulncheck (./security/advancedtls) (push) Failing after 1s
govulncheck / govulncheck (./stats/opencensus) (push) Failing after 1s
Stale bot / stale (push) Failing after 1s
Some checks failed
codecov / upload (push) Failing after 13m59s
CodeQL / Analyze (push) Failing after 1s
Testing / vet-proto (push) Failing after 1s
Testing / tests (arm, latest) (push) Waiting to run
Testing / extras (latest) (push) Failing after 1s
Testing / static checks (latest-1) (push) Failing after 1s
Testing / tests (-race, latest) (push) Failing after 1s
Testing / tests (i386, latest) (push) Failing after 1s
Testing / tests (latest) (push) Failing after 1s
Testing / tests (latest-1) (push) Failing after 1s
Lock Threads / lock (push) Failing after 1s
govulncheck / govulncheck (.) (push) Failing after 1s
govulncheck / govulncheck (./cmd/protoc-gen-go-grpc) (push) Failing after 1s
govulncheck / govulncheck (./gcp/observability) (push) Failing after 1s
govulncheck / govulncheck (./security/advancedtls) (push) Failing after 1s
govulncheck / govulncheck (./stats/opencensus) (push) Failing after 1s
Stale bot / stale (push) Failing after 1s
This commit is contained in:
244
internal/envconfig/envconfig.go
Normal file
244
internal/envconfig/envconfig.go
Normal file
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
// Package envconfig contains grpc settings configured by environment variables.
|
||||
package envconfig
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
// EnableTXTServiceConfig is set if the DNS resolver should perform TXT
|
||||
// lookups for service config ("GRPC_ENABLE_TXT_SERVICE_CONFIG" is not
|
||||
// "false").
|
||||
EnableTXTServiceConfig = boolFromEnv("GRPC_ENABLE_TXT_SERVICE_CONFIG", true)
|
||||
|
||||
// TXTErrIgnore is set if TXT errors should be ignored
|
||||
// ("GRPC_GO_IGNORE_TXT_ERRORS" is not "false").
|
||||
TXTErrIgnore = boolFromEnv("GRPC_GO_IGNORE_TXT_ERRORS", true)
|
||||
|
||||
// RingHashCap indicates the maximum ring size which defaults to 4096
|
||||
// entries but may be overridden by setting the environment variable
|
||||
// "GRPC_RING_HASH_CAP". This does not override the default bounds
|
||||
// checking which NACKs configs specifying ring sizes > 8*1024*1024 (~8M).
|
||||
RingHashCap = uint64FromEnv("GRPC_RING_HASH_CAP", 4096, 1, 8*1024*1024)
|
||||
|
||||
// ALTSMaxConcurrentHandshakes is the maximum number of concurrent ALTS
|
||||
// handshakes that can be performed.
|
||||
ALTSMaxConcurrentHandshakes = uint64FromEnv("GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES", 100, 1, 100)
|
||||
|
||||
// EnforceALPNEnabled is set if TLS connections to servers with ALPN disabled
|
||||
// should be rejected. The HTTP/2 protocol requires ALPN to be enabled, this
|
||||
// option is present for backward compatibility. This option may be overridden
|
||||
// by setting the environment variable "GRPC_ENFORCE_ALPN_ENABLED" to "true"
|
||||
// or "false".
|
||||
EnforceALPNEnabled = boolFromEnv("GRPC_ENFORCE_ALPN_ENABLED", true)
|
||||
|
||||
// XDSEndpointHashKeyBackwardCompat controls the parsing of the endpoint hash
|
||||
// key from EDS LbEndpoint metadata. Endpoint hash keys can be disabled by
|
||||
// setting "GRPC_XDS_ENDPOINT_HASH_KEY_BACKWARD_COMPAT" to "true". A future
|
||||
// release will remove this environment variable, enabling the new behavior
|
||||
// unconditionally.
|
||||
XDSEndpointHashKeyBackwardCompat = boolFromEnv("GRPC_XDS_ENDPOINT_HASH_KEY_BACKWARD_COMPAT", false)
|
||||
|
||||
// LabelServerGoroutines controls setting [runtime/pprof.Labels] on the
|
||||
// goroutines spawned by [grpc.Server] type.
|
||||
// For now, this is limited to the goroutines spawned to handle incoming
|
||||
// requests on the server.
|
||||
// Set "GRPC_GO_SERVER_GOROUTINE_LABELS" to "grpc.method=true" to
|
||||
// enable this grpc.method label, or "all" to enable all valid labels.
|
||||
// This variable is a bit-field.
|
||||
LabelServerGoroutines = goroutineLabelsFromEnv("GRPC_GO_SERVER_GOROUTINE_LABELS", 0)
|
||||
|
||||
// RingHashSetRequestHashKey is set if the ring hash balancer can get the
|
||||
// request hash header by setting the "requestHashHeader" field, according
|
||||
// to gRFC A76. It can be disabled by setting the environment variable
|
||||
// "GRPC_EXPERIMENTAL_RING_HASH_SET_REQUEST_HASH_KEY" to "false".
|
||||
RingHashSetRequestHashKey = boolFromEnv("GRPC_EXPERIMENTAL_RING_HASH_SET_REQUEST_HASH_KEY", true)
|
||||
|
||||
// ALTSHandshakerKeepaliveParams is set if we should add the
|
||||
// KeepaliveParams when dial the ALTS handshaker service.
|
||||
ALTSHandshakerKeepaliveParams = boolFromEnv("GRPC_EXPERIMENTAL_ALTS_HANDSHAKER_KEEPALIVE_PARAMS", false)
|
||||
|
||||
// EnableDefaultPortForProxyTarget controls whether the resolver adds a default port 443
|
||||
// to a target address that lacks one. This flag only has an effect when all of
|
||||
// the following conditions are met:
|
||||
// - A connect proxy is being used.
|
||||
// - Target resolution is disabled.
|
||||
// - The DNS resolver is being used.
|
||||
EnableDefaultPortForProxyTarget = boolFromEnv("GRPC_EXPERIMENTAL_ENABLE_DEFAULT_PORT_FOR_PROXY_TARGET", true)
|
||||
|
||||
// CaseSensitiveBalancerRegistries is set if the balancer registry should be
|
||||
// case-sensitive. This is enabled by default, but can be disabled by setting
|
||||
// the env variable "GRPC_GO_EXPERIMENTAL_CASE_SENSITIVE_BALANCER_REGISTRIES"
|
||||
// to "false".
|
||||
//
|
||||
// This env varible will be removed in release v1.82.0.
|
||||
CaseSensitiveBalancerRegistries = boolFromEnv("GRPC_GO_EXPERIMENTAL_CASE_SENSITIVE_BALANCER_REGISTRIES", true)
|
||||
|
||||
// XDSAuthorityRewrite indicates whether xDS authority rewriting is enabled.
|
||||
// This feature is defined in gRFC A81 and is enabled by setting the
|
||||
// environment variable GRPC_EXPERIMENTAL_XDS_AUTHORITY_REWRITE to "true".
|
||||
XDSAuthorityRewrite = boolFromEnv("GRPC_EXPERIMENTAL_XDS_AUTHORITY_REWRITE", false)
|
||||
|
||||
// PickFirstWeightedShuffling indicates whether weighted endpoint shuffling
|
||||
// is enabled in the pick_first LB policy, as defined in gRFC A113. This
|
||||
// feature can be disabled by setting the environment variable
|
||||
// GRPC_EXPERIMENTAL_PF_WEIGHTED_SHUFFLING to "false".
|
||||
PickFirstWeightedShuffling = boolFromEnv("GRPC_EXPERIMENTAL_PF_WEIGHTED_SHUFFLING", true)
|
||||
|
||||
// XDSRecoverPanicInResourceParsing indicates whether the xdsclient should
|
||||
// recover from panics while parsing xDS resources.
|
||||
//
|
||||
// This feature can be disabled (e.g. for fuzz testing) by setting the
|
||||
// environment variable "GRPC_GO_EXPERIMENTAL_XDS_RESOURCE_PANIC_RECOVERY"
|
||||
// to "false".
|
||||
XDSRecoverPanicInResourceParsing = boolFromEnv("GRPC_GO_EXPERIMENTAL_XDS_RESOURCE_PANIC_RECOVERY", true)
|
||||
|
||||
// EnablePriorityLBChildPolicyCache controls whether the priority balancer
|
||||
// should cache child balancers that are removed from the LB policy config,
|
||||
// for a period of 15 minutes. This is disabled by default, but can be
|
||||
// enabled by setting the env variable
|
||||
// GRPC_EXPERIMENTAL_ENABLE_PRIORITY_LB_CHILD_POLICY_CACHE to true.
|
||||
EnablePriorityLBChildPolicyCache = boolFromEnv("GRPC_EXPERIMENTAL_ENABLE_PRIORITY_LB_CHILD_POLICY_CACHE", false)
|
||||
|
||||
// Enable8KBDefaultHeaderListSize indicates that default maximum header list
|
||||
// size is restricted to 8KB. This is disabled by default, but can be enabled
|
||||
// by setting the environment variable
|
||||
// "GRPC_GO_EXPERIMENTAL_ENABLE_8KB_DEFAULT_HEADER_LIST_SIZE" to "true".
|
||||
// When disabled, the default maximum header list size of 16MB is used.
|
||||
//
|
||||
// When enabled, RPCs with a total size of headers exceeding 8KB will fail
|
||||
// unless explicitly configured otherwise by the user.
|
||||
//
|
||||
// TODO: In release v1.82.0, env var will be enabled by default.
|
||||
Enable8KBDefaultHeaderListSize = boolFromEnv("GRPC_GO_EXPERIMENTAL_ENABLE_8KB_DEFAULT_HEADER_LIST_SIZE", false)
|
||||
|
||||
// EnableHTTPFramerReadBufferPooling enables the use of the
|
||||
// readyreader.Reader interface to perform non-memory-pinning reads,
|
||||
// provided the underlying net.Conn supports it. This reduces memory usage
|
||||
// when subchannels are idle.
|
||||
//
|
||||
// This environment variable serves as an escape hatch to disable the
|
||||
// feature if unforeseen issues arise, and it will be removed in a future
|
||||
// release.
|
||||
EnableHTTPFramerReadBufferPooling = boolFromEnv("GRPC_GO_EXPERIMENTAL_HTTP_FRAMER_READ_BUFFER_POOLING", true)
|
||||
|
||||
// ControlBufferThrottleLimit is the maximum number of control frames that can
|
||||
// be queued in the control buffer before throttling is applied. The value
|
||||
// must be between 1 and 10,000, and is set to 100 by default.
|
||||
//
|
||||
// This environment variable serves as an escape hatch to increase the
|
||||
// throttling limit if unforeseen issues arise, and it will be removed in a
|
||||
// future release.
|
||||
//
|
||||
// TODO: Remove this env var once v1.83.0 is released.
|
||||
ControlBufferThrottleLimit = uint64FromEnv("GRPC_GO_EXPERIMENTAL_CONTROL_BUFFER_THROTTLE_LIMIT", 100, 1, 10000)
|
||||
|
||||
// ALTSMaxFrameSize is the maximum frame size for ALTS in bytes.
|
||||
// This can be overridden by setting the environment variable
|
||||
// "GRPC_GO_EXPERIMENTAL_ALTS_MAX_FRAME_SIZE" (min: 4096, max: 512*1024, capped at
|
||||
// 512KiB to match altsWriteBufferMaxSize in
|
||||
// credentials/alts/internal/conn/record.go).
|
||||
ALTSMaxFrameSize = uint64FromEnv("GRPC_GO_EXPERIMENTAL_ALTS_MAX_FRAME_SIZE", 4096, 4096, 512*1024)
|
||||
|
||||
// EnableReceiveBufferCompaction enables the compaction of data buffers
|
||||
// to reduce the number of buffers in the receive buffer.
|
||||
//
|
||||
// This environment variable serves as an escape hatch to disable the
|
||||
// feature if unforeseen issues arise, and it will be removed in a future
|
||||
// release.
|
||||
//
|
||||
// TODO: Remove this env var once v1.85.0 is released.
|
||||
EnableReceiveBufferCompaction = boolFromEnv("GRPC_GO_EXPERIMENTAL_ENABLE_RECEIVE_BUFFER_COMPACTION", true)
|
||||
)
|
||||
|
||||
func boolFromEnv(envVar string, def bool) bool {
|
||||
if def {
|
||||
// The default is true; return true unless the variable is "false".
|
||||
return !strings.EqualFold(os.Getenv(envVar), "false")
|
||||
}
|
||||
// The default is false; return false unless the variable is "true".
|
||||
return strings.EqualFold(os.Getenv(envVar), "true")
|
||||
}
|
||||
|
||||
func uint64FromEnv(envVar string, def, min, max uint64) uint64 {
|
||||
v, err := strconv.ParseUint(os.Getenv(envVar), 10, 64)
|
||||
if err != nil {
|
||||
return def
|
||||
}
|
||||
if v < min {
|
||||
return min
|
||||
}
|
||||
if v > max {
|
||||
return max
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// GoroutineLabels is a bitfield indicating which goroutine labels are enabled.
|
||||
type GoroutineLabels uint16
|
||||
|
||||
func goroutineLabelsFromEnv(envVar string, def GoroutineLabels) GoroutineLabels {
|
||||
val := def
|
||||
v := os.Getenv(envVar)
|
||||
if strings.EqualFold(v, "all") {
|
||||
return AllGoroutineLabels
|
||||
} else if strings.EqualFold(v, "none") {
|
||||
return 0
|
||||
}
|
||||
for s := range strings.SplitSeq(v, ",") {
|
||||
s = strings.TrimSpace(s)
|
||||
if len(s) == 0 {
|
||||
continue
|
||||
}
|
||||
pre, post, ok := strings.Cut(s, "=")
|
||||
if !ok {
|
||||
// no equals sign
|
||||
continue
|
||||
}
|
||||
post = strings.TrimSpace(post)
|
||||
pre = strings.TrimSpace(pre)
|
||||
bitDesignator := GoroutineLabels(0)
|
||||
switch {
|
||||
case strings.EqualFold(pre, "grpc.method"):
|
||||
bitDesignator = GoroutineLabelServerMethod
|
||||
default:
|
||||
continue
|
||||
}
|
||||
if strings.EqualFold(post, "true") {
|
||||
val |= bitDesignator
|
||||
} else if strings.EqualFold(post, "false") {
|
||||
val &^= bitDesignator
|
||||
}
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
const (
|
||||
// GoroutineLabelServerMethod sets the grpc.method label on new
|
||||
// server-side gRPC streams.
|
||||
GoroutineLabelServerMethod GoroutineLabels = 1 << iota
|
||||
)
|
||||
|
||||
// AllGoroutineLabels is an or'd together bitfield of all valid GoroutineLabels
|
||||
// constant values (above).
|
||||
const AllGoroutineLabels = GoroutineLabelServerMethod
|
||||
218
internal/envconfig/envconfig_test.go
Normal file
218
internal/envconfig/envconfig_test.go
Normal file
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2022 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package envconfig
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"google.golang.org/grpc/internal/grpctest"
|
||||
)
|
||||
|
||||
type s struct {
|
||||
grpctest.Tester
|
||||
}
|
||||
|
||||
func Test(t *testing.T) {
|
||||
grpctest.RunSubTests(t, s{})
|
||||
}
|
||||
|
||||
func (s) TestUint64FromEnv(t *testing.T) {
|
||||
var testCases = []struct {
|
||||
name string
|
||||
val string
|
||||
def, min, max uint64
|
||||
want uint64
|
||||
}{
|
||||
{
|
||||
name: "error parsing",
|
||||
val: "asdf", def: 5, want: 5,
|
||||
}, {
|
||||
name: "unset",
|
||||
val: "", def: 5, want: 5,
|
||||
}, {
|
||||
name: "too low",
|
||||
val: "5", min: 10, want: 10,
|
||||
}, {
|
||||
name: "too high",
|
||||
val: "5", max: 2, want: 2,
|
||||
}, {
|
||||
name: "in range",
|
||||
val: "17391", def: 13000, min: 12000, max: 18000, want: 17391,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
const testVar = "testvar"
|
||||
if tc.val == "" {
|
||||
os.Unsetenv(testVar)
|
||||
} else {
|
||||
os.Setenv(testVar, tc.val)
|
||||
}
|
||||
if got := uint64FromEnv(testVar, tc.def, tc.min, tc.max); got != tc.want {
|
||||
t.Errorf("uint64FromEnv(%q(=%q), %v, %v, %v) = %v; want %v", testVar, tc.val, tc.def, tc.min, tc.max, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s) TestBoolFromEnv(t *testing.T) {
|
||||
var testCases = []struct {
|
||||
val string
|
||||
def bool
|
||||
want bool
|
||||
}{
|
||||
{val: "", def: true, want: true},
|
||||
{val: "", def: false, want: false},
|
||||
{val: "true", def: true, want: true},
|
||||
{val: "true", def: false, want: true},
|
||||
{val: "false", def: true, want: false},
|
||||
{val: "false", def: false, want: false},
|
||||
{val: "asdf", def: true, want: true},
|
||||
{val: "asdf", def: false, want: false},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run("", func(t *testing.T) {
|
||||
const testVar = "testvar"
|
||||
if tc.val == "" {
|
||||
os.Unsetenv(testVar)
|
||||
} else {
|
||||
os.Setenv(testVar, tc.val)
|
||||
}
|
||||
if got := boolFromEnv(testVar, tc.def); got != tc.want {
|
||||
t.Errorf("boolFromEnv(%q(=%q), %v) = %v; want %v", testVar, tc.val, tc.def, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s) TestGoroutineLabelsFromEnv(t *testing.T) {
|
||||
var testCases = []struct {
|
||||
name string
|
||||
val string
|
||||
def GoroutineLabels
|
||||
want GoroutineLabels
|
||||
}{
|
||||
{
|
||||
name: "unset_env_non-zero_default",
|
||||
val: "",
|
||||
def: GoroutineLabelServerMethod,
|
||||
want: GoroutineLabelServerMethod,
|
||||
}, {
|
||||
name: "unset_env_zero_default",
|
||||
val: "",
|
||||
def: 0,
|
||||
want: 0,
|
||||
}, {
|
||||
name: "force-enable_zero_default",
|
||||
val: "grpc.method=true",
|
||||
def: 0,
|
||||
want: GoroutineLabelServerMethod,
|
||||
}, {
|
||||
name: "force-enable_zero_default_all_caps",
|
||||
val: "grpc.method=TRUE",
|
||||
def: 0,
|
||||
want: GoroutineLabelServerMethod,
|
||||
}, {
|
||||
name: "force-enable_zero_default_with_whitespace",
|
||||
val: " grpc.method\t= true",
|
||||
def: 0,
|
||||
want: GoroutineLabelServerMethod,
|
||||
}, {
|
||||
name: "force-enable_zero_default_with_other_garbage",
|
||||
val: "grpc.method=true,foobar",
|
||||
def: 0,
|
||||
want: GoroutineLabelServerMethod,
|
||||
}, {
|
||||
name: "force-enable_mixed_case_zero_default_with_other_garbage",
|
||||
val: "grpc.method=tRuE,foobar",
|
||||
def: 0,
|
||||
want: GoroutineLabelServerMethod,
|
||||
}, {
|
||||
name: "force-disable_zero_default",
|
||||
val: "grpc.method=false",
|
||||
def: 0,
|
||||
want: 0,
|
||||
}, {
|
||||
name: "force-disable_non-zero_default",
|
||||
val: "grpc.method=false",
|
||||
def: GoroutineLabelServerMethod,
|
||||
want: 0,
|
||||
}, {
|
||||
name: "force-disable_non-zero_default_all_caps",
|
||||
val: "grpc.method=FALSE",
|
||||
def: GoroutineLabelServerMethod,
|
||||
want: 0,
|
||||
}, {
|
||||
name: "force-disable_non-zero_default_mixed_case",
|
||||
val: "grpc.method=fAlSe",
|
||||
def: GoroutineLabelServerMethod,
|
||||
want: 0,
|
||||
}, {
|
||||
name: "unknown_val_no_equal",
|
||||
val: "grpc.unknown.garbage",
|
||||
def: GoroutineLabelServerMethod,
|
||||
want: GoroutineLabelServerMethod,
|
||||
}, {
|
||||
name: "unknown_val",
|
||||
val: "grpc.unknown.garbage=fooble",
|
||||
def: GoroutineLabelServerMethod,
|
||||
want: GoroutineLabelServerMethod,
|
||||
}, {
|
||||
name: "all_with_empty_default",
|
||||
val: "all",
|
||||
def: 0,
|
||||
want: AllGoroutineLabels,
|
||||
}, {
|
||||
name: "all_with_server_method_default",
|
||||
val: "all",
|
||||
def: GoroutineLabelServerMethod,
|
||||
want: AllGoroutineLabels,
|
||||
}, {
|
||||
name: "none_with_empty_default",
|
||||
val: "none",
|
||||
def: 0,
|
||||
want: 0,
|
||||
}, {
|
||||
name: "none_with_server_method_default",
|
||||
val: "none",
|
||||
def: GoroutineLabelServerMethod,
|
||||
want: 0,
|
||||
}, {
|
||||
name: "unparseable_rhs",
|
||||
val: "grpc.method=quux",
|
||||
def: GoroutineLabelServerMethod,
|
||||
want: GoroutineLabelServerMethod,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
const testVar = "testvar"
|
||||
if tc.val == "" {
|
||||
os.Unsetenv(testVar)
|
||||
} else {
|
||||
os.Setenv(testVar, tc.val)
|
||||
}
|
||||
if got := goroutineLabelsFromEnv(testVar, tc.def); got != tc.want {
|
||||
t.Errorf("goroutineLabelsFromEnv(%q(=%q), %v) = %v; want %v", testVar, tc.val, tc.def, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
42
internal/envconfig/observability.go
Normal file
42
internal/envconfig/observability.go
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2022 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package envconfig
|
||||
|
||||
import "os"
|
||||
|
||||
const (
|
||||
envObservabilityConfig = "GRPC_GCP_OBSERVABILITY_CONFIG"
|
||||
envObservabilityConfigFile = "GRPC_GCP_OBSERVABILITY_CONFIG_FILE"
|
||||
)
|
||||
|
||||
var (
|
||||
// ObservabilityConfig is the json configuration for the gcp/observability
|
||||
// package specified directly in the envObservabilityConfig env var.
|
||||
//
|
||||
// This is used in the 1.0 release of gcp/observability, and thus must not be
|
||||
// deleted or changed.
|
||||
ObservabilityConfig = os.Getenv(envObservabilityConfig)
|
||||
// ObservabilityConfigFile is the json configuration for the
|
||||
// gcp/observability specified in a file with the location specified in
|
||||
// envObservabilityConfigFile env var.
|
||||
//
|
||||
// This is used in the 1.0 release of gcp/observability, and thus must not be
|
||||
// deleted or changed.
|
||||
ObservabilityConfigFile = os.Getenv(envObservabilityConfigFile)
|
||||
)
|
||||
106
internal/envconfig/xds.go
Normal file
106
internal/envconfig/xds.go
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2020 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package envconfig
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
// XDSBootstrapFileNameEnv is the env variable to set bootstrap file name.
|
||||
// Do not use this and read from env directly. Its value is read and kept in
|
||||
// variable XDSBootstrapFileName.
|
||||
//
|
||||
// When both bootstrap FileName and FileContent are set, FileName is used.
|
||||
XDSBootstrapFileNameEnv = "GRPC_XDS_BOOTSTRAP"
|
||||
// XDSBootstrapFileContentEnv is the env variable to set bootstrap file
|
||||
// content. Do not use this and read from env directly. Its value is read
|
||||
// and kept in variable XDSBootstrapFileContent.
|
||||
//
|
||||
// When both bootstrap FileName and FileContent are set, FileName is used.
|
||||
XDSBootstrapFileContentEnv = "GRPC_XDS_BOOTSTRAP_CONFIG"
|
||||
)
|
||||
|
||||
var (
|
||||
// XDSBootstrapFileName holds the name of the file which contains xDS
|
||||
// bootstrap configuration. Users can specify the location of the bootstrap
|
||||
// file by setting the environment variable "GRPC_XDS_BOOTSTRAP".
|
||||
//
|
||||
// When both bootstrap FileName and FileContent are set, FileName is used.
|
||||
XDSBootstrapFileName = os.Getenv(XDSBootstrapFileNameEnv)
|
||||
// XDSBootstrapFileContent holds the content of the xDS bootstrap
|
||||
// configuration. Users can specify the bootstrap config by setting the
|
||||
// environment variable "GRPC_XDS_BOOTSTRAP_CONFIG".
|
||||
//
|
||||
// When both bootstrap FileName and FileContent are set, FileName is used.
|
||||
XDSBootstrapFileContent = os.Getenv(XDSBootstrapFileContentEnv)
|
||||
|
||||
// C2PResolverTestOnlyTrafficDirectorURI is the TD URI for testing.
|
||||
C2PResolverTestOnlyTrafficDirectorURI = os.Getenv("GRPC_TEST_ONLY_GOOGLE_C2P_RESOLVER_TRAFFIC_DIRECTOR_URI")
|
||||
|
||||
// XDSDualstackEndpointsEnabled is true if gRPC should read the
|
||||
// "additional addresses" in the xDS endpoint resource.
|
||||
XDSDualstackEndpointsEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_DUALSTACK_ENDPOINTS", true)
|
||||
|
||||
// XDSSystemRootCertsEnabled is true when xDS enabled gRPC clients can use
|
||||
// the system's default root certificates for TLS certificate validation.
|
||||
// For more details, see:
|
||||
// https://github.com/grpc/proposal/blob/master/A82-xds-system-root-certs.md.
|
||||
XDSSystemRootCertsEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_SYSTEM_ROOT_CERTS", false)
|
||||
|
||||
// XDSSPIFFEEnabled controls if SPIFFE Bundle Maps can be used as roots of
|
||||
// trust. For more details, see:
|
||||
// https://github.com/grpc/proposal/blob/master/A87-mtls-spiffe-support.md
|
||||
XDSSPIFFEEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_MTLS_SPIFFE", false)
|
||||
|
||||
// XDSHTTPConnectEnabled controls support for dynamic HTTP CONNECT proxying
|
||||
// configured via the xDS control plane. For more details, see:
|
||||
// https://github.com/grpc/proposal/blob/master/A86-xds-http-connect.md
|
||||
XDSHTTPConnectEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_HTTP_CONNECT", false)
|
||||
|
||||
// XDSBootstrapCallCredsEnabled controls if call credentials can be used in
|
||||
// xDS bootstrap configuration via the `call_creds` field. For more details,
|
||||
// see: https://github.com/grpc/proposal/blob/master/A97-xds-jwt-call-creds.md
|
||||
XDSBootstrapCallCredsEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_BOOTSTRAP_CALL_CREDS", false)
|
||||
|
||||
// XDSSNIEnabled controls if gRPC should send SNI information in xDS
|
||||
// configured TLS handshakes. For more details, see:
|
||||
// https://github.com/grpc/proposal/blob/master/A101-SNI-setting-and-SNI-SAN-validation.md
|
||||
XDSSNIEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_SNI", false)
|
||||
|
||||
// XDSORCAToLRSPropEnabled controls whether ORCA metrics are explicitly
|
||||
// filtered and prefix-propagated to the LRS server. For more details, see:
|
||||
// https://github.com/grpc/proposal/blob/master/A85-lrs-custom-metrics-changes.md
|
||||
XDSORCAToLRSPropEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_ORCA_LRS_PROPAGATION", true)
|
||||
|
||||
// XDSClientExtProcEnabled indicates whether ExtProc filter is enabled on
|
||||
// the client side. For more details, see:
|
||||
// https://github.com/grpc/proposal/blob/master/A93-xds-ext-proc.md
|
||||
XDSClientExtProcEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_EXT_PROC_ON_CLIENT", false)
|
||||
|
||||
// GCPAuthenticationFilterEnabled enables the xDS GCP Authentication
|
||||
// filter. For more details, see:
|
||||
// https://github.com/grpc/proposal/blob/master/A83-xds-gcp-authn-filter.md
|
||||
GCPAuthenticationFilterEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_GCP_AUTHENTICATION_FILTER", false)
|
||||
|
||||
// XDSClientExtAuthzEnabled indicates whether the external authorization
|
||||
// filter is enabled on the client side. For more details, see:
|
||||
// https://github.com/grpc/proposal/blob/master/A92-xds-ext-authz.md
|
||||
XDSClientExtAuthzEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_EXT_AUTHZ_ON_CLIENT", false)
|
||||
)
|
||||
Reference in New Issue
Block a user