go.temporal.io/server/components/callbacks/request.go
146 LOC · 61 covered · 85 uncovered · 21 ranges · 17 concepts · 17 introducers · 9 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
package callbacks
import (
"errors"
"net/http"
"github.com/nexus-rpc/sdk-go/nexus"
"go.temporal.io/api/serviceerror"
"go.temporal.io/server/common"
"go.temporal.io/server/common/cluster"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/log/tag"
"go.temporal.io/server/common/namespace"
commonnexus "go.temporal.io/server/common/nexus"
)
// Header key used to identify callbacks that originate from and target the same cluster.
// Note: this is the nexusoperations.NexusCallbackSourceHeader stripped of Nexus-Callback-
const callbackSourceHeader = "source"
// routeSystemCallbackRequest routes a system callback request to the appropriate frontend client
// based on the callback token's namespace and active cluster.
func routeSystemCallbackRequest(
r *http.Request,
clusterMetadata cluster.Metadata,
namespaceRegistry namespace.Registry,
httpClientCache *cluster.FrontendHTTPClientCache,
callbackTokenGenerator *commonnexus.CallbackTokenGenerator,
localClient *common.FrontendHTTPClient,
logger log.Logger,
var frontendClient *common.FrontendHTTPClient
if r.Header != nil {
token, err := commonnexus.DecodeCallbackToken(r.Header.Get(commonnexus.CallbackTokenHeader))
request.go ×1
if err != nil {
return nil, nexus.NewHandlerErrorf(nexus.HandlerErrorTypeBadRequest, "invalid callback token")
}
if err != nil {
return nil, nexus.NewHandlerErrorf(nexus.HandlerErrorTypeBadRequest, "invalid callback token")
}
// Resolve the target namespace/workflow from the token. For CHASM completions (e.g.
// standalone Nexus operations) the namespace lives inside the ComponentRef, not the
// top-level field, so use the shared helper rather than reading completion.NamespaceId
// directly.
namespaceID, businessID, _, err := commonnexus.CompletionTarget(completion)
callback_token.go ×2
if err != nil {
logger.Error("failed to extract target from nexus completion token", tag.Error(err))
return nil, nexus.NewHandlerErrorf(nexus.HandlerErrorTypeBadRequest, "invalid callback token")
}
if err != nil {
logger.Error("failed to get namespace for nexus completion request", tag.WorkflowNamespaceID(namespaceID), tag.Error(err))
request.go ×1
var nfe *serviceerror.NamespaceNotFound
if errors.As(err, &nfe) {
return nil, nexus.NewHandlerErrorf(nexus.HandlerErrorTypeNotFound, "namespace %q not found", namespaceID)
}
return nil, commonnexus.ConvertGRPCError(err, false)
}
if clusterMetadata.GetCurrentClusterName() == clusterName {
frontendClient = localClient
} else {
fec, err := httpClientCache.Get(clusterName)
if err != nil {
logger.Warn(
"HTTPCallerProvider unable to get FrontendHTTPClient for callback target cluster. Using local HTTP Client.",
tag.SourceCluster(clusterMetadata.GetCurrentClusterName()),
tag.TargetCluster(clusterName),
tag.Error(err),
)
frontendClient = localClient
} else {
frontendClient = fec
}
}
frontendClient = localClient
}
r.URL.Scheme = frontendClient.Scheme
r.URL.Host = frontendClient.Address
r.Host = frontendClient.Address
return frontendClient.Do(r)
}
func routeRequest(
r *http.Request,
clusterMetadata cluster.Metadata,
namespaceRegistry namespace.Registry,
httpClientCache *cluster.FrontendHTTPClientCache,
callbackTokenGenerator *commonnexus.CallbackTokenGenerator,
defaultClient *http.Client,
localClient *common.FrontendHTTPClient,
logger log.Logger,
if r.URL.String() == commonnexus.SystemCallbackURL {
return routeSystemCallbackRequest(r, clusterMetadata, namespaceRegistry, httpClientCache, callbackTokenGenerator, localClient, logger)
request.go ×1
}
// This source header is populated in nexusoperations/executors (via the ClientProvider) for worker targets
// if this header is not populated then we assume it's an external target.
}
// If we got here, we assume that the endpoint in the original call was a worker target, and we should route
// internally, either to a local frontend, or one of the other connected clusters' frontends.
callbackSource := r.Header.Get(callbackSourceHeader)
for clusterName, clusterInfo := range clusterMetadata.GetAllClusterInfo() {
if callbackSource == clusterInfo.ClusterID {
frontendClient = localClient
} else {
fec, err := httpClientCache.Get(clusterName)
if err != nil {
logger.Warn(
"HTTPCallerProvider unable to get FrontendHTTPClient for callback target cluster. Using local HTTP Client.",
tag.SourceCluster(clusterMetadata.GetCurrentClusterName()),
tag.TargetCluster(clusterName),
tag.Error(err),
)
frontendClient = localClient
} else {
frontendClient = fec
}
}
}
}
logger.Warn(
"HTTPCallerProvider unable to find the target cluster. Using local HTTP Client.",
tag.SourceCluster(clusterMetadata.GetCurrentClusterName()),
)
frontendClient = localClient
}
r.URL.Host = frontendClient.Address
r.Host = frontendClient.Address
return frontendClient.Do(r)
}