Skip to content

Commit

Permalink
Metrics & Tracing (topi314#21)
Browse files Browse the repository at this point in the history
* idk tracing?

* working traces lol

* use otelchi & add metrics

* update modules

* add db system

* update deps

* update deps

* format imports

* use slog

* update var names

* add trace id to logs

* update go version

* fix log level & type

* add span id to log

* add sql args to traces

* move logs into config

* Update docker.yml
  • Loading branch information
topi314 authored May 20, 2023
1 parent f465db7 commit 1ab053b
Show file tree
Hide file tree
Showing 24 changed files with 638 additions and 147 deletions.
1 change: 0 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Deploy
if: github.ref == 'refs/heads/master'
uses: fjogeleit/http-request-action@v1
with:
url: "https://watchtower.topi.wtf/v1/update?image=ghcr.io/topisenpai/gobin"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.x
go-version: 1.20.x
cache: true

- name: File Extension Windows
Expand All @@ -47,7 +47,7 @@ jobs:
CGO_ENABLED=0
GOOS=${{ matrix.goos }}
GOARCH=${{ matrix.goarch }}
go build -ldflags="-X 'main.version=${{ env.VERSION }}' -X 'main.commit=${{ env.COMMIT }}' -X 'main.buildTime=${{ env.BUILD_TIME }}'" -o dist/gobin-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.file_name }} github.com/topisenpai/gobin/cli
go build -ldflags="-X 'main.Version=${{ env.VERSION }}' -X 'main.Commit=${{ env.COMMIT }}' -X 'main.BuildTime=${{ env.BUILD_TIME }}'" -o dist/gobin-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.file_name }} github.com/topisenpai/gobin/cli
- name: Upload
uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 \
GOOS=$TARGETOS \
GOARCH=$TARGETARCH \
go build -ldflags="-X 'main.version=$VERSION' -X 'main.commit=$COMMIT' -X 'main.buildTime=$BUILD_TIME'" -o gobin-server github.com/topisenpai/gobin
go build -ldflags="-X 'main.Version=$VERSION' -X 'main.Commit=$COMMIT' -X 'main.BuildTime=$BUILD_TIME'" -o gobin-server github.com/topisenpai/gobin

FROM alpine

Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,18 @@ Create a new `gobin.json` file with the following content:

```yml
{
"dev_mode": false,
"log": {
# log level, either "debug", "info", "warn" or "error"
"level": "info",
# log format, either "json" or "text"
"format": "text",
# whether to add the source file and line to the log output
"add_source": false
},
# enable or disable debug profiler endpoint
"debug": false,
# enable or disable hot reload of templates and assets
"dev_mode": false,
"listen_addr": "0.0.0.0:80",
# secret for jwt tokens, replace with a long random string
"jwt_secret": "...",
Expand Down Expand Up @@ -200,8 +210,12 @@ Alternatively you can use environment variables to configure gobin. The environm
<summary>Here is a list of all environment variables</summary>

```env
GOBIN_DEV_MODE=false
GOBIN_LOG_LEVEL=info
GOBIN_LOG_FORMAT=text
GOBIN_LOG_ADD_SOURCE=false
GOBIN_DEBUG=false
GOBIN_DEV_MODE=false
GOBIN_LISTEN_ADDR=0.0.0.0:80
GOBIN_JWT_SECRET=...
Expand Down
11 changes: 7 additions & 4 deletions cli/main.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package main

import (
"time"

"github.com/topisenpai/gobin/cmd"
"github.com/topisenpai/gobin/gobin"
)

// These variables are set via the -ldflags option in go build
var (
version = "unknown"
commit = "unknown"
buildTime = "unknown"
Version = "unknown"
Commit = "unknown"
BuildTime = "unknown"
)

