Skip to content

Commit

Permalink
Fix register search attributes when starting server
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigozhou committed Sep 26, 2024
1 parent e398811 commit 171be43
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 57 deletions.
13 changes: 6 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/temporalio/cli

go 1.22.3
go 1.22.6

require (
github.com/alitto/pond v1.9.1
Expand All @@ -15,10 +15,10 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
github.com/temporalio/ui-server/v2 v2.30.3
go.temporal.io/api v1.38.0
go.temporal.io/api v1.39.0
go.temporal.io/sdk v1.29.0
go.temporal.io/server v1.25.0
google.golang.org/grpc v1.65.0
go.temporal.io/server v1.26.0-120.0.20240904002151-40431ec95546
google.golang.org/grpc v1.66.0
google.golang.org/protobuf v1.34.2
gopkg.in/yaml.v3 v3.0.1
)
Expand Down Expand Up @@ -81,7 +81,6 @@ require (
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/nexus-rpc/sdk-go v0.0.10 // indirect
github.com/olivere/elastic/v7 v7.0.32 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pborman/uuid v1.2.1 // indirect
Expand Down Expand Up @@ -136,8 +135,8 @@ require (
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.182.0 // indirect
google.golang.org/genproto v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed // indirect
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5
go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4=
go.opentelemetry.io/proto/otlp v1.2.0 h1:pVeZGk7nXDC9O2hncA6nHldxEjm6LByfA2aN8IOkz94=
go.opentelemetry.io/proto/otlp v1.2.0/go.mod h1:gGpR8txAl5M03pDhMC79G6SdqNV26naRm/KDsgaHD8A=
go.temporal.io/api v1.38.0 h1:L5i+Ai7UoBa2Gq/goVHLY32064AgawxPDLkKm4I7fu4=
go.temporal.io/api v1.38.0/go.mod h1:fmh06EjstyrPp6SHbjJo7yYHBfHamPE4SytM+2NRejc=
go.temporal.io/api v1.39.0 h1:pbhcfvNDB7mllb8lIBqPcg+m6LMG/IhTpdiFxe+0mYk=
go.temporal.io/api v1.39.0/go.mod h1:1WwYUMo6lao8yl0371xWUm13paHExN5ATYT/B7QtFis=
go.temporal.io/sdk v1.29.0 h1:AHObeNFFxVlnaj7jql3Bjd4B0bMBaXkywJU0uVIPgJo=
go.temporal.io/sdk v1.29.0/go.mod h1:kp//DRvn3CqQVBCtjL51Oicp9wrZYB2s6row1UgzcKQ=
go.temporal.io/server v1.25.0 h1:HwP7musDblTbobv8727t5riWB5T1UKqUZBLmIrWFwF8=
go.temporal.io/server v1.25.0/go.mod h1:+8eYt3bSdHzPDMyEW3RgtsbAJRblhUEH0PVRSPiMyUs=
go.temporal.io/server v1.26.0-120.0.20240904002151-40431ec95546 h1:5cJSjEjVVHyM7Yuh7kH92Mtsx+0Eme6s74fYVU6jhQg=
go.temporal.io/server v1.26.0-120.0.20240904002151-40431ec95546/go.mod h1:u1mM4Fichm3r9/u4kvYQCAqtIplJnhJ+tdxeOubPBxI=
go.temporal.io/version v0.3.0 h1:dMrei9l9NyHt8nG6EB8vAwDLLTwx2SvRyucCSumAiig=
go.temporal.io/version v0.3.0/go.mod h1:UA9S8/1LaKYae6TyD9NaPMJTZb911JcbqghI2CBSP78=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
Expand Down Expand Up @@ -527,18 +527,18 @@ google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfG
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20240528184218-531527333157 h1:u7WMYrIrVvs0TF5yaKwKNbcJyySYf+HAIFXxWltJOXE=
google.golang.org/genproto v0.0.0-20240528184218-531527333157/go.mod h1:ubQlAQnzejB8uZzszhrTCU2Fyp6Vi7ZE5nn0c3W8+qQ=
google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd h1:BBOTEWLuuEGQy9n1y9MhVJ9Qt0BDu21X8qZs71/uPZo=
google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd/go.mod h1:fO8wJzT2zbQbAjbIoos1285VfEIYKDDY+Dt+WpTkh6g=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd h1:6TEm2ZxXoQmFWFlt1vNxvVOa1Q0dXFQD1m/rYjXmS0E=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed h1:3RgNmBoI9MZhsj3QxC+AP/qQhNwpCLOvYDYYsFrhFt0=
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed/go.mod h1:OCdP9MfskevB/rbYvHTsXTtKC+3bHWajPdoKgjcYkfo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed h1:J6izYgfBXAI3xTKLgxzTmUltdYaLsuBxFCgDHWJ/eXg=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c=
google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
40 changes: 1 addition & 39 deletions temporalcli/commands.server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import (
"github.com/google/uuid"
"github.com/temporalio/cli/temporalcli/devserver"
"go.temporal.io/api/enums/v1"
"go.temporal.io/api/operatorservice/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

var defaultDynamicConfigValues = map[string]any{
Expand Down Expand Up @@ -121,6 +118,7 @@ func (t *TemporalServerStartDevCommand) run(cctx *CommandContext, args []string)
if err != nil {
return err
}
opts.SearchAttributes = searchAttrs

// If not using DB file, set persistent cluster ID
if t.DbFilename == "" {
Expand Down Expand Up @@ -149,11 +147,6 @@ func (t *TemporalServerStartDevCommand) run(cctx *CommandContext, args []string)
}
defer s.Stop()

// Register search attributes
if err := t.registerSearchAttributes(cctx, searchAttrs, opts.Namespaces); err != nil {
return err
}

cctx.Printer.Printlnf("CLI %v\n", VersionString())
cctx.Printer.Printlnf("%-8s %v:%v", "Server:", toFriendlyIp(opts.FrontendIP), opts.FrontendPort)
if !t.Headless {
Expand Down Expand Up @@ -214,34 +207,3 @@ func (t *TemporalServerStartDevCommand) prepareSearchAttributes() (map[string]en
}
return attrs, nil
}

func (t *TemporalServerStartDevCommand) registerSearchAttributes(
cctx *CommandContext,
attrs map[string]enums.IndexedValueType,
namespaces []string,
) error {
if len(attrs) == 0 {
return nil
}

conn, err := grpc.NewClient(
fmt.Sprintf("%v:%v", t.Ip, t.Port),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
return fmt.Errorf("failed creating client to register search attributes: %w", err)
}
defer conn.Close()
client := operatorservice.NewOperatorServiceClient(conn)
// Call for each namespace
for _, ns := range namespaces {
_, err := client.AddSearchAttributes(cctx, &operatorservice.AddSearchAttributesRequest{
Namespace: ns,
SearchAttributes: attrs,
})
if err != nil {
return fmt.Errorf("failed registering search attributes: %w", err)
}
}
return nil
}
8 changes: 7 additions & 1 deletion temporalcli/devserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
uiserver "github.com/temporalio/ui-server/v2/server"
uiconfig "github.com/temporalio/ui-server/v2/server/config"
uiserveroptions "github.com/temporalio/ui-server/v2/server/server_options"
"go.temporal.io/api/enums/v1"
"go.temporal.io/server/common/authorization"
"go.temporal.io/server/common/cluster"
"go.temporal.io/server/common/config"
Expand Down Expand Up @@ -84,6 +85,7 @@ type StartOptions struct {
FrontendHTTPPort int
EnableGlobalNamespace bool
DynamicConfigValues map[string]any
SearchAttributes map[string]enums.IndexedValueType
LogConfig func([]byte)
GRPCInterceptors []grpc.UnaryServerInterceptor
}
Expand Down Expand Up @@ -346,7 +348,11 @@ func (s *StartOptions) buildSQLConfig() (*config.SQL, error) {
// Create namespaces
namespaces := make([]*sqliteschema.NamespaceConfig, len(s.Namespaces))
for i, ns := range s.Namespaces {
namespaces[i] = sqlite.NewNamespaceConfig(s.CurrentClusterName, ns, false)
nsConfig, err := sqlite.NewNamespaceConfig(s.CurrentClusterName, ns, false, s.SearchAttributes)
if err != nil {
return nil, fmt.Errorf("failed creating namespace config: %w", err)
}
namespaces[i] = nsConfig
}
if err := sqliteschema.CreateNamespaces(&conf, namespaces...); err != nil {
return nil, fmt.Errorf("failed creating namespaces: %w", err)
Expand Down

0 comments on commit 171be43

Please sign in to comment.