Skip to content

Commit

Permalink
etcdmain/grpc-proxy: add 'metrics-addr' option
Browse files Browse the repository at this point in the history
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Jul 14, 2017
1 parent 8463b37 commit c47d445
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions etcdmain/grpc_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"net"
"net/http"
"net/url"
"os"
"time"

Expand All @@ -40,6 +41,7 @@ import (

var (
grpcProxyListenAddr string
grpcProxyMetricsListenAddr string
grpcProxyEndpoints []string
grpcProxyDNSCluster string
grpcProxyInsecureDiscovery bool
Expand Down Expand Up @@ -80,6 +82,7 @@ func newGRPCProxyStartCommand() *cobra.Command {

cmd.Flags().StringVar(&grpcProxyListenAddr, "listen-addr", "127.0.0.1:23790", "listen address")
cmd.Flags().StringVar(&grpcProxyDNSCluster, "discovery-srv", "", "DNS domain used to bootstrap initial cluster")
cmd.Flags().StringVar(&grpcProxyMetricsListenAddr, "metrics-addr", "", "listen for /metrics requests on an additional interface")
cmd.Flags().BoolVar(&grpcProxyInsecureDiscovery, "insecure-discovery", false, "accept insecure SRV records")
cmd.Flags().StringSliceVar(&grpcProxyEndpoints, "endpoints", []string{"127.0.0.1:2379"}, "comma separated etcd cluster endpoints")
cmd.Flags().StringVar(&grpcProxyCert, "cert", "", "identify secure connections with etcd servers using this TLS certificate file")
Expand Down Expand Up @@ -129,7 +132,7 @@ func startGRPCProxy(cmd *cobra.Command, args []string) {
}()
m := cmux.New(l)

cfg, err := newClientCfg()
cfg, cfgtls, err := newClientCfg()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand Down Expand Up @@ -202,14 +205,35 @@ func startGRPCProxy(cmd *cobra.Command, args []string) {

go func() { errc <- m.Serve() }()

if len(grpcProxyMetricsListenAddr) > 0 {
murl, err := url.Parse(grpcProxyMetricsListenAddr)
if err != nil {
fmt.Fprintf(os.Stderr, "cannot parse %q", grpcProxyMetricsListenAddr)
os.Exit(1)
}
ml, err := transport.NewListener(murl.Host, murl.Scheme, cfgtls)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

mux := http.NewServeMux()
mux.Handle("/metrics", prometheus.Handler())

go func() {
plog.Info("grpc-proxy: listening for metrics on ", murl.String())
plog.Fatal(http.Serve(ml, mux))
}()
}

// grpc-proxy is initialized, ready to serve
notifySystemd()

fmt.Fprintln(os.Stderr, <-errc)
os.Exit(1)
}

func newClientCfg() (*clientv3.Config, error) {
func newClientCfg() (*clientv3.Config, *transport.TLSInfo, error) {
// set tls if any one tls option set
var cfgtls *transport.TLSInfo
tlsinfo := transport.TLSInfo{}
Expand All @@ -235,12 +259,12 @@ func newClientCfg() (*clientv3.Config, error) {
if cfgtls != nil {
clientTLS, err := cfgtls.ClientConfig()
if err != nil {
return nil, err
return nil, nil, err
}
cfg.TLS = clientTLS
}

// TODO: support insecure tls

return &cfg, nil
return &cfg, cfgtls, nil
}

0 comments on commit c47d445

Please sign in to comment.