Skip to content

Commit bc9db8b

Browse files
committed
Use axiomhq/pkg/cmd
1 parent e766aae commit bc9db8b

File tree

3 files changed

+260
-169
lines changed

3 files changed

+260
-169
lines changed

cmd/axiom-honeycomb-proxy/main.go

Lines changed: 24 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,90 +3,63 @@ package main
33
import (
44
"context"
55
"flag"
6-
"log"
7-
"os"
8-
"os/signal"
9-
"syscall"
10-
"time"
116

127
"github.com/axiomhq/axiom-go/axiom"
8+
"github.com/axiomhq/pkg/cmd"
139
"github.com/axiomhq/pkg/http"
14-
"github.com/axiomhq/pkg/version"
10+
"go.uber.org/zap"
1511

1612
"github.com/axiomhq/axiom-honeycomb-proxy/proxy"
1713
)
1814

19-
const (
20-
exitOK int = iota
21-
exitConfig
22-
exitInternal
23-
)
24-
2515
const defaultHoneyCombURL = "https://api.honeycomb.io"
2616

2717
var addr = flag.String("addr", ":8080", "Listen address <ip>:<port>")
2818

2919
func main() {
30-
os.Exit(Main())
20+
cmd.Run("axiom-honeycomb-proxy", run,
21+
cmd.WithValidateAxiomCredentials(),
22+
)
3123
}
3224

33-
func Main() int {
34-
// Export `AXIOM_TOKEN` and `AXIOM_ORG_ID` for Axiom Cloud
35-
// Export `AXIOM_URL` and `AXIOM_TOKEN` for Axiom Selfhost
36-
37-
log.Print("starting axiom-honeycomb-proxy version ", version.Release())
25+
func run(ctx context.Context, log *zap.Logger, client *axiom.Client) error {
26+
// Export `AXIOM_TOKEN` and `AXIOM_ORG_ID` for Axiom Cloud.
27+
// Export `AXIOM_URL` and `AXIOM_TOKEN` for Axiom Selfhost.
3828

3929
flag.Parse()
4030

41-
ctx, cancel := signal.NotifyContext(context.Background(),
42-
os.Interrupt,
43-
os.Kill,
44-
syscall.SIGHUP,
45-
syscall.SIGINT,
46-
syscall.SIGQUIT,
47-
)
48-
defer cancel()
49-
50-
client, err := axiom.NewClient()
51-
if err != nil {
52-
log.Print(err)
53-
return exitConfig
54-
} else if err = client.ValidateCredentials(ctx); err != nil {
55-
log.Print(err)
56-
return exitConfig
57-
}
58-
5931
mp, err := proxy.NewMultiplexer(client, defaultHoneyCombURL)
6032
if err != nil {
61-
log.Print(err)
62-
return exitInternal
33+
return cmd.Error("create multiplexer", err)
6334
}
6435

65-
srv, err := http.NewServer(*addr, mp)
36+
srv, err := http.NewServer(*addr, mp,
37+
http.WithBaseContext(ctx),
38+
http.WithLogger(log),
39+
)
6640
if err != nil {
67-
log.Print(err)
68-
return exitInternal
41+
return cmd.Error("create http server", err)
6942
}
7043
defer func() {
71-
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), time.Second*5)
72-
defer shutdownCancel()
73-
74-
if shutdownErr := srv.Shutdown(shutdownCtx); shutdownErr != nil {
75-
log.Print(shutdownErr)
44+
if shutdownErr := srv.Shutdown(); shutdownErr != nil {
45+
log.Error("stopping server", zap.Error(shutdownErr))
46+
return
7647
}
7748
}()
7849

7950
srv.Run(ctx)
8051

81-
log.Print("listening on ", srv.ListenAddr().String())
52+
log.Info("server listening",
53+
zap.String("address", srv.ListenAddr().String()),
54+
zap.String("network", srv.ListenAddr().Network()),
55+
)
8256

8357
select {
8458
case <-ctx.Done():
85-
log.Print("received interrupt, exiting gracefully")
59+
log.Warn("received interrupt, exiting gracefully")
8660
case err := <-srv.ListenError():
87-
log.Print("error starting http server, exiting gracefully: ", err)
88-
return exitInternal
61+
return cmd.Error("error starting http server, exiting gracefully", err)
8962
}
9063

91-
return exitOK
64+
return nil
9265
}

