Skip to content

Commit 09e601e

Browse files
authored
fix: logging and pf improvements, skip namespaces & non-ClusterIP svcs (#249)
* fix: logging and pf improvements, skip namespaces & non-ClusterIP svcs This PR contains a number of reliability and UX improvements for using localizer in a larger cluster. * When creating a port-forward, we don't pass a stop channel anymore. This was previously passed `ctx.Done()` which would silently stop the port-forward on ^C. This caused invalid "use of closed connection" logging that was confusing to the user but also possibly could end up in a port-forward not being fully stopped. * When shutting down, pass a temporary context that has a timeout of 30 seconds. This ensures that `/etc/host` modifications, ip pool cleanups, and other shutdown functions properly finish instead of possibly being terminated midway through during normal shutdown. * Enabled delibird to remove tracing/metrics information being sent by default in localizer binaries. This is a OSS friendly way of us getting telemetry by logging to disk instead, which a user can opt to send us when reporting bugs (more on that in future work!) * Upgraded all dependencies, including `client-go`. We still need a fork, but thankfully our fork is a single line now so it's much more likely we can upstream the change we made (the other change was upstreamed a year ago by another user!) * Exposes `stderr` from the port-forwarder to the console with a colored prefix. This makes it easier to tell when a port-forward was busted but localizer didn't detect it (or if it did, why it failed!) * Skipped namespaces by default (`kube-system`) and enabled the user to pass `--skip-namespace` to provide more (helps #212). * Skip non-clusterIP services. These aren't addressable in the cluster, so we shouldn't create a tunnel for them. This helps with `NodePort` and `LoadBalancer` service overhead that some larger clusters may have. * Reduced logging to be easier to read, while keeping a lot of helpful logs in the `debug` level. Defaults to `info` logging instead of `debug` logging (pass `--log-level debug` for that!) * make linter happy and shutdown easier to read
1 parent 41773d1 commit 09e601e

File tree

12 files changed

+406
-448
lines changed

12 files changed

+406
-448
lines changed

.goreleaser.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ builds:
1414
- arm64
1515
ldflags:
1616
- '-w -s -X "github.com/getoutreach/gobox/pkg/app.Version=v{{ .Version }}"'
17-
- '-X "main.HoneycombTracingKey={{ .Env.HONEYCOMB_APIKEY }}"'
18-
- '-X "main.TeleforkAPIKey={{ .Env.TELEFORK_APIKEY }}"'
1917
env:
2018
- CGO_ENABLED=0
2119

cmd/localizer/localizer.go

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"syscall"
1717

1818
oapp "github.com/getoutreach/gobox/pkg/app"
19-
"github.com/getoutreach/gobox/pkg/cfg"
2019
gcli "github.com/getoutreach/gobox/pkg/cli"
2120
"github.com/getoutreach/localizer/internal/kevents"
2221
"github.com/getoutreach/localizer/internal/kube"
@@ -32,22 +31,6 @@ import (
3231
// <</Stencil::Block>>
3332
)
3433

35-
// HoneycombTracingKey gets set by the Makefile at compile-time which is pulled
36-
// down by devconfig.sh.
37-
var HoneycombTracingKey = "NOTSET" //nolint:gochecknoglobals // Why: We can't compile in things as a const.
38-
39-
// TeleforkAPIKey gets set by the Makefile at compile-time which is pulled
40-
// down by devconfig.sh.
41-
var TeleforkAPIKey = "NOTSET" //nolint:gochecknoglobals // Why: We can't compile in things as a const.
42-
43-
// <<Stencil::Block(honeycombDataset)>>
44-
45-
// HoneycombDataset is a constant denoting the dataset that traces should be stored
46-
// in in honeycomb.
47-
const HoneycombDataset = ""
48-
49-
// <</Stencil::Block>>
50-
5134
// <<Stencil::Block(global)>>
5235

5336
// <</Stencil::Block>>
@@ -78,11 +61,9 @@ func main() {
7861
EnvVars: []string{"KUBECONTEXT"},
7962
},
8063
&cli.StringFlag{
81-
Name: "log-level",
82-
Usage: "Set the log level",
83-
EnvVars: []string{"LOG_LEVEL"},
84-
Value: "DEBUG",
85-
DefaultText: "DEBUG",
64+
Name: "log-level",
65+
Usage: "Set the log level. Valid values are: debug",
66+
EnvVars: []string{"LOG_LEVEL"},
8667
},
8768
&cli.StringFlag{
8869
Name: "log-format",
@@ -104,6 +85,10 @@ func main() {
10485
Name: "namespace",
10586
Usage: "Restrict forwarding to the given namespace. (default: all namespaces)",
10687
},
88+
&cli.StringSliceFlag{
89+
Name: "skip-namespace",
90+
Usage: "Skip forwarding services from the following namespace",
91+
},
10792
// <</Stencil::Block>>
10893
}
10994
app.Commands = []*cli.Command{
@@ -140,7 +125,7 @@ func main() {
140125
log.SetFormatter(&logrus.JSONFormatter{})
141126
}
142127

143-
klog.SetLogger(logrusr.New(log))
128+
klog.SetLogger(logrusr.New(log, logrusr.WithReportCaller()))
144129

145130
// setup the global kubernetes cache interface
146131
config, k, err := kube.GetKubeClient(c.String("context"))
@@ -182,10 +167,7 @@ func main() {
182167
gcli.Run(ctx, cancel, &app, &gcli.Config{
183168
Logger: log,
184169
Telemetry: gcli.TelemetryConfig{
185-
Otel: gcli.TelemetryOtelConfig{
186-
Dataset: HoneycombDataset,
187-
HoneycombAPIKey: cfg.SecretData(HoneycombTracingKey),
188-
},
170+
UseDelibird: true,
189171
},
190172
})
191173
}

go.mod

Lines changed: 85 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,105 +3,117 @@ module github.com/getoutreach/localizer
33
go 1.19
44

55
require (
6-
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
7-
github.com/benbjohnson/clock v1.3.0
6+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
7+
github.com/benbjohnson/clock v1.3.5
88
github.com/davecgh/go-spew v1.1.1
99
github.com/elazarl/goproxy v0.0.0-20210110162100-a92cc753f88e // indirect
10-
github.com/function61/gokit v0.0.0-20210402130425-341c2c9ecfd0
10+
github.com/function61/gokit v0.0.0-20230712092143-d63a51667e64
1111
github.com/google/go-cmp v0.5.9
1212
github.com/google/gofuzz v1.2.0 // indirect
13-
github.com/metal-stack/go-ipam v1.11.2
13+
github.com/metal-stack/go-ipam v1.12.3
1414
github.com/pkg/errors v0.9.1
15-
github.com/sirupsen/logrus v1.9.0
16-
github.com/urfave/cli/v2 v2.16.3
17-
golang.org/x/crypto v0.1.0
18-
google.golang.org/genproto v0.0.0-20230127162408-596548ed4efa // indirect
19-
google.golang.org/grpc v1.53.0
20-
google.golang.org/protobuf v1.28.1
15+
github.com/sirupsen/logrus v1.9.3
16+
github.com/urfave/cli/v2 v2.25.7
17+
golang.org/x/crypto v0.11.0
18+
google.golang.org/genproto v0.0.0-20230731193218-e0aa005b6bdf // indirect
19+
google.golang.org/grpc v1.57.0
20+
google.golang.org/protobuf v1.31.0
2121

2222
// kubernetes deps
23-
k8s.io/api v0.23.1
24-
k8s.io/apimachinery v0.24.0-alpha.3
25-
k8s.io/client-go v0.23.1
26-
k8s.io/klog/v2 v2.60.1
23+
k8s.io/api v0.25.12
24+
k8s.io/apimachinery v0.25.12
25+
k8s.io/client-go v0.25.12
26+
k8s.io/klog/v2 v2.100.1
2727
)
2828

29-
require github.com/getoutreach/gobox v1.71.0
29+
require (
30+
github.com/egymgmbh/go-prefix-writer v0.0.0-20180609083313-7326ea162eca
31+
github.com/fatih/color v1.13.0
32+
github.com/getoutreach/gobox v1.73.1
33+
)
3034

3135
require (
32-
cloud.google.com/go/compute v1.15.1 // indirect
36+
cloud.google.com/go/compute v1.23.0 // indirect
3337
cloud.google.com/go/compute/metadata v0.2.3 // indirect
3438
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
35-
github.com/Azure/go-autorest/autorest v0.11.12 // indirect
36-
github.com/Azure/go-autorest/autorest/adal v0.9.16 // indirect
39+
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
40+
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
3741
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
3842
github.com/Azure/go-autorest/logger v0.2.1 // indirect
3943
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
40-
github.com/Microsoft/go-winio v0.5.2 // indirect
44+
github.com/Microsoft/go-winio v0.6.1 // indirect
4145
github.com/ProtonMail/go-crypto v0.0.0-20220407094043-a94812496cf5 // indirect
46+
github.com/PuerkitoBio/purell v1.1.1 // indirect
47+
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
4248
github.com/acomagu/bufpipe v1.0.3 // indirect
4349
github.com/alecthomas/chroma v0.10.0 // indirect
44-
github.com/avast/retry-go/v4 v4.3.0 // indirect
50+
github.com/avast/retry-go/v4 v4.3.4 // indirect
4551
github.com/aymanbagabas/go-osc52 v1.0.3 // indirect
4652
github.com/aymerick/douceur v0.2.0 // indirect
4753
github.com/beorn7/perks v1.0.1 // indirect
4854
github.com/briandowns/spinner v1.23.0 // indirect
49-
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
55+
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
5056
github.com/cespare/xxhash/v2 v2.2.0 // indirect
5157
github.com/charmbracelet/glamour v0.6.0 // indirect
5258
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
53-
github.com/coreos/go-semver v0.3.0 // indirect
54-
github.com/coreos/go-systemd/v22 v22.4.0 // indirect
59+
github.com/coreos/go-semver v0.3.1 // indirect
60+
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
5561
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
5662
github.com/creack/pty v1.1.17 // indirect
5763
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
5864
github.com/dlclark/regexp2 v1.4.0 // indirect
65+
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
5966
github.com/emirpasic/gods v1.12.1 // indirect
60-
github.com/fatih/color v1.13.0 // indirect
6167
github.com/felixge/httpsnoop v1.0.3 // indirect
62-
github.com/fsnotify/fsnotify v1.5.1 // indirect
6368
github.com/go-git/gcfg v1.5.0 // indirect
6469
github.com/go-git/go-billy/v5 v5.3.1 // indirect
6570
github.com/go-git/go-git/v5 v5.4.2 // indirect
66-
github.com/go-logr/logr v1.2.3 // indirect
71+
github.com/go-logr/logr v1.2.4 // indirect
6772
github.com/go-logr/stdr v1.2.2 // indirect
68-
github.com/go-redis/redis/v8 v8.11.5 // indirect
73+
github.com/go-openapi/jsonpointer v0.19.5 // indirect
74+
github.com/go-openapi/jsonreference v0.19.5 // indirect
75+
github.com/go-openapi/swag v0.19.14 // indirect
6976
github.com/gogo/protobuf v1.3.2 // indirect
70-
github.com/golang/protobuf v1.5.2 // indirect
77+
github.com/golang/protobuf v1.5.3 // indirect
7178
github.com/golang/snappy v0.0.4 // indirect
79+
github.com/google/gnostic v0.5.7-v3refs // indirect
7280
github.com/google/go-github/v47 v47.0.0 // indirect
7381
github.com/google/go-querystring v1.1.0 // indirect
7482
github.com/google/uuid v1.3.0 // indirect
7583
github.com/gorilla/css v1.0.0 // indirect
7684
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 // indirect
7785
github.com/honeycombio/beeline-go v1.11.1 // indirect
78-
github.com/imdario/mergo v0.3.13 // indirect
86+
github.com/imdario/mergo v0.3.15 // indirect
7987
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect
8088
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
8189
github.com/jmoiron/sqlx v1.3.5 // indirect
90+
github.com/josharian/intern v1.0.0 // indirect
8291
github.com/json-iterator/go v1.1.12 // indirect
8392
github.com/kevinburke/ssh_config v1.2.0 // indirect
84-
github.com/klauspost/compress v1.15.12 // indirect
93+
github.com/klauspost/compress v1.16.7 // indirect
8594
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
95+
github.com/mailru/easyjson v0.7.6 // indirect
8696
github.com/manifoldco/promptui v0.9.0 // indirect
8797
github.com/mattn/go-colorable v0.1.12 // indirect
8898
github.com/mattn/go-isatty v0.0.17 // indirect
8999
github.com/mattn/go-runewidth v0.0.14 // indirect
90-
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
100+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
91101
github.com/microcosm-cc/bluemonday v1.0.21 // indirect
92102
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
93103
github.com/mitchellh/go-homedir v1.1.0 // indirect
94104
github.com/moby/spdystream v0.2.0 // indirect
95105
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
96106
github.com/modern-go/reflect2 v1.0.2 // indirect
97-
github.com/montanaflynn/stats v0.6.6 // indirect
107+
github.com/montanaflynn/stats v0.7.1 // indirect
98108
github.com/muesli/reflow v0.3.0 // indirect
99109
github.com/muesli/termenv v0.13.0 // indirect
110+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
100111
github.com/olekukonko/tablewriter v0.0.5 // indirect
101-
github.com/prometheus/client_golang v1.14.0 // indirect
102-
github.com/prometheus/client_model v0.3.0 // indirect
103-
github.com/prometheus/common v0.37.0 // indirect
104-
github.com/prometheus/procfs v0.8.0 // indirect
112+
github.com/prometheus/client_golang v1.16.0 // indirect
113+
github.com/prometheus/client_model v0.4.0 // indirect
114+
github.com/prometheus/common v0.44.0 // indirect
115+
github.com/prometheus/procfs v0.11.1 // indirect
116+
github.com/redis/go-redis/v9 v9.0.5 // indirect
105117
github.com/rivo/uniseg v0.2.0 // indirect
106118
github.com/russross/blackfriday/v2 v2.1.0 // indirect
107119
github.com/schollz/progressbar/v3 v3.13.1 // indirect
@@ -110,58 +122,61 @@ require (
110122
github.com/ulikunitz/xz v0.5.10 // indirect
111123
github.com/xanzy/ssh-agent v0.3.1 // indirect
112124
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
113-
github.com/xdg-go/scram v1.1.1 // indirect
114-
github.com/xdg-go/stringprep v1.0.3 // indirect
125+
github.com/xdg-go/scram v1.1.2 // indirect
126+
github.com/xdg-go/stringprep v1.0.4 // indirect
115127
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
116128
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
117129
github.com/yuin/goldmark v1.5.2 // indirect
118130
github.com/yuin/goldmark-emoji v1.0.1 // indirect
119-
go.etcd.io/etcd/api/v3 v3.5.5 // indirect
120-
go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect
121-
go.etcd.io/etcd/client/v3 v3.5.5 // indirect
122-
go.mongodb.org/mongo-driver v1.10.3 // indirect
123-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.33.0 // indirect
124-
go.opentelemetry.io/otel v1.14.0 // indirect
125-
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 // indirect
126-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.14.0 // indirect
127-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0 // indirect
128-
go.opentelemetry.io/otel/metric v0.31.0 // indirect
129-
go.opentelemetry.io/otel/sdk v1.14.0 // indirect
130-
go.opentelemetry.io/otel/trace v1.14.0 // indirect
131+
go.etcd.io/etcd/api/v3 v3.5.9 // indirect
132+
go.etcd.io/etcd/client/pkg/v3 v3.5.9 // indirect
133+
go.etcd.io/etcd/client/v3 v3.5.9 // indirect
134+
go.mongodb.org/mongo-driver v1.12.1 // indirect
135+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 // indirect
136+
go.opentelemetry.io/otel v1.16.0 // indirect
137+
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
138+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 // indirect
139+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0 // indirect
140+
go.opentelemetry.io/otel/metric v1.16.0 // indirect
141+
go.opentelemetry.io/otel/sdk v1.16.0 // indirect
142+
go.opentelemetry.io/otel/trace v1.16.0 // indirect
131143
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
132-
go.uber.org/atomic v1.10.0 // indirect
133-
go.uber.org/multierr v1.8.0 // indirect
134-
go.uber.org/zap v1.23.0 // indirect
135-
go4.org/netipx v0.0.0-20220925034521-797b0c90d8ab // indirect
136-
golang.org/x/net v0.7.0 // indirect
137-
golang.org/x/oauth2 v0.4.0 // indirect
138-
golang.org/x/sync v0.1.0 // indirect
139-
golang.org/x/sys v0.6.0 // indirect
140-
golang.org/x/term v0.6.0 // indirect
141-
golang.org/x/text v0.7.0 // indirect
144+
go.uber.org/multierr v1.11.0 // indirect
145+
go.uber.org/zap v1.25.0 // indirect
146+
go4.org/netipx v0.0.0-20230728184502-ec4c8b891b28 // indirect
147+
golang.org/x/mod v0.12.0 // indirect
148+
golang.org/x/net v0.13.0 // indirect
149+
golang.org/x/oauth2 v0.8.0 // indirect
150+
golang.org/x/sync v0.3.0 // indirect
151+
golang.org/x/sys v0.10.0 // indirect
152+
golang.org/x/term v0.10.0 // indirect
153+
golang.org/x/text v0.11.0 // indirect
154+
golang.org/x/tools v0.11.1 // indirect
142155
google.golang.org/appengine v1.6.7 // indirect
156+
google.golang.org/genproto/googleapis/api v0.0.0-20230731193218-e0aa005b6bdf // indirect
157+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230731193218-e0aa005b6bdf // indirect
143158
gopkg.in/inf.v0 v0.9.1 // indirect
144159
gopkg.in/warnings.v0 v0.1.2 // indirect
145160
gopkg.in/yaml.v2 v2.4.0 // indirect
146161
gopkg.in/yaml.v3 v3.0.1 // indirect
162+
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
163+
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
147164
)
148165

149166
require (
150167
github.com/Masterminds/semver/v3 v3.2.0 // indirect
151168
github.com/bombsimon/logrusr/v2 v2.0.1
152-
github.com/golang-jwt/jwt/v4 v4.1.0 // indirect
153-
github.com/googleapis/gnostic v0.5.5 // indirect
154-
github.com/hashicorp/golang-lru v0.5.4 // indirect
155-
github.com/lib/pq v1.10.7 // indirect
169+
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
170+
github.com/lib/pq v1.10.9 // indirect
156171
golang.org/x/time v0.1.0 // indirect
157-
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
158-
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
172+
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
173+
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
159174
sigs.k8s.io/yaml v1.3.0 // indirect
160175
)
161176

162177
replace (
163-
// We're on a fork, keep version at v0.21.0
164-
k8s.io/api => k8s.io/api v0.21.0
165-
k8s.io/apimachinery => k8s.io/apimachinery v0.21.0
166-
k8s.io/client-go => github.com/jaredallard/client-go v0.21.0-jaredallard
178+
// We're on a fork, keep version at v0.25.12
179+
k8s.io/api => k8s.io/api v0.25.12
180+
k8s.io/apimachinery => k8s.io/apimachinery v0.25.12
181+
k8s.io/client-go => github.com/jaredallard/client-go v0.25.12-jaredallard.1
167182
)

0 commit comments

Comments
 (0)