Documentation
¶
Index ¶
- Constants
- Variables
- func GetClientNameAndVersion(ctx context.Context) (string, string)
- func GetValues(ctx context.Context, headerNames ...string) []string
- func NewDefaultVersionChecker() *versionChecker
- func NewVersionChecker(supportedClients map[string]string, serverVersion string) *versionChecker
- func Propagate(ctx context.Context) context.Context
- func SetCallerInfo(ctx context.Context, info CallerInfo) context.Context
- func SetCallerName(ctx context.Context, callerName string) context.Context
- func SetCallerType(ctx context.Context, callerType string) context.Context
- func SetOrigin(ctx context.Context, callOrigin string) context.Context
- func SetVersions(ctx context.Context) context.Context
- func SetVersionsForTests(ctx context.Context, ...) context.Context
- type CallerInfo
- type GRPCHeaderGetter
- type HeaderGetter
- type VersionChecker
Constants ¶
const (
CallerTypeOperator = "operator"
CallerTypeAPI = "api"
CallerTypeBackground = "background"
CallerTypePreemptable = "preemptable"
CallerNameSystem = "system"
)
const (
ClientNameHeaderName = "client-name"
ClientVersionHeaderName = "client-version"
SupportedServerVersionsHeaderName = "supported-server-versions"
SupportedFeaturesHeaderName = "supported-features"
SupportedFeaturesHeaderDelim = ","
CallerNameHeaderName = "caller-name"
CallerTypeHeaderName = "caller-type"
CallOriginHeaderName = "call-initiation"
)
Note the nexusoperations component references these headers and adds them to a list of disallowed headers for users to set. If any other headers are added for internal use, they should be added to the disallowed headers list.
const (
ClientNameServer = "temporal-server"
ClientNameServerHTTP = "temporal-server-http"
ClientNameGoSDK = "temporal-go"
ClientNameJavaSDK = "temporal-java"
ClientNamePHPSDK = "temporal-php"
ClientNameTypeScriptSDK = "temporal-typescript"
ClientNamePythonSDK = "temporal-python"
ClientNameCLI = "temporal-cli"
ClientNameUI = "temporal-ui"
ClientNameNexusGoSDK = "Nexus-go-sdk"
// ServerVersion value can be changed by the create-tag Github workflow.
// If you change the var name or move it, be sure to update the workflow.
ServerVersion = "1.27.0"
// SupportedServerVersions is used by CLI and inter role communication.
SupportedServerVersions = ">=1.0.0 <2.0.0"
// FeatureFollowsNextRunID means that the client supports following next execution run id for
// completed/failed/timedout completion events when getting the final result of a workflow.
FeatureFollowsNextRunID = "follows-next-run-id"
)
Variables ¶
var (
SystemBackgroundCallerInfo = CallerInfo{
CallerName: CallerNameSystem,
CallerType: CallerTypeBackground,
}
SystemPreemptableCallerInfo = CallerInfo{
CallerName: CallerNameSystem,
CallerType: CallerTypePreemptable,
}
)
var (
// AllFeatures contains all known features. This list is used as the value of the supported
// features header for internal server requests. There is an assumption that if a feature is
// defined, then the server itself supports it.
AllFeatures = strings.Join([]string{
FeatureFollowsNextRunID,
}, SupportedFeaturesHeaderDelim)
SupportedClients = map[string]string{
ClientNameGoSDK: "<2.0.0",
ClientNameJavaSDK: "<2.0.0",
ClientNamePHPSDK: "<2.0.0",
ClientNameTypeScriptSDK: "<2.0.0",
ClientNameCLI: "<2.0.0",
ClientNameServer: "<2.0.0",
ClientNameUI: "<3.0.0",
ClientNameNexusGoSDK: "<2.0.0",
}
)
Functions ¶
func GetClientNameAndVersion ¶ added in v1.15.0
func GetClientNameAndVersion(ctx context.Context) (string, string)
GetClientNameAndVersion extracts SDK name and version from context headers
func GetValues ¶
func GetValues(ctx context.Context, headerNames ...string) []string
GetValues returns header values for passed header names. It always returns slice of the same size as number of passed header names.
func NewDefaultVersionChecker ¶ added in v1.0.0
func NewDefaultVersionChecker() *versionChecker
NewDefaultVersionChecker constructs a new VersionChecker using default versions from const.
func NewVersionChecker ¶
func NewVersionChecker(supportedClients map[string]string, serverVersion string) *versionChecker
NewVersionChecker constructs a new VersionChecker
func Propagate ¶ added in v1.13.0
func Propagate(ctx context.Context) context.Context
Propagate propagates version headers from incoming context to outgoing context. It copies all headers to outgoing context only if they are exist in incoming context and doesn't exist in outgoing context already.
func SetCallerInfo ¶ added in v1.17.2
func SetCallerInfo(
ctx context.Context,
info CallerInfo,
) context.Context
SetCallerInfo sets callerName, callerType and CallOrigin in the context. Existing values will be overwritten if new value is not empty. TODO: consider only set the caller info to golang context instead of grpc metadata and propagate to grpc outgoing context upon making an rpc call
func SetCallerName ¶ added in v1.17.3
func SetCallerName(
ctx context.Context,
callerName string,
) context.Context
SetCallerName set caller name in the context. Existing caller name will be overwritten if exists and new caller name is not empty.
func SetCallerType ¶ added in v1.17.3
func SetCallerType(
ctx context.Context,
callerType string,
) context.Context
SetCallerType set caller type in the context. Existing caller type will be overwritten if exists and new caller type is not empty.
func SetOrigin ¶ added in v1.17.3
func SetOrigin(
ctx context.Context,
callOrigin string,
) context.Context
SetOrigin set call origin in the context. Existing call origin will be overwritten if exists and new call origin is not empty.
func SetVersions ¶
func SetVersions(ctx context.Context) context.Context
SetVersions sets headers for internal communications.
func SetVersionsForTests ¶
func SetVersionsForTests(ctx context.Context, clientVersion, clientName, supportedServerVersions, supportedFeatures string) context.Context
SetVersionsForTests sets headers as they would be received from the client. Must be used in tests only.
Types ¶
type CallerInfo ¶ added in v1.17.2
type CallerInfo struct {
// CallerName is the name of the caller.
// It can either user namespace name or
// the predefined CallerNameSystem.
CallerName string
// CallerType indicates if the call originates from
// user API calls or from system background operations.
CallerType string
// CallOrigin is the first API method name in the call chain.
// Currently, it is only specified when CallerType is CallerTypeAPI
CallOrigin string
}
func GetCallerInfo ¶ added in v1.17.2
func GetCallerInfo(
ctx context.Context,
) CallerInfo
GetCallerInfo retrieves caller information from the context if exists. Empty value is returned if any piece of caller information is not specified in the context.
func NewBackgroundCallerInfo ¶ added in v1.17.3
func NewBackgroundCallerInfo(
callerName string,
) CallerInfo
NewBackgroundCallerInfo creates a new CallerInfo with Background callerType and empty callOrigin. This is equivalent to NewCallerInfo(callerName, CallerTypeBackground, "")
func NewCallerInfo ¶ added in v1.17.2
func NewCallerInfo(
callerName string,
callerType string,
callOrigin string,
) CallerInfo
NewCallerInfo creates a new CallerInfo
func NewPreemptableCallerInfo ¶ added in v1.20.1
func NewPreemptableCallerInfo(
callerName string,
) CallerInfo
NewPreemptableCallerInfo creates a new CallerInfo with Preemptable callerType and empty callOrigin. This is equivalent to NewCallerInfo(callerName, CallerTypePreemptable, "")
type GRPCHeaderGetter ¶ added in v1.24.0
type GRPCHeaderGetter struct {
// contains filtered or unexported fields
}
Wrapper for gRPC metadata that exposes a helper to extract a single metadata value.
func NewGRPCHeaderGetter ¶ added in v1.25.0
func NewGRPCHeaderGetter(ctx context.Context) GRPCHeaderGetter
type HeaderGetter ¶ added in v1.24.0
type HeaderGetter interface {
Get(string) string
}
HeaderGetter is an interface for getting a single header value from a case insensitive key.
type VersionChecker ¶
type VersionChecker interface {
ClientSupported(ctx context.Context) error
ClientSupportsFeature(ctx context.Context, feature string) bool
}
VersionChecker is used to check client/server compatibility and client's capabilities