Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch default alog.Logger back to a mutex #226

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions build/deploy/atlas/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
atlas-api:
image: ghcr.io/thingspect/atlas:e29ff1eb
image: ghcr.io/thingspect/atlas:2a02e705
command: atlas-api
restart: on-failure
ports:
Expand All @@ -22,7 +22,7 @@ services:
- API_LORA_DEV_PROF_ID=00000000-0000-0000-0000-000000000000

atlas-mqtt-ingestor:
image: ghcr.io/thingspect/atlas:e29ff1eb
image: ghcr.io/thingspect/atlas:2a02e705
command: atlas-mqtt-ingestor
restart: on-failure
depends_on:
Expand All @@ -34,7 +34,7 @@ services:
- MQTT_INGEST_NSQ_PUB_ADDR=nsqd:4150

atlas-lora-ingestor:
image: ghcr.io/thingspect/atlas:e29ff1eb
image: ghcr.io/thingspect/atlas:2a02e705
command: atlas-lora-ingestor
restart: on-failure
depends_on:
Expand All @@ -47,7 +47,7 @@ services:
- LORA_INGEST_NSQ_PUB_ADDR=nsqd:4150

atlas-decoder:
image: ghcr.io/thingspect/atlas:e29ff1eb
image: ghcr.io/thingspect/atlas:2a02e705
command: atlas-decoder
restart: on-failure
depends_on:
Expand All @@ -60,7 +60,7 @@ services:
- DECODER_NSQ_LOOKUP_ADDRS=nsqlookupd:4161

atlas-validator:
image: ghcr.io/thingspect/atlas:e29ff1eb
image: ghcr.io/thingspect/atlas:2a02e705
command: atlas-validator
restart: on-failure
depends_on:
Expand All @@ -74,7 +74,7 @@ services:
- VALIDATOR_NSQ_LOOKUP_ADDRS=nsqlookupd:4161

atlas-accumulator:
image: ghcr.io/thingspect/atlas:e29ff1eb
image: ghcr.io/thingspect/atlas:2a02e705
command: atlas-accumulator
restart: on-failure
environment:
Expand All @@ -84,7 +84,7 @@ services:
- ACCUMULATOR_NSQ_LOOKUP_ADDRS=nsqlookupd:4161

atlas-eventer:
image: ghcr.io/thingspect/atlas:e29ff1eb
image: ghcr.io/thingspect/atlas:2a02e705
command: atlas-eventer
restart: on-failure
depends_on:
Expand All @@ -96,7 +96,7 @@ services:
- EVENTER_NSQ_LOOKUP_ADDRS=nsqlookupd:4161

atlas-alerter:
image: ghcr.io/thingspect/atlas:e29ff1eb
image: ghcr.io/thingspect/atlas:2a02e705
command: atlas-alerter
restart: on-failure
environment:
Expand Down
29 changes: 14 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
module github.com/thingspect/atlas

go 1.21.0
go 1.21.1

require (
github.com/NYTimes/gziphandler v1.1.1
github.com/antonmedv/expr v1.14.3
github.com/chirpstack/chirpstack/api/go/v4 v4.4.3
github.com/antonmedv/expr v1.15.2
github.com/chirpstack/chirpstack/api/go/v4 v4.5.0
github.com/eclipse/paho.mqtt.golang v1.4.3
github.com/google/uuid v1.3.1
github.com/gregdel/pushover v1.2.1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.2
github.com/gregdel/pushover v1.3.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0
github.com/jackc/pgx/v5 v5.4.3
github.com/jellydator/ttlcache/v3 v3.0.1
github.com/jellydator/ttlcache/v3 v3.1.0
github.com/mennanov/fmutils v0.2.0
github.com/nsqio/go-nsq v1.1.0
github.com/redis/go-redis/v9 v9.1.0
github.com/smira/go-statsd v1.3.2
github.com/stretchr/testify v1.8.4
github.com/thingspect/api/go v1.0.14
go.uber.org/mock v0.2.0
golang.org/x/crypto v0.12.0
google.golang.org/grpc v1.57.0
golang.org/x/crypto v0.13.0
google.golang.org/grpc v1.58.0
google.golang.org/protobuf v1.31.0
)

Expand All @@ -34,15 +34,14 @@ require (
github.com/gorilla/websocket v1.5.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/genproto v0.0.0-20230821184602-ccc8af3d0e93 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230821184602-ccc8af3d0e93 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230821184602-ccc8af3d0e93 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230911183012-2d3300fd4832 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230911183012-2d3300fd4832 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230911183012-2d3300fd4832 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
1,045 changes: 1,012 additions & 33 deletions go.sum

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions pkg/alog/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package alog

import (
"fmt"
"sync/atomic"
"sync"
)

// logger is an atomic value of type Logger.
var logger atomic.Value
// Since logger is global and may be replaced, locking is required.
var (
logger Logger
loggerMu sync.Mutex
)

// NewConsole returns a new Logger with console formatting at the specified
// level.
Expand All @@ -21,17 +24,17 @@ func NewJSON(level string) Logger {

// Default returns the default logger, which is thread-safe.
func Default() Logger {
l, ok := logger.Load().(Logger)
if !ok {
panic("Default logger.Load: false")
}
loggerMu.Lock()
defer loggerMu.Unlock()

return l
return logger
}

// SetDefault sets a new default logger.
func SetDefault(l Logger) {
logger.Store(l)
loggerMu.Lock()
logger = l
loggerMu.Unlock()
}

// WithField returns a derived Logger from the default Logger with a string
Expand Down
16 changes: 8 additions & 8 deletions pkg/alog/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ import (
)

func TestDefault(t *testing.T) {
logger := Default()
t.Logf("logger: %#v", logger)
logDef := Default()
t.Logf("logDef: %#v", logDef)

for i := 0; i < 5; i++ {
lTest := i

t.Run(fmt.Sprintf("Can log %v", lTest), func(t *testing.T) {
t.Parallel()

logger.Debug("Debug")
logger.Debugf("Debugf: %v", lTest)
logger.Info("Info")
logger.Infof("Infof: %v", lTest)
logger.Error("Error")
logger.Errorf("Errorf: %v", lTest)
logDef.Debug("Debug")
logDef.Debugf("Debugf: %v", lTest)
logDef.Info("Info")
logDef.Infof("Infof: %v", lTest)
logDef.Error("Error")
logDef.Errorf("Errorf: %v", lTest)
// Do not test Fatal* due to os.Exit.
})
}
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/antonmedv/expr/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions vendor/github.com/antonmedv/expr/SECURITY.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions vendor/github.com/antonmedv/expr/ast/func.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions vendor/github.com/antonmedv/expr/ast/node.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions vendor/github.com/antonmedv/expr/ast/print.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/antonmedv/expr/ast/visitor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading