Skip to content

Commit

Permalink
Go 1.17 enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmalkmus committed Sep 8, 2021
1 parent 82853df commit 8993a18
Show file tree
Hide file tree
Showing 13 changed files with 404 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main

env:
GOVERSION: "1.16"
GOVERSION: "1.17"

jobs:
lint:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main

env:
GOVERSION: "1.16"
GOVERSION: "1.17"

jobs:
lint:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- "*"

env:
GOVERSION: "1.16"
GOVERSION: "1.17"

jobs:
release:
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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-syslog-proxy /usr/bin/axiom-syslog-proxy
Expand Down
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ GOLANGCI_LINT := bin/golangci-lint
GORELEASER := bin/goreleaser
GOTESTSUM := bin/gotestsum

GOTOOLS := $(shell cat tools.go | grep "_ \"" | awk '{ print $$2 }' | tr -d '"')

# MISC
COVERPROFILE := coverage.out
DIST_DIR := dist
Expand Down Expand Up @@ -62,12 +64,12 @@ build: $(GORELEASER) dep.stamp $(call go-pkg-sourcefiles, ./...) ## Build the bi
.PHONY: clean
clean: ## Remove build and test artifacts
@echo ">> cleaning up artifacts"
@rm -rf bin $(DIST_DIR) $(COVERPROFILE)
@rm -rf bin $(DIST_DIR) $(COVERPROFILE) dep.stamp

.PHONY: cover
cover: $(COVERPROFILE) ## Calculate the code coverage score
.PHONY: coverage
coverage: $(COVERPROFILE) ## Calculate the code coverage score
@echo ">> calculating code coverage"
@$(GO) tool cover -func=$(COVERPROFILE) | tail -n1
@$(GO) tool cover -func=$(COVERPROFILE) | grep total | awk '{print $$3}'

.PHONY: dep-clean
dep-clean: ## Remove obsolete dependencies
Expand All @@ -80,6 +82,9 @@ dep-upgrade: ## Upgrade all direct dependencies to their latest version
@$(GO) get -d $(shell $(GO) list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all)
@make dep

.PHONY: dep-upgrade-tools
dep-upgrade-tools: $(GOTOOLS) ## Upgrade all tool dependencies to their latest version and install them

.PHONY: dep
dep: dep-clean dep.stamp ## Install and verify dependencies and remove obsolete ones

Expand Down Expand Up @@ -138,3 +143,8 @@ $(GORELEASER): dep.stamp $(call go-pkg-sourcefiles, github.com/goreleaser/gorele
$(GOTESTSUM): dep.stamp $(call go-pkg-sourcefiles, gotest.tools/gotestsum)
@echo ">> installing gotestsum"
@$(GO) install gotest.tools/gotestsum

$(GOTOOLS): dep.stamp $(call go-pkg-sourcefiles, $@)
@echo ">> installing $@"
@$(GO) get -d $@
@$(GO) install $@
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,21 @@ Docker images are available on [DockerHub][docker].

## Usage

1. Set the following environment variables:
1. Set the following environment variables to connect to Axiom Cloud:

* `AXIOM_TOKEN`: **Personal Access** or **Ingest** token. Can be
created under `Profile` or `Settings > Ingest Tokens`. For security reasons
it is advised to use an Ingest Token with minimal privileges only.
* `AXIOM_DATASET`: Dataset to ingest into.
* `AXIOM_TOKEN`: **Personal Access** or **Ingest** token. Can be created under
`Profile` or `Settings > Ingest Tokens`. For security reasons it is advised to
use an Ingest Token with minimal privileges only.
* `AXIOM_ORG_ID`: The organization identifier of the organization to use
* `AXIOM_DATASET`: Dataset to ship the logs to

When using Axiom Selfhost:

* `AXIOM_URL`: URL of the Axiom deployment to use.
* `AXIOM_TOKEN`: **Personal Access** or **Ingest** token. Can be created under
`Profile` or `Settings > Ingest Tokens`. For security reasons it is advised to
use an Ingest Token with minimal privileges only.
* `AXIOM_URL`: URL of the Axiom deployment to use
* `AXIOM_DATASET`: Dataset to ship the logs to

2. Run it: `./axiom-syslog-proxy` or using Docker:

Expand Down
59 changes: 43 additions & 16 deletions cmd/axiom-syslog-proxy/main.go
Original file line number Diff line number Diff line change
@@ -1,52 +1,79 @@
package main

import (
"context"
"flag"
"log"
"os"
"os/signal"
"syscall"

"github.com/axiomhq/axiom-go/axiom"
"github.com/axiomhq/pkg/version"

"github.com/axiomhq/axiom-syslog-proxy/server"
)

var (
deploymentURL = os.Getenv("AXIOM_URL")
ingestToken = os.Getenv("AXIOM_TOKEN")
ingestDataset = os.Getenv("AXIOM_DATASET")
const (
exitOK int = iota
exitConfig
exitInternal
)

var (
addrTCP = flag.String("addr-tcp", ":601", "Listen address <ip>:<port>")
addrUDP = flag.String("addr-udp", ":514", "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-syslog-proxy version ", version.Release())

flag.Parse()

if deploymentURL == "" {
deploymentURL = axiom.CloudURL
}
if ingestToken == "" {
log.Fatal("missing AXIOM_TOKEN")
ctx, cancel := signal.NotifyContext(context.Background(),
os.Interrupt,
os.Kill,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGQUIT,
)
defer cancel()

dataset := os.Getenv("AXIOM_DATASET")
if dataset == "" {
log.Print("AXIOM_DATASET is required")
return exitConfig
}
if ingestDataset == "" {
log.Fatal("missing AXIOM_DATASET")

client, err := axiom.NewClient()
if err != nil {
log.Print(err)
return exitConfig
} else if err = client.ValidateCredentials(ctx); err != nil {
log.Print(err)
return exitConfig
}

config := &server.Config{
URL: deploymentURL,
Dataset: ingestDataset,
Token: ingestToken,
Dataset: dataset,
AddrUDP: *addrUDP,
AddrTCP: *addrTCP,
}

srv, err := server.NewServer(config)
srv, err := server.NewServer(client, config)
if err != nil {
log.Fatal(err)
log.Print(err)
return exitInternal
}

srv.Run()

return exitOK
}
Loading

0 comments on commit 8993a18

Please sign in to comment.