Skip to content

Commit

Permalink
escape reachability search attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
carlydf committed Nov 23, 2024
1 parent 215efc9 commit 6de1893
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
19 changes: 17 additions & 2 deletions common/worker_versioning/worker_versioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,24 @@ const (
UnversionedSearchAttribute = buildIdSearchAttributePrefixUnversioned
)

// ReachabilityBuildIdSearchAttribute returns the search attribute value for the currently assigned build ID
// escapeBuildIdSearchAttributeDelimiter is a helper which escapes the BuildIdSearchAttributeDelimiter character in the input string
func escapeBuildIdSearchAttributeDelimiter(s string) string {
s = strings.Replace(s, BuildIdSearchAttributeDelimiter, `|`+BuildIdSearchAttributeDelimiter, -1)
return s
}

// ReachabilityBuildIdSearchAttribute returns the search attribute value for the currently assigned build ID in the form
// 'reachability:<behavior>:<deployment_series_name>:<deployment_build_id>'
func ReachabilityBuildIdSearchAttribute(behavior enumspb.VersioningBehavior, deployment *deploymentpb.Deployment) string {
return fmt.Sprintf("%s:%s:%s", buildIdSearchAttributePrefixReachability, behavior.String(), DeploymentToString(deployment))
return sqlparser.String(sqlparser.NewStrVal([]byte(fmt.Sprintf("%s%s%s%s%s%s%s",
buildIdSearchAttributePrefixReachability,
BuildIdSearchAttributeDelimiter,
escapeBuildIdSearchAttributeDelimiter(behavior.String()),
BuildIdSearchAttributeDelimiter,
escapeBuildIdSearchAttributeDelimiter(deployment.GetSeriesName()),
BuildIdSearchAttributeDelimiter,
escapeBuildIdSearchAttributeDelimiter(deployment.GetBuildId()),
))))
}

// AssignedBuildIdSearchAttribute returns the search attribute value for the currently assigned build ID
Expand Down
11 changes: 4 additions & 7 deletions service/worker/deployment/deployment_reachability.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package deployment
import (
"context"
"fmt"
"github.com/temporalio/sqlparser"
deploymentpb "go.temporal.io/api/deployment/v1"
enumspb "go.temporal.io/api/enums/v1"
"go.temporal.io/server/common/cache"
Expand Down Expand Up @@ -92,12 +91,10 @@ func makeCountRequest(

func makeDeploymentQuery(seriesName, buildID string, open bool) string {
var statusFilter string
deploymentFilter := "= " + sqlparser.String(sqlparser.NewStrVal([]byte(
worker_versioning.ReachabilityBuildIdSearchAttribute(enumspb.VERSIONING_BEHAVIOR_PINNED, &deploymentpb.Deployment{
SeriesName: seriesName,
BuildId: buildID,
}),
)))
deploymentFilter := "= " + worker_versioning.ReachabilityBuildIdSearchAttribute(enumspb.VERSIONING_BEHAVIOR_PINNED, &deploymentpb.Deployment{
SeriesName: seriesName,
BuildId: buildID,
})
if open {
statusFilter = "= 'Running'"
} else {
Expand Down

0 comments on commit 6de1893

Please sign in to comment.