Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize config manager packages in agent #1198

Merged
merged 3 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package httpserver
package tchannel
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a big fan of the new package structure: without looking at the code, I would expect that the packages cmd/agent/app/httpserver/[tchannel|grpc] would contain code that ties something about gRPC or TChannel with the HTTP server that the agent starts, when in reality, all these packages have are specific implementations of the ClientConfigManager interface.

Perhaps the managers deserve their own packages? cmd/agent/app/clientconfigmanager/[tchannel|grpc]? Perhaps they should even be outside of the cmd package.

Copy link
Member Author

Choose a reason for hiding this comment

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

The manager interface is used only in httpserver package Therefore it was originally colocated there I am fine scoping it under httpserver.

Perhaps they should even be outside of the cmd package.

This applies also to reporter and probably other subpackages. It would make sense to move them if they could be reused in other cmd. This is specific to the agent only.


import (
"time"

"github.com/uber/tchannel-go"
"github.com/uber/tchannel-go/thrift"

"github.com/jaegertracing/jaeger/cmd/agent/app/httpserver"
"github.com/jaegertracing/jaeger/thrift-gen/baggage"
"github.com/jaegertracing/jaeger/thrift-gen/sampling"
)
Expand All @@ -30,7 +31,7 @@ type collectorProxy struct {
}

// NewCollectorProxy implements Manager by proxying the requests to collector.
func NewCollectorProxy(svc string, channel *tchannel.Channel) ClientConfigManager {
func NewCollectorProxy(svc string, channel *tchannel.Channel) httpserver.ClientConfigManager {
thriftClient := thrift.NewClient(channel, svc, nil)
res := &collectorProxy{
samplingClient: sampling.NewTChanSamplingManagerClient(thriftClient),
Expand Down
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 httpserver
package tchannel

import (
"errors"
Expand Down
3 changes: 2 additions & 1 deletion cmd/agent/app/reporter/grpc/collector_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"google.golang.org/grpc/resolver/manual"

"github.com/jaegertracing/jaeger/cmd/agent/app/httpserver"
mGrpc "github.com/jaegertracing/jaeger/cmd/agent/app/httpserver/grpc"
pavolloffay marked this conversation as resolved.
Show resolved Hide resolved
aReporter "github.com/jaegertracing/jaeger/cmd/agent/app/reporter"
)

Expand Down Expand Up @@ -57,7 +58,7 @@ func NewCollectorProxy(o *Options, mFactory metrics.Factory, logger *zap.Logger)
return &ProxyBuilder{
conn: conn,
reporter: aReporter.WrapWithMetrics(NewReporter(conn, logger), grpcMetrics),
manager: httpserver.WrapWithMetrics(NewSamplingManager(conn), grpcMetrics)}, nil
manager: httpserver.WrapWithMetrics(mGrpc.NewSamplingManager(conn), grpcMetrics)}, nil
}

// GetReporter returns Reporter
Expand Down
13 changes: 13 additions & 0 deletions cmd/agent/app/reporter/grpc/collector_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package grpc

import (
"net"
"testing"
"time"

Expand Down Expand Up @@ -80,3 +81,15 @@ func TestMultipleCollectors(t *testing.T) {
assert.Equal(t, true, bothServers)
require.Nil(t, proxy.Close())
}

func initializeGRPCTestServer(t *testing.T, beforeServe func(server *grpc.Server)) (*grpc.Server, net.Addr) {
server := grpc.NewServer()
lis, err := net.Listen("tcp", "localhost:0")
require.NoError(t, err)
beforeServe(server)
go func() {
err := server.Serve(lis)
pavolloffay marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)
}()
return server, lis.Addr()
}
3 changes: 2 additions & 1 deletion cmd/agent/app/reporter/tchannel/collector_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/agent/app/httpserver"
"github.com/jaegertracing/jaeger/cmd/agent/app/httpserver/tchannel"
"github.com/jaegertracing/jaeger/cmd/agent/app/reporter"
)

Expand All @@ -39,7 +40,7 @@ func NewCollectorProxy(builder *Builder, mFactory metrics.Factory, logger *zap.L
return &ProxyBuilder{
tchanRep: r,
reporter: reporter.WrapWithMetrics(r, tchannelMetrics),
manager: httpserver.WrapWithMetrics(httpserver.NewCollectorProxy(r.CollectorServiceName(), r.Channel()), tchannelMetrics),
manager: httpserver.WrapWithMetrics(tchannel.NewCollectorProxy(r.CollectorServiceName(), r.Channel()), tchannelMetrics),
}, nil
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/agent/app/reporter/tchannel/collector_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/agent/app/httpserver"
"github.com/jaegertracing/jaeger/cmd/agent/app/httpserver/tchannel"
"github.com/jaegertracing/jaeger/cmd/agent/app/reporter"
)

Expand All @@ -42,7 +43,7 @@ func TestCreate(t *testing.T) {
assert.NotNil(t, b)
r, _ := cfg.CreateReporter(logger)
assert.Equal(t, reporter.WrapWithMetrics(r, mFactory), b.GetReporter())
m := httpserver.NewCollectorProxy(r.CollectorServiceName(), r.Channel())
m := tchannel.NewCollectorProxy(r.CollectorServiceName(), r.Channel())
assert.Equal(t, httpserver.WrapWithMetrics(m, mFactory), b.GetManager())
assert.Nil(t, b.Close())
}