func main() {
rootCmd := cmd.NewRootCmd()
cmd.NewGetCmd(rootCmd)
cmd.NewPushCmd(rootCmd)
cmd.NewRmCmd(rootCmd)
cmd.NewVersionCmd(rootCmd, gobin.FormatBuildVersion(version, commit, buildTime))
buildTime, _ := time.Parse(time.RFC3339, BuildTime)
cmd.NewVersionCmd(rootCmd, gobin.FormatBuildVersion(Version, Commit, buildTime))
cmd.NewCompletionCmd(rootCmd)
cmd.Execute(rootCmd)
}
2 changes: 0 additions & 2 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import (
"time"

"github.com/dustin/go-humanize"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/topisenpai/gobin/gobin"
"github.com/topisenpai/gobin/internal/ezhttp"
)
Expand Down
1 change: 0 additions & 1 deletion cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/topisenpai/gobin/gobin"
"github.com/topisenpai/gobin/internal/cfg"
"github.com/topisenpai/gobin/internal/ezhttp"
Expand Down
1 change: 0 additions & 1 deletion cmd/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/topisenpai/gobin/gobin"
"github.com/topisenpai/gobin/internal/cfg"
"github.com/topisenpai/gobin/internal/ezhttp"
Expand Down
1 change: 0 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/topisenpai/gobin/internal/ezhttp"
)

Expand Down
7 changes: 6 additions & 1 deletion example.gobin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"dev_mode": false,
"log": {
"level": "info",
"format": "text",
"add_source": false
},
"debug": false,
"dev_mode": false,
"listen_addr": ":80",
"jwt_secret": "...",
"database": {
Expand Down
50 changes: 41 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ module github.com/topisenpai/gobin

go 1.20

replace github.com/alecthomas/chroma/v2 => github.com/topisenpai/chroma/v2 v2.0.0-20230324233532-b14d693aac4a
replace (
github.com/alecthomas/chroma/v2 => github.com/topisenpai/chroma/v2 v2.0.0-20230324233532-b14d693aac4a
github.com/riandyrn/otelchi => github.com/TopiSenpai/otelchi v0.0.0-20230502153208-000734fa627a
)

require (
github.com/alecthomas/chroma/v2 v2.5.0
github.com/XSAM/otelsql v0.22.0
github.com/alecthomas/chroma/v2 v2.7.0
github.com/dustin/go-humanize v1.0.1
github.com/go-chi/chi/v5 v5.0.8
github.com/go-chi/httprate v0.7.4
Expand All @@ -14,17 +18,33 @@ require (
github.com/jackc/pgx/v5 v5.3.1
github.com/jmoiron/sqlx v1.3.5
github.com/mitchellh/mapstructure v1.5.0
github.com/prometheus/client_golang v1.15.1
github.com/riandyrn/otelchi v0.5.1
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53
go.opentelemetry.io/otel v1.15.1
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.15.1
go.opentelemetry.io/otel/exporters/prometheus v0.38.1
go.opentelemetry.io/otel/metric v0.38.1
go.opentelemetry.io/otel/sdk v1.15.1
go.opentelemetry.io/otel/sdk/metric v0.38.1
go.opentelemetry.io/otel/trace v1.15.1
golang.org/x/exp v0.0.0-20230519143937-03e91628a987
modernc.org/sqlite v1.22.1
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dlclark/regexp2 v1.9.0 // indirect
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20200511160909-eb529947af53 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
Expand All @@ -34,24 +54,36 @@ require (
github.com/lib/pq v1.10.7 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.43.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/crypto v0.8.0 // indirect
go.opentelemetry.io/contrib v1.16.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.15.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.15.1 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.8.0 // indirect
golang.org/x/tools v0.9.1 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
modernc.org/cc/v3 v3.40.0 // indirect
modernc.org/ccgo/v3 v3.16.13 // indirect
modernc.org/libc v1.22.5 // indirect
modernc.org/libc v1.22.6 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/opt v0.1.3 // indirect
Expand Down
Loading

0 comments on commit 1ab053b

Please sign in to comment.