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

cmd/nsqlookup-proxy: replace log use of segmnetio/events #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 17 additions & 15 deletions cmd/nsqlookup-proxy/main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package main

import (
"log/slog"
"net"
"net/http"
"os"
"strings"
"time"

"github.com/segmentio/conf"
"github.com/segmentio/events"
_ "github.com/segmentio/events/ecslogs"
"github.com/segmentio/events/httpevents"
_ "github.com/segmentio/events/text"
"github.com/segmentio/events/v2/httpevents"
nsq "github.com/segmentio/nsq-go"
"github.com/segmentio/nsq-go/nsqlookup"
)
Expand All @@ -35,8 +33,12 @@ func main() {
}

args := conf.Load(&config)
events.DefaultLogger.EnableDebug = config.Debug
events.DefaultLogger.EnableSource = config.Debug
if config.Debug {
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
Level: slog.LevelDebug,
AddSource: true,
})))
}

var transport http.RoundTripper = http.DefaultTransport
if config.Verbose {
Expand All @@ -46,10 +48,10 @@ func main() {
switch len(args) {
case 1:
case 0:
events.Log("missing registry endpoint")
slog.Info("missing registry endpoint")
os.Exit(1)
default:
events.Log("too many registry endpoints: %{endpoints}v", args)
slog.Info("too many registry endpoints", "endponts", args)
os.Exit(1)
}

Expand All @@ -58,37 +60,37 @@ func main() {

switch protocol {
case "consul":
events.Log("using consul registry at %{address}s", address)
slog.Info("using consul registry", "address", address)
registry = &nsqlookup.ConsulRegistry{
Address: address,
Transport: transport,
}
case "":
events.Log("using local registry mapping %{service}s to %{address}s", nsqlookupd, address)
slog.Info("using local registry mapping", "service", nsqlookupd, "address", address)
registry = nsqlookup.LocalRegistry{
nsqlookupd: {address},
}
default:
events.Log("unknown registry: %{protocol}s://%{address}s", protocol, address)
slog.Error("unknown registry", "protocol", protocol, "address", address)
os.Exit(1)
}

var topology nsqlookup.SubnetTopology
for subnet, zone := range config.Topology {
_, cidr, err := net.ParseCIDR(subnet)
if err != nil {
events.Log("error parsing %{subnet}s subnet: %{error}v", subnet, err)
slog.Warn("error parsing subnet", "subnet", subnet, "err", err)
continue
}
topology = append(topology, nsqlookup.Subnet{
CIDR: cidr,
Zone: zone,
})
events.Log("configuring network topology with %{cidr}s subnet in zone %{zone}s", cidr, zone)
slog.Info("configuring network topology with specified subnet", "cidr", cidr, "zone", zone)
}

for _, topic := range config.ZoneAwareTopics {
events.Log("applying zone restriction to topic %{topic}s", topic)
slog.Info("applying zone restriction to topic", "topic", topic)
}

var proxy = &nsqlookup.ProxyEngine{
Expand All @@ -114,7 +116,7 @@ func main() {
handler = httpevents.NewHandler(handler)
}

events.Log("starting nsqlookup-proxy listening on %{address}s", config.Bind)
slog.Info("starting nsqlookup-proxy", "listen_address", config.Bind)
http.ListenAndServe(config.Bind, handler)
}

Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ module github.com/segmentio/nsq-go
go 1.11

require (
github.com/pkg/errors v0.8.0
github.com/pkg/errors v0.9.1
github.com/segmentio/conf v1.0.0
github.com/segmentio/events v2.1.0+incompatible
github.com/segmentio/events/v2 v2.6.0
github.com/segmentio/go-snakecase v1.0.0 // indirect
github.com/segmentio/objconv v1.0.1 // indirect
github.com/segmentio/timers v0.0.0-20180605162245-8ad1428b010e
golang.org/x/sys v0.15.0 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/mold.v2 v2.2.0 // indirect
gopkg.in/validator.v2 v2.0.0-20180514200540-135c24b11c19 // indirect
Expand Down
14 changes: 10 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/segmentio/asm v1.1.3/go.mod h1:Ld3L4ZXGNcSLRg4JBsZ3//1+f/TjYl0Mzen/DQy1EJg=
github.com/segmentio/conf v1.0.0 h1:oRF4BtoJbI/+I7fUngYMnMcKFbjqVUFi8hv4Pp0l88w=
github.com/segmentio/conf v1.0.0/go.mod h1:y0VyxYAlU2slxCjm7XX7tGKFlN39bwHCZrbOpCcLsr8=
github.com/segmentio/events v2.1.0+incompatible h1:7ns47dgRJMt/JgIXrNU0MiD/NtCGa55lKzWP15dcGnM=
github.com/segmentio/events v2.1.0+incompatible/go.mod h1:npQUbmKYO33tlRpaQNZjgD2mXv0fb2hbOH0CNVs6g2Y=
github.com/segmentio/encoding v0.3.6/go.mod h1:n0JeuIqEQrQoPDGsjo8UNd1iA0U8d8+oHAA4E3G3OxM=
github.com/segmentio/events/v2 v2.6.0 h1:MRPhHWwfLGFjkppjkdCDw2DZVBMyMb/JcBVnDVVNdzc=
github.com/segmentio/events/v2 v2.6.0/go.mod h1:oDngvacuvZ/bPnAq8VKNzvk8ICS1pVVEtQESVcvSL/w=
github.com/segmentio/go-snakecase v1.0.0 h1:FSeHpP0sBL3O+MCpxvQZrS5a51WAki6gposZuwVE9L4=
github.com/segmentio/go-snakecase v1.0.0/go.mod h1:jk1miR5MS7Na32PZUykG89Arm+1BUSYhuGR6b7+hJto=
github.com/segmentio/objconv v1.0.1 h1:QjfLzwriJj40JibCV3MGSEiAoXixbp4ybhwfTB8RXOM=
github.com/segmentio/objconv v1.0.1/go.mod h1:auayaH5k3137Cl4SoXTgrzQcuQDmvuVtZgS0fb1Ahys=
github.com/segmentio/timers v0.0.0-20180605162245-8ad1428b010e h1:GNlZqttb0RQTUYTYnSwAMyqgHzYouBGVImRJp8Y43Hg=
github.com/segmentio/timers v0.0.0-20180605162245-8ad1428b010e/go.mod h1:/6SKE4F6LzTh32hPOJs0KRJ7MHHWpTZ7wb4PxdjgzaQ=
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
Expand Down