-
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
ec1129a
commit 550f0b0
Showing
10 changed files
with
457 additions
and
163 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 |
---|---|---|
|
@@ -6,7 +6,7 @@ on: | |
- "*" | ||
|
||
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
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-loki-proxy /usr/bin/axiom-loki-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,45 +1,88 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"log" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/axiomhq/axiom-go/axiom" | ||
xhttp "github.com/axiomhq/pkg/http" | ||
"github.com/axiomhq/pkg/version" | ||
|
||
httpProxy "github.com/axiomhq/axiom-loki-proxy/http" | ||
) | ||
|
||
var ( | ||
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 | ||
) | ||
|
||
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-loki-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 | ||
} | ||
|
||
mux := http.NewServeMux() | ||
mux.Handle("/loki/api/v1/push", httpProxy.NewPushHandler(client)) | ||
|
||
log.Print("listening on", *addr) | ||
srv, err := xhttp.NewServer(*addr, mux) | ||
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: mux, Addr: *addr} | ||
log.Fatal(server.ListenAndServe()) | ||
return exitOK | ||
} |
Oops, something went wrong.