Skip to content

Commit

Permalink
Fill in namespace capabilities in describe response (#6256)
Browse files Browse the repository at this point in the history
## Why?

We added the field in the protos and never filled this in.

## How did you test it?

Unit test.
  • Loading branch information
bergundy authored Sep 5, 2024
1 parent 3c064b8 commit 18411e9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 16 deletions.
19 changes: 10 additions & 9 deletions service/frontend/namespace_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
"go.temporal.io/server/common/archiver/provider"
"go.temporal.io/server/common/clock"
"go.temporal.io/server/common/cluster"
"go.temporal.io/server/common/dynamicconfig"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/log/tag"
"go.temporal.io/server/common/namespace"
Expand All @@ -59,16 +58,15 @@ type (
// namespaceHandler implements the namespace-related APIs specified by the [workflowservice] package,
// such as registering, updating, and querying namespaces.
namespaceHandler struct {
maxBadBinaryCount dynamicconfig.IntPropertyFnWithNamespaceFilter
logger log.Logger
metadataMgr persistence.MetadataManager
clusterMetadata cluster.Metadata
namespaceReplicator namespace.Replicator
namespaceAttrValidator *namespace.AttrValidatorImpl
archivalMetadata archiver.ArchivalMetadata
archiverProvider provider.ArchiverProvider
supportsSchedules dynamicconfig.BoolPropertyFnWithNamespaceFilter
timeSource clock.TimeSource
config *Config
}
)

Expand All @@ -88,27 +86,25 @@ var (

// newNamespaceHandler create a new namespace handler
func newNamespaceHandler(
maxBadBinaryCount dynamicconfig.IntPropertyFnWithNamespaceFilter,
logger log.Logger,
metadataMgr persistence.MetadataManager,
clusterMetadata cluster.Metadata,
namespaceReplicator namespace.Replicator,
archivalMetadata archiver.ArchivalMetadata,
archiverProvider provider.ArchiverProvider,
supportsSchedules dynamicconfig.BoolPropertyFnWithNamespaceFilter,
timeSource clock.TimeSource,
config *Config,
) *namespaceHandler {
return &namespaceHandler{
maxBadBinaryCount: maxBadBinaryCount,
logger: logger,
metadataMgr: metadataMgr,
clusterMetadata: clusterMetadata,
namespaceReplicator: namespaceReplicator,
namespaceAttrValidator: namespace.NewAttrValidator(clusterMetadata),
archivalMetadata: archivalMetadata,
archiverProvider: archiverProvider,
supportsSchedules: supportsSchedules,
timeSource: timeSource,
config: config,
}
}

Expand Down Expand Up @@ -485,7 +481,7 @@ func (d *namespaceHandler) UpdateNamespace(
config.VisibilityArchivalUri = nextVisibilityArchivalState.URI
}
if updatedConfig.BadBinaries != nil {
maxLength := d.maxBadBinaryCount(updateRequest.GetNamespace())
maxLength := d.config.MaxBadBinaries(updateRequest.GetNamespace())
// only do merging
bb := d.mergeBadBinaries(config.BadBinaries.Binaries, updatedConfig.BadBinaries.Binaries, time.Now().UTC())
config.BadBinaries = &bb
Expand Down Expand Up @@ -699,7 +695,12 @@ func (d *namespaceHandler) createResponse(
Data: info.Data,
Id: info.Id,

SupportsSchedules: d.supportsSchedules(info.Name),
Capabilities: &namespacepb.NamespaceInfo_Capabilities{
EagerWorkflowStart: d.config.EnableEagerWorkflowStart(info.Name),
SyncUpdate: d.config.EnableUpdateWorkflowExecution(info.Name),
AsyncUpdate: d.config.EnableUpdateWorkflowExecutionAsyncAccepted(info.Name),
},
SupportsSchedules: d.config.EnableSchedules(info.Name),
}

configResult := &namespacepb.NamespaceConfig{
Expand Down
45 changes: 42 additions & 3 deletions service/frontend/namespace_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package frontend
import (
"context"
"slices"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -69,6 +68,7 @@ type (
archivalMetadata archiver.ArchivalMetadata
mockArchiverProvider *provider.MockArchiverProvider
fakeClock *clock.EventTimeSource
config *Config

handler *namespaceHandler
}
Expand Down Expand Up @@ -106,16 +106,16 @@ func (s *namespaceHandlerCommonSuite) SetupTest() {
)
s.mockArchiverProvider = provider.NewMockArchiverProvider(s.controller)
s.fakeClock = clock.NewEventTimeSource()
s.config = NewConfig(dc.NewNoopCollection(), 1024)
s.handler = newNamespaceHandler(
dc.GetIntPropertyFnFilteredByNamespace(s.maxBadBinaryCount),
logger,
s.mockMetadataMgr,
s.mockClusterMetadata,
s.mockNamespaceReplicator,
s.archivalMetadata,
s.mockArchiverProvider,
func(s string) bool { return strings.HasSuffix(s, "sched") },
s.fakeClock,
s.config,
)
}

Expand Down Expand Up @@ -381,6 +381,45 @@ func (s *namespaceHandlerCommonSuite) TestListNamespace() {
}
}

func (s *namespaceHandlerCommonSuite) TestCapabilities() {
s.mockMetadataMgr.EXPECT().GetNamespace(gomock.Any(), &persistence.GetNamespaceRequest{
Name: "ns",
}).Return(
&persistence.GetNamespaceResponse{
Namespace: &persistencespb.NamespaceDetail{
Info: &persistencespb.NamespaceInfo{
Id: "id",
},
Config: &persistencespb.NamespaceConfig{},
ReplicationConfig: &persistencespb.NamespaceReplicationConfig{},
},
}, nil,
).AnyTimes()

// First call: dynamic configs disabled.
resp, err := s.handler.DescribeNamespace(context.Background(), &workflowservice.DescribeNamespaceRequest{
Namespace: "ns",
})
s.NoError(err)

s.False(resp.NamespaceInfo.Capabilities.EagerWorkflowStart)
s.True(resp.NamespaceInfo.Capabilities.SyncUpdate)
s.True(resp.NamespaceInfo.Capabilities.AsyncUpdate)

s.config.EnableEagerWorkflowStart = dc.GetBoolPropertyFnFilteredByNamespace(true)
s.config.EnableUpdateWorkflowExecution = dc.GetBoolPropertyFnFilteredByNamespace(false)
s.config.EnableUpdateWorkflowExecutionAsyncAccepted = dc.GetBoolPropertyFnFilteredByNamespace(false)

// Second call: dynamic configs enabled.
resp, err = s.handler.DescribeNamespace(context.Background(), &workflowservice.DescribeNamespaceRequest{
Namespace: "ns",
})
s.NoError(err)
s.True(resp.NamespaceInfo.Capabilities.EagerWorkflowStart)
s.False(resp.NamespaceInfo.Capabilities.SyncUpdate)
s.False(resp.NamespaceInfo.Capabilities.AsyncUpdate)
}

func (s *namespaceHandlerCommonSuite) TestRegisterNamespace_WithOneCluster() {
const namespace = "namespace-to-register"
clusterName := "cluster1"
Expand Down
6 changes: 4 additions & 2 deletions service/frontend/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ type Config struct {
HistoryHostErrorPercentage dynamicconfig.FloatPropertyFn

LogAllReqErrors dynamicconfig.BoolPropertyFnWithNamespaceFilter

EnableEagerWorkflowStart dynamicconfig.BoolPropertyFnWithNamespaceFilter
}

// NewConfig returns new service config with default values
Expand Down Expand Up @@ -313,8 +315,8 @@ func NewConfig(
MaskInternalErrorDetails: dynamicconfig.FrontendMaskInternalErrorDetails.Get(dc),

HistoryHostErrorPercentage: dynamicconfig.HistoryHostErrorPercentage.Get(dc),

LogAllReqErrors: dynamicconfig.LogAllReqErrors.Get(dc),
LogAllReqErrors: dynamicconfig.LogAllReqErrors.Get(dc),
EnableEagerWorkflowStart: dynamicconfig.EnableEagerWorkflowStart.Get(dc),
}
}

Expand Down
3 changes: 1 addition & 2 deletions service/frontend/workflow_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,14 @@ func NewWorkflowHandler(
tokenSerializer: common.NewProtoTaskTokenSerializer(),
versionChecker: headers.NewDefaultVersionChecker(),
namespaceHandler: newNamespaceHandler(
config.MaxBadBinaries,
logger,
persistenceMetadataManager,
clusterMetadata,
namespace.NewNamespaceReplicator(namespaceReplicationQueue, logger),
archivalMetadata,
archiverProvider,
config.EnableSchedules,
timeSource,
config,
),
getDefaultWorkflowRetrySettings: config.DefaultWorkflowRetryPolicy,
visibilityMgr: visibilityMgr,
Expand Down

0 comments on commit 18411e9

Please sign in to comment.