Skip to content

Commit d0fc6a3

Browse files
authored
Supporting multiple metrics (#16)
1 parent 090a21e commit d0fc6a3

File tree

1,311 files changed

+743
-437198
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,311 files changed

+743
-437198
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ addons:
1010

1111
language: go
1212
go_import_path: github.com/v3io/sidecar-proxy
13-
go: "1.11"
13+
go: "1.13"
1414

1515
script:
1616
- make

Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ all: lint build
99

1010
.PHONY: build
1111
build:
12-
docker build --tag=$(PROXY_REPOSITORY)sidecar-proxy:$(PROXY_TAG) .
12+
docker build -f cmd/sidecarproxy/Dockerfile --tag=$(PROXY_REPOSITORY)sidecar-proxy:$(PROXY_TAG) .
1313

1414
.PHONY: ensure-gopath bin
1515
bin:
@@ -18,14 +18,12 @@ bin:
1818
.PHONY: lint
1919
lint: ensure-gopath
2020
@echo Installing linters...
21-
go get -u gopkg.in/alecthomas/gometalinter.v2
22-
@$(GOPATH)/bin/gometalinter.v2 --install
21+
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOPATH)/bin v1.21.0
2322

2423
@echo Linting...
25-
@$(GOPATH)/bin/gometalinter.v2 \
24+
@$(GOPATH)/bin/golangci-lint run \
2625
--deadline=300s \
2726
--disable-all \
28-
--enable-gc \
2927
--enable=deadcode \
3028
--enable=goconst \
3129
--enable=gofmt \
@@ -44,7 +42,7 @@ lint: ensure-gopath
4442
--exclude="comment on" \
4543
--exclude="error should be the last" \
4644
--exclude="should have comment" \
47-
./app/...
45+
./pkg/...
4846

4947
@echo Done.
5048

app/metrics.go

Lines changed: 0 additions & 52 deletions
This file was deleted.

app/server.go

Lines changed: 0 additions & 107 deletions
This file was deleted.

Dockerfile renamed to cmd/sidecarproxy/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
FROM golang:1.11 as builder
1+
FROM golang:1.13 as builder
22

33
# copy source tree
44
WORKDIR /go/src/github.com/v3io/sidecar-proxy
55
COPY . .
66

77
# build the app
8-
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags="-s -w" -o proxy_server main.go
8+
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags="-s -w" -o proxy_server cmd/sidecarproxy/main.go
99

1010
#
1111
# Output stage: Copies binary to an alpine based image

cmd/sidecarproxy/main.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"os"
6+
7+
"github.com/v3io/sidecar-proxy/pkg/common"
8+
"github.com/v3io/sidecar-proxy/pkg/sidecarproxy"
9+
10+
"github.com/nuclio/errors"
11+
"github.com/nuclio/loggerus"
12+
"github.com/sirupsen/logrus"
13+
)
14+
15+
func run() error {
16+
var metricNames common.StringArrayFlag
17+
18+
// args
19+
listenAddress := flag.String("listen-addr", os.Getenv("PROXY_LISTEN_ADDRESS"), "Port to listen on")
20+
forwardAddress := flag.String("forward-addr", os.Getenv("PROXY_FORWARD_ADDRESS"), "IP /w port to forward to (without protocol)")
21+
namespace := flag.String("namespace", os.Getenv("PROXY_NAMESPACE"), "Kubernetes namespace")
22+
serviceName := flag.String("service-name", os.Getenv("PROXY_SERVICE_NAME"), "Service which the proxy serves")
23+
instanceName := flag.String("instance-name", os.Getenv("PROXY_INSTANCE_NAME"), "Deployment instance name")
24+
logLevel := flag.String("log-level", os.Getenv("LOG_LEVEL"), "Set proxy's log level")
25+
flag.Var(&metricNames, "metric-name", "Set which metrics to collect")
26+
flag.Parse()
27+
28+
// logger conf
29+
parsedLogLevel, err := logrus.ParseLevel(*logLevel)
30+
if err != nil {
31+
errors.Wrap(err, "Failed to parse log level")
32+
}
33+
logger, err := loggerus.NewTextLoggerus("main", parsedLogLevel, os.Stdout, true)
34+
if err != nil {
35+
errors.Wrap(err, "Failed to create new logger")
36+
}
37+
38+
if len(metricNames) == 0 {
39+
return errors.New("at least one metric name should be given")
40+
}
41+
42+
// server start
43+
server, err := sidecarproxy.NewServer(logger, *listenAddress, *forwardAddress, *namespace, *serviceName, *instanceName, metricNames)
44+
if err != nil {
45+
errors.Wrap(err, "Failed to create new server")
46+
}
47+
if err = server.Start(); err != nil {
48+
errors.Wrap(err, "Failed to start server")
49+
}
50+
51+
return nil
52+
}
53+
54+
func main() {
55+
if err := run(); err != nil {
56+
errors.PrintErrorStack(os.Stderr, err, 5)
57+
os.Exit(1)
58+
}
59+
60+
os.Exit(0)
61+
}

go.mod

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module github.com/v3io/sidecar-proxy
2+
3+
go 1.13
4+
5+
require (
6+
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
7+
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf // indirect
8+
github.com/gorilla/websocket v1.4.1
9+
github.com/koding/websocketproxy v0.0.0-20181220232114-7ed82d81a28c
10+
github.com/nuclio/errors v0.0.1
11+
github.com/nuclio/logger v0.0.1
12+
github.com/nuclio/loggerus v0.0.1
13+
github.com/prometheus/client_golang v1.2.1
14+
github.com/sirupsen/logrus v1.4.2
15+
gopkg.in/alecthomas/gometalinter.v2 v2.0.12 // indirect
16+
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c // indirect
17+
)

0 commit comments

Comments
 (0)