From 925c3f34a95534762720dbf630a95a03002c3f50 Mon Sep 17 00:00:00 2001 From: Ryan D McGuire Date: Thu, 14 Aug 2025 15:58:46 -0400 Subject: [PATCH] refactors air.toml configuration, updates Go dependencies, and improves application startup telemetry and signal handling. --- .air.toml | 64 +++++++++---------------------------------------------- go.mod | 2 +- go.sum | 28 ------------------------ main.go | 9 ++++++-- 4 files changed, 18 insertions(+), 85 deletions(-) diff --git a/.air.toml b/.air.toml index 71244cc..6bf0429 100644 --- a/.air.toml +++ b/.air.toml @@ -1,80 +1,36 @@ # .air.toml -# -# A configuration file for the 'air' live-reloading tool. -# This configuration is tailored for a Go project that needs to be run with specific command-line flags -# and requires graceful handling of system signals like SIGINT and SIGTERM. -# -# To use: -# 1. Install air: `go install github.com/cosmtrek/air@latest` -# 2. Place this file, renamed to `.air.toml`, in the root of your project. -# 3. Run `air` from your terminal in the project root. -# The root directory of your project to watch for changes. -# '.' indicates the current directory where air is run. +# Root directory of the project root = "." -# A temporary directory for air to store its build artifacts. -# You should add this directory to your .gitignore file. +# Directory for temporary build artifacts tmp_dir = "tmp" [build] -# Step 1: Build the Go binary and place it in the tmp directory. -# Step 2: Copy the configuration file into the tmp directory as well. -# This ensures all runtime assets are in one place. -cmd = "go build -o ./tmp/main . && cp config.yaml ./tmp/" +cmd = "go build -o tmp/main ." +bin = "tmp/main" +args_bin = ["-config", "config.yaml"] -# The 'full_bin' command gives us complete control over how the app is run. -# We first change the directory to 'tmp' so that the application's working -# directory is where the binary and its config file are located. -# Then, we execute the binary, pointing it to the config file in the same directory. -full_bin = "cd ./tmp && ./main -config config.yaml" - -# A list of directories to watch for file changes. -# Air will recursively watch these directories. -include_dir = ["."] - -# A list of file extensions to watch. -# Air will restart when any of these files change. +# Extensions to watch include_ext = ["go", "toml", "yaml", "yml"] -# A list of directories to ignore. -# It's good practice to ignore temporary directories, vendor folders, and git history. -exclude_dir = ["tmp", "vendor", ".git", "proto"] - -# A list of specific files to ignore. -exclude_file = [] - -# A list of regular expressions to exclude files or directories. +# Ignore temp folders and irrelevant dirs +exclude_dir = ["tmp", "vendor", ".git", "cmd", "proto"] exclude_regex = ["_test.go"] -# A list of files or directories to watch that are not in the 'include_dir'. -# Useful for watching template files if they are outside your main source directories. -include_file = [] - -# This setting is crucial for graceful shutdowns. -# It stops the running process on a file change before building and restarting. -# This ensures that your application's shutdown logic is triggered. +# Stop process on error and send interrupt for graceful shutdown stop_on_error = true - -# Send SIGINT (Ctrl+C) to the running process before killing it. -# This is essential for allowing your application to handle the signal and shut down gracefully. send_interrupt = true - -# The delay in milliseconds to wait for the process to shut down gracefully after sending SIGINT. -# If your app needs more time for cleanup, you can increase this value. -kill_delay = 500 # ms +kill_delay = 500 [log] -# Show timestamps in the log output. time = true [color] -# Customize colors for different parts of the air output. main = "magenta" watcher = "cyan" build = "yellow" runner = "green" [misc] -# Delete the temporary binary file on exit. clean_on_exit = true diff --git a/go.mod b/go.mod index 656a269..571a1f1 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,6 @@ require ( github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1 github.com/rs/zerolog v1.34.0 go.opentelemetry.io/otel/trace v1.37.0 - golang.org/x/sys v0.35.0 google.golang.org/genproto/googleapis/api v0.0.0-20250811230008-5f3141c8851a google.golang.org/grpc v1.74.2 google.golang.org/protobuf v1.36.7 @@ -65,6 +64,7 @@ require ( go.opentelemetry.io/proto/otlp v1.7.1 // indirect golang.org/x/exp v0.0.0-20250813145105-42675adae3e6 // indirect golang.org/x/net v0.43.0 // indirect + golang.org/x/sys v0.35.0 // indirect golang.org/x/text v0.28.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250811230008-5f3141c8851a // indirect google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 // indirect diff --git a/go.sum b/go.sum index 0f08b62..54368fa 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,9 @@ -buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250717185734-6c6e0d3c608e.1 h1:Lg6klmCi3v7VvpqeeLEER9/m5S8y9e9DjhqQnSCNy4k= -buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250717185734-6c6e0d3c608e.1/go.mod h1:avRlCjnFzl98VPaeCtJ24RrV/wwHFzB8sWXhj26+n/U= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.7-20250717185734-6c6e0d3c608e.1 h1:/AZH8sVB6LHv8G+hZlAMCP31NevnesHwYgnlgS5Vt14= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.7-20250717185734-6c6e0d3c608e.1/go.mod h1:eva/VCrd8X7xuJw+JtwCEyrCKiRRASukFqmirnWBvFU= buf.build/go/protovalidate v0.14.0 h1:kr/rC/no+DtRyYX+8KXLDxNnI1rINz0imk5K44ZpZ3A= buf.build/go/protovalidate v0.14.0/go.mod h1:+F/oISho9MO7gJQNYC2VWLzcO1fTPmaTA08SDYJZncA= cel.dev/expr v0.24.0 h1:56OvJKSH3hDGL0ml5uSxZmz3/3Pq4tJ+fb1unVLAFcY= cel.dev/expr v0.24.0/go.mod h1:hLPLo1W4QUmuYdA72RBX06QTs6MXw941piREPl3Yfiw= -gitea.libretechconsulting.com/rmcguire/go-app v0.10.0 h1:Cx3fTaNEEAZQUn6zeg2yXj0CnkBLjf2yrGWX8f/uHzM= -gitea.libretechconsulting.com/rmcguire/go-app v0.10.0/go.mod h1:26ZbEKfhPU4XFWltysJDMhaLJk6qVrUFxhrkoFmv33I= -gitea.libretechconsulting.com/rmcguire/go-app v0.10.2 h1:dwTvWWA2MJUuf8xlakZjqCGZamN3oEVmTLJuCCAQIlc= -gitea.libretechconsulting.com/rmcguire/go-app v0.10.2/go.mod h1:pGjVInL1iiA54lJkQ+V/NGa1RzqVpE6firhfhq7XUmw= gitea.libretechconsulting.com/rmcguire/go-app v0.11.0 h1:IQmZCnr1XFVaw6TvhBmPTfAnvFJMjEcOylSZcCSen5w= gitea.libretechconsulting.com/rmcguire/go-app v0.11.0/go.mod h1:T8K2vbmt0mApScJDGqfmNlvX5gdJSImjArUMpgfYs8U= github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ= @@ -22,8 +16,6 @@ github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E= github.com/bool64/shared v0.1.5/go.mod h1:081yz68YC9jeFB3+Bbmno2RFWvGKv1lPKkMP6MHJlPs= github.com/caarlos0/env/v11 v11.3.1 h1:cArPWC15hWmEt+gWk7YBi7lEXTXCvpaSdCiZE2X5mCA= github.com/caarlos0/env/v11 v11.3.1/go.mod h1:qupehSf/Y0TUTsxKywqRt/vJjN5nz6vauiYEUUr8P4U= -github.com/cenkalti/backoff/v5 v5.0.2 h1:rIfFVxEf1QsI7E1ZHfp/B4DF/6QBAUhmgkxc0H7Zss8= -github.com/cenkalti/backoff/v5 v5.0.2/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM= github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -78,8 +70,6 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.22.0 h1:rb93p9lokFEsctTys46VnV1kLCDpVZ0a/Y92Vm0Zc6Q= -github.com/prometheus/client_golang v1.22.0/go.mod h1:R7ljNsLXhuQXYZYtw6GAE9AZg8Y7vEW5scdCXrWRXC0= github.com/prometheus/client_golang v1.23.0 h1:ust4zpdl9r4trLY/gSjlm07PuiBq2ynaXXlptpfy8Uc= github.com/prometheus/client_golang v1.23.0/go.mod h1:i/o0R9ByOnHX0McrTMTyhYvKE4haaf2mW08I+jGAjEE= github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk= @@ -145,49 +135,31 @@ go.opentelemetry.io/otel/sdk/metric v1.37.0 h1:90lI228XrB9jCMuSdA0673aubgRobVZFh go.opentelemetry.io/otel/sdk/metric v1.37.0/go.mod h1:cNen4ZWfiD37l5NhS+Keb5RXVWZWpRE+9WyVCpbo5ps= go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4= go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0= -go.opentelemetry.io/proto/otlp v1.7.0 h1:jX1VolD6nHuFzOYso2E73H85i92Mv8JQYk0K9vz09os= -go.opentelemetry.io/proto/otlp v1.7.0/go.mod h1:fSKjH6YJ7HDlwzltzyMj036AJ3ejJLCgCSHGj4efDDo= go.opentelemetry.io/proto/otlp v1.7.1 h1:gTOMpGDb0WTBOP8JaO72iL3auEZhVmAQg4ipjOVAtj4= go.opentelemetry.io/proto/otlp v1.7.1/go.mod h1:b2rVh6rfI/s2pHWNlB7ILJcRALpcNDzKhACevjI+ZnE= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -golang.org/x/exp v0.0.0-20250718183923-645b1fa84792 h1:R9PFI6EUdfVKgwKjZef7QIwGcBKu86OEFpJ9nUEP2l4= -golang.org/x/exp v0.0.0-20250718183923-645b1fa84792/go.mod h1:A+z0yzpGtvnG90cToK5n2tu8UJVP2XUATh+r+sfOOOc= golang.org/x/exp v0.0.0-20250813145105-42675adae3e6 h1:SbTAbRFnd5kjQXbczszQ0hdk3ctwYf3qBNH9jIsGclE= golang.org/x/exp v0.0.0-20250813145105-42675adae3e6/go.mod h1:4QTo5u+SEIbbKW1RacMZq1YEfOBqeXa19JeshGi+zc4= -golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs= -golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8= golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE= golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA= -golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= -golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4= -golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU= golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng= golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU= golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U= golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= -google.golang.org/genproto/googleapis/api v0.0.0-20250721164621-a45f3dfb1074 h1:mVXdvnmR3S3BQOqHECm9NGMjYiRtEvDYcqAqedTXY6s= -google.golang.org/genproto/googleapis/api v0.0.0-20250721164621-a45f3dfb1074/go.mod h1:vYFwMYFbmA8vl6Z/krj/h7+U/AqpHknwJX4Uqgfyc7I= google.golang.org/genproto/googleapis/api v0.0.0-20250811230008-5f3141c8851a h1:DMCgtIAIQGZqJXMVzJF4MV8BlWoJh2ZuFiRdAleyr58= google.golang.org/genproto/googleapis/api v0.0.0-20250811230008-5f3141c8851a/go.mod h1:y2yVLIE/CSMCPXaHnSKXxu1spLPnglFLegmgdY23uuE= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250721164621-a45f3dfb1074 h1:qJW29YvkiJmXOYMu5Tf8lyrTp3dOS+K4z6IixtLaCf8= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250721164621-a45f3dfb1074/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= google.golang.org/genproto/googleapis/rpc v0.0.0-20250811230008-5f3141c8851a h1:tPE/Kp+x9dMSwUm/uM0JKK0IfdiJkwAbSMSeZBXXJXc= google.golang.org/genproto/googleapis/rpc v0.0.0-20250811230008-5f3141c8851a/go.mod h1:gw1tLEfykwDz2ET4a12jcXt4couGAm7IwsVaTy0Sflo= -google.golang.org/grpc v1.73.0 h1:VIWSmpI2MegBtTuFt5/JWy2oXxtjJ/e89Z70ImfD2ok= -google.golang.org/grpc v1.73.0/go.mod h1:50sbHOUqWoCQGI8V2HQLJM0B+LMlIUjNSZmow7EVBQc= google.golang.org/grpc v1.74.2 h1:WoosgB65DlWVC9FqI82dGsZhWFNBSLjQ84bjROOpMu4= google.golang.org/grpc v1.74.2/go.mod h1:CtQ+BGjaAIXHs/5YS3i473GqwBBa1zGQNevxdeBEXrM= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 h1:F29+wU6Ee6qgu9TddPgooOdaqsxTMunOoj8KA5yuS5A= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1/go.mod h1:5KF+wpkbTSbGcR9zteSqZV6fqFOWBl4Yde8En8MryZA= -google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= -google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= google.golang.org/protobuf v1.36.7 h1:IgrO7UwFQGJdRNXH/sQux4R1Dj1WAKcLElzeeRaXV2A= google.golang.org/protobuf v1.36.7/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/main.go b/main.go index 8a8b735..2eaa8e7 100644 --- a/main.go +++ b/main.go @@ -16,13 +16,13 @@ import ( "os" "os/signal" "sync" + "syscall" "time" "github.com/rs/zerolog" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" - "golang.org/x/sys/unix" "gitea.libretechconsulting.com/rmcguire/go-app/pkg/app" "gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel" @@ -50,7 +50,7 @@ var ( ) func main() { - ctx, cncl := signal.NotifyContext(context.Background(), os.Interrupt, unix.SIGTERM) + ctx, cncl := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT) defer cncl() // Load configuration and setup logging. The go-app framework @@ -96,6 +96,11 @@ func main() { app.GRPC = grpcSvcs app.HTTP = httpSvcs + span.SetAttributes( + attribute.Int("grpcServices", len(app.GRPC.Services)), + attribute.Int("httpServices", len(app.HTTP.Funcs)+len(app.HTTP.Handlers)), + ) + // Launch app app.MustRun()