http-api: Register OperatorService (#5452)

## What changed?

I registered the operatorservice with our HTTP API

## Why?

Turns out we didn't actually host this, so calls to ListSearchAttributes
would 404

## How did you test it?
I added a new test to our HTTP API tests

## Potential risks
None

## Is hotfix candidate?
No
This commit is contained in:
Tim Deeb-Swihart
2024-02-26 14:49:06 -08:00
committed by GitHub
parent 4c940aa7ed
commit a59a46cccf
5 changed files with 66 additions and 2 deletions

View File

@@ -637,6 +637,7 @@ func HTTPAPIServerProvider(
grpcListener net.Listener,
tlsConfigProvider encryption.TLSConfigProvider,
handler Handler,
operatorHandler *OperatorHandlerImpl,
grpcServerOptions GrpcServerOptions,
metricsHandler metrics.Handler,
namespaceRegistry namespace.Registry,
@@ -657,6 +658,7 @@ func HTTPAPIServerProvider(
grpcListener,
tlsConfigProvider,
handler,
operatorHandler,
grpcServerOptions.UnaryInterceptors,
metricsHandler,
namespaceRegistry,

View File

@@ -43,6 +43,7 @@ import (
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"go.temporal.io/api/operatorservice/v1"
"go.temporal.io/api/serviceerror"
"go.temporal.io/api/workflowservice/v1"
"go.temporal.io/server/common/config"
@@ -88,6 +89,7 @@ func NewHTTPAPIServer(
grpcListener net.Listener,
tlsConfigProvider encryption.TLSConfigProvider,
handler Handler,
operatorHandler *OperatorHandlerImpl,
interceptors []grpc.UnaryServerInterceptor,
metricsHandler metrics.Handler,
namespaceRegistry namespace.Registry,
@@ -151,7 +153,10 @@ func NewHTTPAPIServer(
// Create inline client connection
clientConn := newInlineClientConn(
map[string]any{"temporal.api.workflowservice.v1.WorkflowService": handler},
map[string]any{
"temporal.api.workflowservice.v1.WorkflowService": handler,
"temporal.api.operatorservice.v1.OperatorService": operatorHandler,
},
interceptors,
metricsHandler,
namespaceRegistry,
@@ -159,14 +164,25 @@ func NewHTTPAPIServer(
// Create serve mux
h.serveMux = runtime.NewServeMux(opts...)
err = workflowservice.RegisterWorkflowServiceHandlerClient(
context.Background(),
h.serveMux,
workflowservice.NewWorkflowServiceClient(clientConn),
)
if err != nil {
return nil, fmt.Errorf("failed registering HTTP API handler: %w", err)
return nil, fmt.Errorf("failed registering workflowservice HTTP API handler: %w", err)
}
err = operatorservice.RegisterOperatorServiceHandlerClient(
context.Background(),
h.serveMux,
operatorservice.NewOperatorServiceClient(clientConn),
)
if err != nil {
return nil, fmt.Errorf("failed registering operatorservice HTTP API handler: %w", err)
}
// Set the handler as our function that wraps serve mux
h.server.Handler = http.HandlerFunc(h.serveHTTP)

View File

@@ -49,5 +49,7 @@ type (
// OperatorHandler is interface wrapping frontend workflow handler
OperatorHandler interface {
operatorservice.OperatorServiceServer
Start()
Stop()
}
)

View File

@@ -1198,6 +1198,30 @@ func (mr *MockOperatorHandlerMockRecorder) RemoveSearchAttributes(arg0, arg1 int
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveSearchAttributes", reflect.TypeOf((*MockOperatorHandler)(nil).RemoveSearchAttributes), arg0, arg1)
}
// Start mocks base method.
func (m *MockOperatorHandler) Start() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Start")
}
// Start indicates an expected call of Start.
func (mr *MockOperatorHandlerMockRecorder) Start() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockOperatorHandler)(nil).Start))
}
// Stop mocks base method.
func (m *MockOperatorHandler) Stop() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Stop")
}
// Stop indicates an expected call of Stop.
func (mr *MockOperatorHandlerMockRecorder) Stop() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockOperatorHandler)(nil).Stop))
}
// mustEmbedUnimplementedOperatorServiceServer mocks base method.
func (m *MockOperatorHandler) mustEmbedUnimplementedOperatorServiceServer() {
m.ctrl.T.Helper()

View File

@@ -393,3 +393,23 @@ func (s *ClientFunctionalSuite) httpRequest(expectedStatus int, req *http.Reques
s.Require().Equal(expectedStatus, resp.StatusCode, "Bad status, body: %s", body)
return resp, body
}
func (s *ClientFunctionalSuite) TestHTTPAPI_OperatorService_ListSearchAttributes() {
_, respBody := s.httpGet(
http.StatusOK,
"/api/v1/namespaces/"+s.namespace+"/search-attributes",
"application/json",
)
s.T().Log(string(respBody))
var searchAttrsResp struct {
CustomAttributes map[string]string `json:"customAttributes"`
SystemAttributes map[string]string `json:"systemAttributes"`
StorageSchema map[string]string `json:"storageSchema"`
}
s.Require().NoError(json.Unmarshal(respBody, &searchAttrsResp))
// We don't allow for creating search attributes from the HTTP API yet, so
// we just check that a few defaults exist. We don't want to check for all
// of them as that's brittle and will break the tests if we ever add a new type
s.Require().Contains(searchAttrsResp.CustomAttributes, "CustomIntField")
s.Require().Equal(searchAttrsResp.CustomAttributes["CustomIntField"], "INDEXED_VALUE_TYPE_INT")
}