Skip to content

Commit

Permalink
Make listener and metrics ports configurable (#1647)
Browse files Browse the repository at this point in the history
  • Loading branch information
jannfis authored and alexec committed May 28, 2019
1 parent 4c41f82 commit 9f9a076
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 15 deletions.
5 changes: 4 additions & 1 deletion cmd/argocd-application-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func newCommand() *cobra.Command {
operationProcessors int
logLevel string
glogLevel int
metricsPort int
cacheSrc func() (*cache.Cache, error)
)
var command = cobra.Command{
Expand Down Expand Up @@ -81,7 +82,8 @@ func newCommand() *cobra.Command {
appClient,
repoClientset,
cache,
resyncDuration)
resyncDuration,
metricsPort)
errors.CheckError(err)

log.Infof("Application Controller (version: %s) starting (namespace: %s)", argocd.GetVersion(), namespace)
Expand All @@ -104,6 +106,7 @@ func newCommand() *cobra.Command {
command.Flags().IntVar(&operationProcessors, "operation-processors", 1, "Number of application operation processors")
command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error")
command.Flags().IntVar(&glogLevel, "gloglevel", 0, "Set the glog logging level")
command.Flags().IntVar(&metricsPort, "metrics-port", common.DefaultPortArgoCDMetrics, "Start metrics server on given port")
cacheSrc = cache.AddCacheFlagsToCmd(&command)
return &command
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/argocd-repo-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func newCommand() *cobra.Command {
var (
logLevel string
parallelismLimit int64
listenPort int
metricsPort int
cacheSrc func() (*cache.Cache, error)
tlsConfigCustomizerSrc func() (tls.ConfigCustomizer, error)
)
Expand All @@ -49,11 +51,11 @@ func newCommand() *cobra.Command {
server, err := reposerver.NewServer(git.NewFactory(), cache, tlsConfigCustomizer, parallelismLimit)
errors.CheckError(err)
grpc := server.CreateGRPC()
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", common.PortRepoServer))
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", listenPort))
errors.CheckError(err)

http.Handle("/metrics", promhttp.Handler())
go func() { errors.CheckError(http.ListenAndServe(fmt.Sprintf(":%d", common.PortRepoServerMetrics), nil)) }()
go func() { errors.CheckError(http.ListenAndServe(fmt.Sprintf(":%d", metricsPort), nil)) }()

log.Infof("argocd-repo-server %s serving on %s", argocd.GetVersion(), listener.Addr())
stats.RegisterStackDumper()
Expand All @@ -67,6 +69,8 @@ func newCommand() *cobra.Command {

command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error")
command.Flags().Int64Var(&parallelismLimit, "parallelismlimit", 0, "Limit on number of concurrent manifests generate requests. Any value less the 1 means no limit.")
command.Flags().IntVar(&listenPort, "port", common.DefaultPortRepoServer, "Listen on given port for incoming connections")
command.Flags().IntVar(&metricsPort, "metrics-port", common.DefaultPortRepoServerMetrics, "Start metrics server on given port")
tlsConfigCustomizerSrc = tls.AddTLSFlagsToCmd(&command)
cacheSrc = cache.AddCacheFlagsToCmd(&command)
return &command
Expand Down
8 changes: 7 additions & 1 deletion cmd/argocd-server/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
func NewCommand() *cobra.Command {
var (
insecure bool
listenPort int
metricsPort int
logLevel string
glogLevel int
clientConfig clientcmd.ClientConfig
Expand Down Expand Up @@ -61,6 +63,8 @@ func NewCommand() *cobra.Command {

argoCDOpts := server.ArgoCDServerOpts{
Insecure: insecure,
ListenPort: listenPort,
MetricsPort: metricsPort,
Namespace: namespace,
StaticAssetsDir: staticAssetsDir,
BaseHRef: baseHRef,
Expand All @@ -81,7 +85,7 @@ func NewCommand() *cobra.Command {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
argocd := server.NewServer(ctx, argoCDOpts)
argocd.Run(ctx, common.PortAPIServer)
argocd.Run(ctx, listenPort, metricsPort)
cancel()
}
},
Expand All @@ -97,6 +101,8 @@ func NewCommand() *cobra.Command {
command.Flags().StringVar(&dexServerAddress, "dex-server", common.DefaultDexServerAddr, "Dex server address")
command.Flags().BoolVar(&disableAuth, "disable-auth", false, "Disable client authentication")
command.AddCommand(cli.NewVersionCmd(cliName))
command.Flags().IntVar(&listenPort, "port", common.DefaultPortAPIServer, "Listen on given port")
command.Flags().IntVar(&metricsPort, "metrics-port", common.DefaultPortArgoCDAPIServerMetrics, "Start metrics on given port")
tlsConfigCustomizerSrc = tls.AddTLSFlagsToCmd(command)
cacheSrc = cache.AddCacheFlagsToCmd(command)
return command
Expand Down
11 changes: 6 additions & 5 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ const (
ArgoCDRBACConfigMapName = "argocd-rbac-cm"
)

// Default listener ports for ArgoCD components
const (
PortAPIServer = 8080
PortRepoServer = 8081
PortArgoCDMetrics = 8082
PortArgoCDAPIServerMetrics = 8083
PortRepoServerMetrics = 8084
DefaultPortAPIServer = 8080
DefaultPortRepoServer = 8081
DefaultPortArgoCDMetrics = 8082
DefaultPortArgoCDAPIServerMetrics = 8083
DefaultPortRepoServerMetrics = 8084
)

// Argo CD application related constants
Expand Down
3 changes: 2 additions & 1 deletion controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func NewApplicationController(
repoClientset reposerver.Clientset,
argoCache *argocache.Cache,
appResyncPeriod time.Duration,
metricsPort int,
) (*ApplicationController, error) {
db := db.NewDB(namespace, settingsMgr, kubeClientset)
settings, err := settingsMgr.GetSettings()
Expand All @@ -112,7 +113,7 @@ func NewApplicationController(
}
appInformer, appLister := ctrl.newApplicationInformerAndLister()
projInformer := v1alpha1.NewAppProjectInformer(applicationClientset, namespace, appResyncPeriod, cache.Indexers{})
metricsAddr := fmt.Sprintf("0.0.0.0:%d", common.PortArgoCDMetrics)
metricsAddr := fmt.Sprintf("0.0.0.0:%d", metricsPort)
ctrl.metricsServer = metrics.NewMetricsServer(metricsAddr, appLister)
stateCache := statecache.NewLiveStateCache(db, appInformer, ctrl.settings, kubectlCmd, ctrl.metricsServer, ctrl.handleAppUpdated)
appStateManager := NewAppStateManager(db, applicationClientset, repoClientset, namespace, kubectlCmd, ctrl.settings, stateCache, projInformer, ctrl.metricsServer)
Expand Down
1 change: 1 addition & 0 deletions controller/appcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func newFakeController(data *fakeData) *ApplicationController {
&mockRepoClientset,
utilcache.NewCache(utilcache.NewInMemoryCache(1*time.Hour)),
time.Minute,
common.DefaultPortArgoCDMetrics,
)
if err != nil {
panic(err)
Expand Down
10 changes: 6 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ type ArgoCDServer struct {
type ArgoCDServerOpts struct {
DisableAuth bool
Insecure bool
ListenPort int
MetricsPort int
Namespace string
DexServerAddr string
StaticAssetsDir string
Expand Down Expand Up @@ -189,7 +191,7 @@ func NewServer(ctx context.Context, opts ArgoCDServerOpts) *ArgoCDServer {
// We use k8s.io/code-generator/cmd/go-to-protobuf to generate the .proto files from the API types.
// k8s.io/ go-to-protobuf uses protoc-gen-gogo, which comes from gogo/protobuf (a fork of
// golang/protobuf).
func (a *ArgoCDServer) Run(ctx context.Context, port int) {
func (a *ArgoCDServer) Run(ctx context.Context, port int, metricsPort int) {
grpcS := a.newGRPCServer()
grpcWebS := grpcweb.WrapServer(grpcS)
var httpS *http.Server
Expand All @@ -200,7 +202,7 @@ func (a *ArgoCDServer) Run(ctx context.Context, port int) {
} else {
httpS = a.newHTTPServer(ctx, port, grpcWebS)
}
metricsServ := newAPIServerMetricsServer()
metricsServ := newAPIServerMetricsServer(metricsPort)

// Start listener
var conn net.Listener
Expand Down Expand Up @@ -618,11 +620,11 @@ func indexFilePath(srcPath string, baseHRef string) (string, error) {
}

// newAPIServerMetricsServer returns HTTP server which serves prometheus metrics on gRPC requests
func newAPIServerMetricsServer() *http.Server {
func newAPIServerMetricsServer(port int) *http.Server {
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
return &http.Server{
Addr: fmt.Sprintf("0.0.0.0:%d", common.PortArgoCDAPIServerMetrics),
Addr: fmt.Sprintf("0.0.0.0:%d", port),
Handler: mux,
}
}
Expand Down
4 changes: 3 additions & 1 deletion server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,11 @@ func TestUserAgent(t *testing.T) {
defer cancelInformer()
port, err := test.GetFreePort()
assert.NoError(t, err)
metricsPort, err := test.GetFreePort()
assert.NoError(t, err)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go s.Run(ctx, port)
go s.Run(ctx, port, metricsPort)

err = test.WaitForPortListen(fmt.Sprintf("127.0.0.1:%d", port), 10*time.Second)
assert.NoError(t, err)
Expand Down

0 comments on commit 9f9a076

Please sign in to comment.