Skip to content

Commit

Permalink
feat: Zerolog writers for axiom.co & fluent-bit
Browse files Browse the repository at this point in the history
Signed-off-by: jay-dee7 <me@jsdp.dev>
  • Loading branch information
jay-dee7 committed Oct 24, 2023
1 parent dff53ae commit 12dc89a
Show file tree
Hide file tree
Showing 16 changed files with 611 additions and 358 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ config.yml.bak
*.cert
*.log
*.DS_Store
*.test
telemetry/*.yml
2 changes: 0 additions & 2 deletions auth/jwt_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/containerish/OpenRegistry/store/v2/types"
"github.com/fatih/color"
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
echo_jwt "github.com/labstack/echo-jwt/v4"
Expand Down Expand Up @@ -110,7 +109,6 @@ func (a *auth) ACL() echo.MiddlewareFunc {
}

username := ctx.Param("username")
color.Cyan("user claims - username: %s - claims: %s", username, claims.ID)

user, err := a.pgStore.GetUserByID(ctx.Request().Context(), uuid.MustParse(claims.ID))
if err != nil {
Expand Down
15 changes: 7 additions & 8 deletions cmd/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/containerish/OpenRegistry/store/v2/users"
"github.com/containerish/OpenRegistry/store/v2/webauthn"
"github.com/containerish/OpenRegistry/telemetry"
fluentbit "github.com/containerish/OpenRegistry/telemetry/fluent-bit"
"github.com/containerish/OpenRegistry/telemetry/otel"
"github.com/containerish/OpenRegistry/vcs/github"
"github.com/fatih/color"
"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -67,13 +67,7 @@ func RunRegistryServer(ctx *cli.Context) {
os.Exit(1)
}

fluentBitCollector, err := fluentbit.New(cfg)
if err != nil {
color.Red("error initializing fluentbit collector: %s\n", err)
os.Exit(1)
}

logger := telemetry.ZLogger(fluentBitCollector, cfg.Environment)
logger := telemetry.ZLogger(cfg.Environment, cfg.Telemetry)
e := echo.New()

rawDB := store_v2.NewDB(cfg.StoreConfig, cfg.Environment)
Expand Down Expand Up @@ -141,6 +135,11 @@ func RunRegistryServer(ctx *cli.Context) {
}()
}

otelShutdownFunc := otel.ConfigureOtel(cfg.Telemetry, "openregistry-api", e)
if otelShutdownFunc != nil {
defer otelShutdownFunc()
}

color.Red("error initialising OpenRegistry Server: %s", buildHTTPServer(cfg, e))
}

Expand Down
49 changes: 37 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import (

type (
OpenRegistryConfig struct {
WebAppConfig WebAppConfig `yaml:"web_app" mapstructure:"web_app"`
OAuth OAuth `yaml:"oauth" mapstructure:"oauth" validate:"-"`
StoreConfig Store `yaml:"database" mapstructure:"database" validate:"required"`
LogConfig Log `yaml:"log_service" mapstructure:"log_service"`
Email Email `yaml:"email" mapstructure:"email" validate:"-"`
WebAppConfig WebAppConfig `yaml:"web_app" mapstructure:"web_app"`
Integrations Integrations `yaml:"integrations" mapstructure:"integrations"`
Registry Registry `yaml:"registry" mapstructure:"registry" validate:"required"`
Telemetry Telemetry `yaml:"telemetry" mapstructure:"telemetry"`
StoreConfig Store `yaml:"database" mapstructure:"database" validate:"required"`
DFS DFS `yaml:"dfs" mapstructure:"dfs"`
WebAuthnConfig WebAuthnConfig `yaml:"web_authn_config" mapstructure:"web_authn_config"`
Environment Environment `yaml:"environment" mapstructure:"environment" validate:"required"`
Expand Down Expand Up @@ -87,15 +87,6 @@ type (
Enabled bool `yaml:"enabled" mapstructure:"enabled"`
}

Log struct {
Service string `yaml:"name" mapstructure:"name"`
Endpoint string `yaml:"endpoint" mapstructure:"endpoint"`
AuthMethod string `yaml:"auth_method" mapstructure:"auth_method"`
Username string `yaml:"username" mapstructure:"username"`
Password string `yaml:"password" mapstructure:"password"`
Enabled bool `yaml:"enabled" mapstructure:"enabled"`
}

Store struct {
Kind StoreKind `yaml:"kind" mapstructure:"kind" validate:"required"`
User string `yaml:"username" mapstructure:"username" validate:"required"`
Expand Down Expand Up @@ -155,6 +146,40 @@ type (
JWTSigningPubKey *rsa.PublicKey `yaml:"pub_key" mapstructure:"pub_key"`
Enabled bool `yaml:"enabled" mapstructure:"enabled"`
}

Otel struct {
Enabled bool `yaml:"enabled" mapstructure:"enabled"`
}

AxiomConfig struct {
Dataset string `yaml:"dataset" mapstructure:"dataset"`
APIKey string `yaml:"api_key" mapstructure:"api_key"`
OrganizationID string `yaml:"organization" mapstructure:"organization"`
Enabled bool `yaml:"enabled" mapstructure:"enabled"`
}

FluentBitConfig struct {
Endpoint string `yaml:"endpoint" mapstructure:"endpoint"`
AuthMethod string `yaml:"auth_method" mapstructure:"auth_method"`
Username string `yaml:"username" mapstructure:"username"`
Password string `yaml:"password" mapstructure:"password"`
Enabled bool `yaml:"enabled" mapstructure:"enabled"`
}

Logging struct {
Axiom AxiomConfig `yaml:"axiom" mapstructure:"axiom"`
Level string `yaml:"level" mapstructure:"level"`
FluentBit FluentBitConfig `yaml:"fluent_bit" mapstructure:"fluent_bit"`
Pretty bool `yaml:"pretty" mapstructure:"pretty"`
RemoteForwarding bool `yaml:"remote_forwarding" mapstructure:"remote_forwarding"`
Enabled bool `yaml:"enabled" mapstructure:"enabled"`
}

Telemetry struct {
Logging Logging `yaml:"logging" mapstructure:"logging"`
Otel Otel `yaml:"otel" mapstructure:"otel"`
Enabled bool `yaml:"enabled" mapstructure:"enabled"`
}
)

const (
Expand Down
44 changes: 42 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/aws/aws-sdk-go-v2/config v1.19.0
github.com/aws/aws-sdk-go-v2/credentials v1.13.43
github.com/aws/aws-sdk-go-v2/service/s3 v1.40.2
github.com/axiomhq/axiom-go v0.17.1
github.com/bradleyfalzon/ghinstallation/v2 v2.8.0
github.com/fatih/color v1.15.0
github.com/go-playground/locales v0.14.1
Expand All @@ -18,6 +19,8 @@ require (
github.com/google/go-github/v50 v50.2.0
github.com/google/uuid v1.3.1
github.com/hashicorp/go-multierror v1.1.1
github.com/honeycombio/honeycomb-opentelemetry-go v0.8.1
github.com/honeycombio/otel-config-go v1.12.1
github.com/jackc/pgconn v1.14.1
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
github.com/jackc/pgx/v4 v4.18.1
Expand All @@ -36,38 +39,75 @@ require (
github.com/uptrace/bun/driver/sqliteshim v1.1.16
github.com/urfave/cli/v2 v2.25.7
github.com/valyala/fasttemplate v1.2.2
go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho v0.45.0
golang.org/x/crypto v0.14.0
golang.org/x/oauth2 v0.13.0
gopkg.in/yaml.v2 v2.4.0
storj.io/uplink v1.12.1
)

require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/flynn/noise v1.0.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-webauthn/x v0.1.4 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/google/go-github/v56 v56.0.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jtolio/noiseconn v0.0.0-20230111204749-d7ec1a08b0b8 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sethvargo/go-envconfig v0.9.0 // indirect
github.com/shirou/gopsutil/v3 v3.23.8 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/host v0.44.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.44.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/contrib/instrumentation/runtime v0.44.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.20.0 // indirect
go.opentelemetry.io/contrib/propagators/ot v1.19.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.41.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.41.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.41.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.18.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/sdk v1.18.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.41.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/grpc v1.58.2 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
mellium.im/sasl v0.3.1 // indirect
modernc.org/cc/v3 v3.41.0 // indirect
Expand Down Expand Up @@ -111,7 +151,7 @@ require (
github.com/google/go-github/v53 v53.2.0
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/go-tpm v0.9.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
Expand Down
Loading

0 comments on commit 12dc89a

Please sign in to comment.