-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bafb4d9
commit e766aae
Showing
11 changed files
with
481 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ on: | |
- main | ||
|
||
env: | ||
GOVERSION: "1.16" | ||
GOVERSION: "1.17" | ||
|
||
jobs: | ||
lint: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ on: | |
- main | ||
|
||
env: | ||
GOVERSION: "1.16" | ||
GOVERSION: "1.17" | ||
|
||
jobs: | ||
lint: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ name: Release | |
on: | ||
push: | ||
tags: | ||
- "*" | ||
- "v*" | ||
|
||
env: | ||
GOVERSION: "1.16" | ||
GOVERSION: "1.17" | ||
|
||
jobs: | ||
release: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,9 @@ FROM alpine | |
LABEL maintainer="Axiom, Inc. <[email protected]>" | ||
|
||
# Upgrade packages and install ca-certificates. | ||
RUN apk update --no-cache | ||
RUN apk upgrade --no-cache | ||
RUN apk add --no-cache ca-certificates | ||
RUN apk update --no-cache \ | ||
&& apk upgrade --no-cache \ | ||
&& apk add --no-cache ca-certificates | ||
|
||
# Copy binary into image. | ||
COPY axiom-honeycomb-proxy /usr/bin/axiom-honeycomb-proxy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,92 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"log" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/axiomhq/axiom-go/axiom" | ||
"github.com/axiomhq/pkg/http" | ||
"github.com/axiomhq/pkg/version" | ||
|
||
"github.com/axiomhq/axiom-honeycomb-proxy/proxy" | ||
) | ||
|
||
var ( | ||
defaultHoneyCombURL = "https://api.honeycomb.io" | ||
deploymentURL = os.Getenv("AXIOM_URL") | ||
accessToken = os.Getenv("AXIOM_TOKEN") | ||
addr = flag.String("addr", ":8080", "Listen address <ip>:<port>") | ||
const ( | ||
exitOK int = iota | ||
exitConfig | ||
exitInternal | ||
) | ||
|
||
const defaultHoneyCombURL = "https://api.honeycomb.io" | ||
|
||
var addr = flag.String("addr", ":8080", "Listen address <ip>:<port>") | ||
|
||
func main() { | ||
os.Exit(Main()) | ||
} | ||
|
||
func Main() int { | ||
// Export `AXIOM_TOKEN` and `AXIOM_ORG_ID` for Axiom Cloud | ||
// Export `AXIOM_URL` and `AXIOM_TOKEN` for Axiom Selfhost | ||
|
||
log.Print("starting axiom-honeycomb-proxy version ", version.Release()) | ||
|
||
flag.Parse() | ||
|
||
if deploymentURL == "" { | ||
deploymentURL = axiom.CloudURL | ||
} | ||
if accessToken == "" { | ||
log.Fatal("missing AXIOM_TOKEN") | ||
} | ||
ctx, cancel := signal.NotifyContext(context.Background(), | ||
os.Interrupt, | ||
os.Kill, | ||
syscall.SIGHUP, | ||
syscall.SIGINT, | ||
syscall.SIGQUIT, | ||
) | ||
defer cancel() | ||
|
||
client, err := axiom.NewClient(deploymentURL, accessToken) | ||
client, err := axiom.NewClient() | ||
if err != nil { | ||
log.Fatal(err) | ||
log.Print(err) | ||
return exitConfig | ||
} else if err = client.ValidateCredentials(ctx); err != nil { | ||
log.Print(err) | ||
return exitConfig | ||
} | ||
|
||
log.Print("listening on", *addr) | ||
mp, err := proxy.NewMultiplexer(client, defaultHoneyCombURL) | ||
if err != nil { | ||
panic(err) | ||
log.Print(err) | ||
return exitInternal | ||
} | ||
|
||
srv, err := http.NewServer(*addr, mp) | ||
if err != nil { | ||
log.Print(err) | ||
return exitInternal | ||
} | ||
defer func() { | ||
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), time.Second*5) | ||
defer shutdownCancel() | ||
|
||
if shutdownErr := srv.Shutdown(shutdownCtx); shutdownErr != nil { | ||
log.Print(shutdownErr) | ||
} | ||
}() | ||
|
||
srv.Run(ctx) | ||
|
||
log.Print("listening on ", srv.ListenAddr().String()) | ||
|
||
select { | ||
case <-ctx.Done(): | ||
log.Print("received interrupt, exiting gracefully") | ||
case err := <-srv.ListenError(): | ||
log.Print("error starting http server, exiting gracefully: ", err) | ||
return exitInternal | ||
} | ||
|
||
server := http.Server{Handler: mp, Addr: *addr} | ||
log.Fatal(server.ListenAndServe()) | ||
return exitOK | ||
} |
Oops, something went wrong.