Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions controller/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go_library(
srcs = [
"controller.go",
"distance_filter.go",
"errors.go",
"getchangedtargetgraph.go",
"getchangedtargets.go",
"gettargetgraph.go",
Expand Down Expand Up @@ -48,7 +47,6 @@ go_test(
"metrics_test.go",
"output_filter_test.go",
"testhelper_test.go",
"wireerror_test.go",
],
embed = [":controller"],
deps = [
Expand All @@ -66,8 +64,6 @@ go_test(
"@com_github_stretchr_testify//require",
"@com_github_uber_go_tally//:tally",
"@org_uber_go_mock//gomock",
"@org_uber_go_yarpc//encoding/protobuf",
"@org_uber_go_yarpc//yarpcerrors",
"@org_uber_go_zap//:zap",
"@org_uber_go_zap//zaptest",
],
Expand Down
4 changes: 0 additions & 4 deletions controller/getchangedtargets.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ func (c *controller) GetChangedTargets(request *pb.GetChangedTargetsRequest, str
)
defer func() {
op.Complete(retErr)
if retErr != nil {
logger.Error("GetChangedTargets failed", tangoerrors.Fields(retErr)...)
retErr = toWireError(retErr)
}
}()
if repositoryErr != nil {
return repositoryErr
Expand Down
4 changes: 0 additions & 4 deletions controller/gettargetgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ func (c *controller) GetTargetGraph(request *pb.GetTargetGraphRequest, stream pb
)
defer func() {
op.Complete(retErr)
if retErr != nil {
logger.Error("GetTargetGraph failed", tangoerrors.Fields(retErr)...)
retErr = toWireError(retErr)
}
}()
start := time.Now()
ctx, cancelLink := c.linkRequestCtx(stream.Context())
Expand Down
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func run() error {
GraphConfig: cfg,
})

h := handler.New(handler.Params{Controller: ctrl})
h := handler.New(handler.Params{Logger: logger, Controller: ctrl})

// YARPC transports and dispatcher
grpcTransport := yarpcgrpc.NewTransport()
Expand Down
15 changes: 15 additions & 0 deletions handler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "handler",
srcs = [
"errors.go",
"getchangedtargetgraph.go",
"getchangedtargets.go",
"gettargetgraph.go",
Expand All @@ -12,7 +13,10 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//controller",
"//core/errors",
"//mapper/proto",
"//tangopb",
"@org_uber_go_zap//:zap",
],
)

Expand All @@ -22,13 +26,24 @@ go_test(
"getchangedtargetgraph_test.go",
"getchangedtargets_test.go",
"gettargetgraph_test.go",
"testhelper_test.go",
"wireerror_test.go",
],
embed = [":handler"],
deps = [
"//config",
"//controller",
"//controller/controllermock",
"//core/errors",
"//core/storage",
"//core/storage/storagemock",
"//tangopb",
"//tangopb/tangopbmock",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@org_uber_go_mock//gomock",
"@org_uber_go_yarpc//encoding/protobuf",
"@org_uber_go_yarpc//yarpcerrors",
"@org_uber_go_zap//zaptest",
],
)
2 changes: 1 addition & 1 deletion controller/errors.go → handler/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package controller
package handler

import (
"github.com/uber/tango/mapper/proto"
Expand Down
9 changes: 8 additions & 1 deletion handler/getchangedtargets.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
package handler

import (
tangoerrors "github.com/uber/tango/core/errors"
pb "github.com/uber/tango/tangopb"
)

func (h *handler) GetChangedTargets(request *pb.GetChangedTargetsRequest, stream pb.TangoServiceGetChangedTargetsYARPCServer) error {
func (h *handler) GetChangedTargets(request *pb.GetChangedTargetsRequest, stream pb.TangoServiceGetChangedTargetsYARPCServer) (retErr error) {
defer func() {
if retErr != nil {
h.logger.Error("GetChangedTargets failed", tangoerrors.Fields(retErr)...)
retErr = toWireError(retErr)
}
}()
return h.controller.GetChangedTargets(request, stream)
}
3 changes: 2 additions & 1 deletion handler/getchangedtargets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
mock_controller "github.com/uber/tango/controller/controllermock"
pb "github.com/uber/tango/tangopb"
"go.uber.org/mock/gomock"
"go.uber.org/zap/zaptest"
)

type fakeGetChangedTargetsStream struct {
Expand All @@ -30,7 +31,7 @@ type fakeGetChangedTargetsStream struct {

func TestGetChangedTargetsForwardsToController(t *testing.T) {
ctrl := mock_controller.NewMockController(gomock.NewController(t))
h := New(Params{Controller: ctrl})
h := New(Params{Logger: zaptest.NewLogger(t), Controller: ctrl})

req := &pb.GetChangedTargetsRequest{}
stream := &fakeGetChangedTargetsStream{}
Expand Down
9 changes: 8 additions & 1 deletion handler/gettargetgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
package handler

import (
tangoerrors "github.com/uber/tango/core/errors"
pb "github.com/uber/tango/tangopb"
)

func (h *handler) GetTargetGraph(request *pb.GetTargetGraphRequest, stream pb.TangoServiceGetTargetGraphYARPCServer) error {
func (h *handler) GetTargetGraph(request *pb.GetTargetGraphRequest, stream pb.TangoServiceGetTargetGraphYARPCServer) (retErr error) {
defer func() {
if retErr != nil {
h.logger.Error("GetTargetGraph failed", tangoerrors.Fields(retErr)...)
retErr = toWireError(retErr)
}
}()
return h.controller.GetTargetGraph(request, stream)
}
3 changes: 2 additions & 1 deletion handler/gettargetgraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
mock_controller "github.com/uber/tango/controller/controllermock"
pb "github.com/uber/tango/tangopb"
"go.uber.org/mock/gomock"
"go.uber.org/zap/zaptest"
)

type fakeGetTargetGraphStream struct {
Expand All @@ -30,7 +31,7 @@ type fakeGetTargetGraphStream struct {

func TestGetTargetGraphForwardsToController(t *testing.T) {
ctrl := mock_controller.NewMockController(gomock.NewController(t))
h := New(Params{Controller: ctrl})
h := New(Params{Logger: zaptest.NewLogger(t), Controller: ctrl})

req := &pb.GetTargetGraphRequest{}
stream := &fakeGetTargetGraphStream{}
Expand Down
5 changes: 4 additions & 1 deletion handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ package handler
import (
"github.com/uber/tango/controller"
pb "github.com/uber/tango/tangopb"
"go.uber.org/zap"
)

type Params struct {
Logger *zap.Logger
Controller controller.Controller
}

type handler struct {
logger *zap.Logger
controller controller.Controller
}

func New(p Params) pb.TangoYARPCServer {
return &handler{controller: p.Controller}
return &handler{logger: p.Logger, controller: p.Controller}
}
28 changes: 28 additions & 0 deletions handler/testhelper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2026 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package handler

import "github.com/uber/tango/config"

// allowAnyRepositoryConfigProvider resolves every remote to a fixed
// repository, mirroring the stub of the same name in controller's tests.
type allowAnyRepositoryConfigProvider struct{}

func (allowAnyRepositoryConfigProvider) GetRepositoryConfig(remote string) (config.RepositoryConfig, bool) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied from controller/testhelper_test.go but controller version is still needed until handler is fully implemented.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export it? it already depends on controller

return config.RepositoryConfig{
Remote: remote,
RepositoryID: "test-repository",
}, true
}
15 changes: 8 additions & 7 deletions controller/wireerror_test.go → handler/wireerror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package controller
package handler

import (
"context"
Expand All @@ -21,6 +21,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/uber/tango/controller"
tangoerrors "github.com/uber/tango/core/errors"
"github.com/uber/tango/core/storage"
storagemock "github.com/uber/tango/core/storage/storagemock"
Expand Down Expand Up @@ -88,10 +89,10 @@ func TestGetTargetGraph_ValidationError_WiresTangoError(t *testing.T) {
stream := tangomock.NewMockTangoServiceGetTargetGraphYARPCServer(ctrl)
stream.EXPECT().Context().Return(context.Background())

c := NewController(context.Background(), Params{
c := New(Params{Logger: zaptest.NewLogger(t), Controller: controller.NewController(context.Background(), controller.Params{
RepoConfig: allowAnyRepositoryConfigProvider{},
Logger: zaptest.NewLogger(t),
})
})})

// Missing BaseSha triggers a validation error classified as ERROR_USER.
err := c.GetTargetGraph(&pb.GetTargetGraphRequest{
Expand All @@ -117,10 +118,10 @@ func TestGetChangedTargets_ValidationError_WiresTangoError(t *testing.T) {
stream := tangomock.NewMockTangoServiceGetChangedTargetsYARPCServer(ctrl)
stream.EXPECT().Context().Return(context.Background()).AnyTimes()

c := NewController(context.Background(), Params{
c := New(Params{Logger: zaptest.NewLogger(t), Controller: controller.NewController(context.Background(), controller.Params{
RepoConfig: allowAnyRepositoryConfigProvider{},
Logger: zaptest.NewLogger(t),
})
})})

// Missing first revision triggers validation error classified as ERROR_USER.
err := c.GetChangedTargets(&pb.GetChangedTargetsRequest{
Expand All @@ -146,11 +147,11 @@ func TestGetTargetGraph_InfraError_WiresTangoError(t *testing.T) {
store := storagemock.NewMockStorage(ctrl)
store.EXPECT().Get(gomock.Any(), gomock.Any()).Return(storage.DownloadResponse{}, errors.New("disk on fire"))

c := NewController(context.Background(), Params{
c := New(Params{Logger: zaptest.NewLogger(t), Controller: controller.NewController(context.Background(), controller.Params{
RepoConfig: allowAnyRepositoryConfigProvider{},
Logger: zaptest.NewLogger(t),
Storage: store,
})
})})

err := c.GetTargetGraph(&pb.GetTargetGraphRequest{
BuildDescription: &pb.BuildDescription{
Expand Down
2 changes: 1 addition & 1 deletion integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func startServerWithLogger(t testing.TB, remote string, zl *zap.Logger) string {
GraphConfig: cfg,
})

h := handler.New(handler.Params{Controller: ctrl})
h := handler.New(handler.Params{Logger: zl, Controller: ctrl})

grpcTransport := yarpcgrpc.NewTransport()
listener, err := net.Listen("tcp", "127.0.0.1:0")
Expand Down
Loading