go.mod

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,41 @@ module github.com/axiomhq/axiom-honeycomb-proxy
33
go 1.17
44

55
require (
6-
github.com/axiomhq/axiom-go v0.6.0
7-
github.com/axiomhq/pkg v0.1.0
6+
github.com/axiomhq/axiom-go v0.6.2
7+
github.com/axiomhq/pkg v0.2.0
88
github.com/golangci/golangci-lint v1.42.1
9-
github.com/goreleaser/goreleaser v0.177.0
10-
github.com/klauspost/compress v1.13.5
9+
github.com/goreleaser/goreleaser v0.180.3
10+
github.com/klauspost/compress v1.13.6
1111
github.com/vmihailenco/msgpack/v5 v5.3.4
12-
go.uber.org/zap v1.19.0
12+
go.uber.org/zap v1.19.1
1313
gotest.tools/gotestsum v1.7.0
1414
)
1515

1616
require (
1717
4d63.com/gochecknoglobals v0.0.0-20201008074935-acfc0b28355a // indirect
18-
cloud.google.com/go v0.81.0 // indirect
19-
cloud.google.com/go/storage v1.15.0 // indirect
18+
cloud.google.com/go v0.94.0 // indirect
19+
cloud.google.com/go/kms v0.1.0 // indirect
20+
cloud.google.com/go/storage v1.16.1 // indirect
2021
code.gitea.io/sdk/gitea v0.15.0 // indirect
2122
github.com/AlekSi/pointer v1.1.0 // indirect
2223
github.com/Antonboom/errname v0.1.4 // indirect
2324
github.com/Azure/azure-pipeline-go v0.2.3 // indirect
24-
github.com/Azure/azure-sdk-for-go v54.0.0+incompatible // indirect
25-
github.com/Azure/azure-storage-blob-go v0.13.0 // indirect
25+
github.com/Azure/azure-sdk-for-go v57.0.0+incompatible // indirect
26+
github.com/Azure/azure-storage-blob-go v0.14.0 // indirect
2627
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
27-
github.com/Azure/go-autorest/autorest v0.11.18 // indirect
28-
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect
29-
github.com/Azure/go-autorest/autorest/azure/auth v0.5.7 // indirect
30-
github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 // indirect
28+
github.com/Azure/go-autorest/autorest v0.11.20 // indirect
29+
github.com/Azure/go-autorest/autorest/adal v0.9.15 // indirect
30+
github.com/Azure/go-autorest/autorest/azure/auth v0.5.8 // indirect
31+
github.com/Azure/go-autorest/autorest/azure/cli v0.4.3 // indirect
3132
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
3233
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
3334
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
3435
github.com/Azure/go-autorest/logger v0.2.1 // indirect
3536
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
3637
github.com/BurntSushi/toml v0.4.1 // indirect
38+
github.com/DisgoOrg/disgohook v1.4.3 // indirect
39+
github.com/DisgoOrg/log v1.1.0 // indirect
40+
github.com/DisgoOrg/restclient v1.2.7 // indirect
3741
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect
3842
github.com/Masterminds/goutils v1.1.1 // indirect
3943
github.com/Masterminds/semver v1.5.0 // indirect
@@ -46,7 +50,18 @@ require (
4650
github.com/apex/log v1.9.0 // indirect
4751
github.com/ashanbrown/forbidigo v1.2.0 // indirect
4852
github.com/ashanbrown/makezero v0.0.0-20210520155254-b6261585ddde // indirect
49-
github.com/aws/aws-sdk-go v1.38.35 // indirect
53+
github.com/atc0005/go-teams-notify/v2 v2.6.0 // indirect
54+
github.com/aws/aws-sdk-go v1.40.34 // indirect
55+
github.com/aws/aws-sdk-go-v2 v1.9.0 // indirect
56+
github.com/aws/aws-sdk-go-v2/config v1.7.0 // indirect
57+
github.com/aws/aws-sdk-go-v2/credentials v1.4.0 // indirect
58+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.5.0 // indirect
59+
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.2 // indirect
60+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.3.0 // indirect
61+
github.com/aws/aws-sdk-go-v2/service/kms v1.5.0 // indirect
62+
github.com/aws/aws-sdk-go-v2/service/sso v1.4.0 // indirect
63+
github.com/aws/aws-sdk-go-v2/service/sts v1.7.0 // indirect
64+
github.com/aws/smithy-go v1.8.0 // indirect
5065
github.com/beorn7/perks v1.0.1 // indirect
5166
github.com/bkielbasa/cyclop v1.2.0 // indirect
5267
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb // indirect
@@ -73,8 +88,7 @@ require (
7388
github.com/ettle/strcase v0.1.1 // indirect
7489
github.com/fatih/color v1.12.0 // indirect
7590
github.com/fatih/structtag v1.2.0 // indirect
76-
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
77-
github.com/fsnotify/fsnotify v1.4.9 // indirect
91+
github.com/fsnotify/fsnotify v1.5.1 // indirect
7892
github.com/fzipp/gocyclo v0.3.1 // indirect
7993
github.com/go-critic/go-critic v0.5.6 // indirect
8094
github.com/go-git/gcfg v1.5.0 // indirect
@@ -90,6 +104,7 @@ require (
90104
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b // indirect
91105
github.com/gobwas/glob v0.2.3 // indirect
92106
github.com/gofrs/flock v0.8.1 // indirect
107+
github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
93108
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
94109
github.com/golang/protobuf v1.5.2 // indirect
95110
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 // indirect
@@ -106,9 +121,9 @@ require (
106121
github.com/google/go-querystring v1.1.0 // indirect
107122
github.com/google/rpmpack v0.0.0-20210410105602-e20c988a6f5a // indirect
108123
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
109-
github.com/google/uuid v1.2.0 // indirect
124+
github.com/google/uuid v1.3.0 // indirect
110125
github.com/google/wire v0.5.0 // indirect
111-
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
126+
github.com/googleapis/gax-go/v2 v2.1.0 // indirect
112127
github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254 // indirect
113128
github.com/goreleaser/chglog v0.1.2 // indirect
114129
github.com/goreleaser/fileglob v1.2.0 // indirect
@@ -133,7 +148,6 @@ require (
133148
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af // indirect
134149
github.com/jmespath/go-jmespath v0.4.0 // indirect
135150
github.com/jonboulle/clockwork v0.2.2 // indirect
136-
github.com/jstemmer/go-junit-report v0.9.1 // indirect
137151
github.com/julz/importas v0.0.0-20210419104244-841f0c0fe66d // indirect
138152
github.com/kevinburke/ssh_config v1.1.0 // indirect
139153
github.com/kisielk/errcheck v1.6.0 // indirect
@@ -214,27 +228,28 @@ require (
214228
github.com/xanzy/ssh-agent v0.3.0 // indirect
215229
github.com/yeya24/promlinter v0.1.0 // indirect
216230
go.opencensus.io v0.23.0 // indirect
217-
go.uber.org/atomic v1.7.0 // indirect
218-
go.uber.org/multierr v1.6.0 // indirect
219-
gocloud.dev v0.23.0 // indirect
220-
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
221-
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
222-
golang.org/x/mod v0.4.2 // indirect
223-
golang.org/x/net v0.0.0-20210505214959-0714010a04ed // indirect
224-
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 // indirect
231+
go.uber.org/atomic v1.9.0 // indirect
232+
go.uber.org/multierr v1.7.0 // indirect
233+
gocloud.dev v0.24.0 // indirect
234+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
235+
golang.org/x/mod v0.5.0 // indirect
236+
golang.org/x/net v0.0.0-20210825183410-e898025ed96a // indirect
237+
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
225238
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
226-
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
239+
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
227240
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
228-
golang.org/x/text v0.3.6 // indirect
229-
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
230-
golang.org/x/tools v0.1.5 // indirect
241+
golang.org/x/text v0.3.7 // indirect
242+
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
243+
golang.org/x/tools v0.1.7 // indirect
231244
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
232-
google.golang.org/api v0.46.0 // indirect
245+
google.golang.org/api v0.56.0 // indirect
233246
google.golang.org/appengine v1.6.7 // indirect
234-
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
235-
google.golang.org/grpc v1.38.0 // indirect
236-
google.golang.org/protobuf v1.26.0 // indirect
247+
google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 // indirect
248+
google.golang.org/grpc v1.40.0 // indirect
249+
google.golang.org/protobuf v1.27.1 // indirect
250+
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
237251
gopkg.in/ini.v1 v1.62.0 // indirect
252+
gopkg.in/mail.v2 v2.3.1 // indirect
238253
gopkg.in/warnings.v0 v0.1.2 // indirect
239254
gopkg.in/yaml.v2 v2.4.0 // indirect
240255
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect

0 commit comments

Comments
 (0)