Skip to content

Commit

Permalink
Use "error" instead of "Error" as key in logs with attached errors (#392
Browse files Browse the repository at this point in the history
)
  • Loading branch information
merlimat authored Nov 30, 2023
1 parent 0689a1a commit 254dc2f
Show file tree
Hide file tree
Showing 35 changed files with 98 additions and 98 deletions.
2 changes: 1 addition & 1 deletion common/client_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (cp *clientPool) Close() error {
cp.log.Warn(
"Failed to close GRPC connection",
slog.String("server_address", target),
slog.Any("Error", err),
slog.Any("error", err),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func newDefaultGrpcProvider(name, bindAddress string, registerFunc func(grpc.Ser
if err := c.server.Serve(listener); err != nil {
c.log.Error(
"Failed to start serving",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand Down
4 changes: 2 additions & 2 deletions common/metrics/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (g *gauge) Unregister() {
if err := g.registration.Unregister(); err != nil {
slog.Error(
"Failed to unregister gauge",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand Down Expand Up @@ -67,7 +67,7 @@ func NewGauge(name string, description string, unit Unit, labels map[string]any,
if err != nil {
slog.Error(
"Failed to register gauge",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand Down
4 changes: 2 additions & 2 deletions common/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func init() {
if err != nil {
slog.Error(
"Failed to initialize Prometheus metrics exporter",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func Start(bindAddress string) (*PrometheusMetrics, error) {
if err = p.server.Serve(listener); err != nil && !errors.Is(err, http.ErrServerClosed) {
slog.Error(
"Failed to serve metrics",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion common/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func RunProfiling() io.Closer {
if err := s.ListenAndServe(); err != nil && err != http.ErrServerClosed {
slog.Error(
"Unable to start debug profiling server",
slog.Any("Error", err),
slog.Any("error", err),
slog.String("component", "pprof"),
)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion common/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func RunProcess(startProcess func() (io.Closer, error)) {
if err != nil {
slog.Error(
"Failed to start the process",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion common/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func WaitUntilSignal(closers ...io.Closer) {
if err := closer.Close(); err != nil {
slog.Error(
"Failed when shutting down server",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand Down
6 changes: 3 additions & 3 deletions coordinator/impl/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,14 @@ func (c *coordinator) waitForExternalEvents() {
if err := c.handleClusterConfigUpdated(); err != nil {
c.log.Warn(
"Failed to update cluster config",
slog.Any("Error", err),
slog.Any("error", err),
)
}

if err := c.rebalanceCluster(); err != nil {
c.log.Warn(
"Failed to rebalance cluster",
slog.Any("Error", err),
slog.Any("error", err),
)
}
}
Expand Down Expand Up @@ -468,7 +468,7 @@ func (c *coordinator) rebalanceCluster() error {
if err := sc.SwapNode(swapAction.From, swapAction.To); err != nil {
c.log.Warn(
"Failed to swap node",
slog.Any("Error", err),
slog.Any("error", err),
slog.Any("swap-action", swapAction),
)
}
Expand Down
4 changes: 2 additions & 2 deletions coordinator/impl/k8s_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewK8SClientConfig() *rest.Config {
if err != nil {
slog.Error(
"failed to load kubeconfig",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand All @@ -54,7 +54,7 @@ func NewK8SClientset(config *rest.Config) kubernetes.Interface {
if err != nil {
slog.Error(
"failed to create client",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion coordinator/impl/metadata_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func configMap(name string, status *model.ClusterStatus, version Version) *coreV
if err != nil {
slog.Error(
"unable to marshal cluster status",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion coordinator/impl/metadata_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (m *metadataProviderFile) Store(cs *model.ClusterStatus, expectedVersion Ve
if err := m.fileLock.Unlock(); err != nil {
slog.Warn(
"Failed to release file lock on metadata",
slog.Any("Error", err),
slog.Any("error", err),
)
}
}()
Expand Down
6 changes: 3 additions & 3 deletions coordinator/impl/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (n *nodeController) healthCheckWithRetries() {
}, backOff, func(err error, duration time.Duration) {
n.log.Warn(
"Storage node health check failed",
slog.Any("Error", err),
slog.Any("error", err),
slog.Duration("retry-after", duration),
)

Expand Down Expand Up @@ -234,7 +234,7 @@ func (n *nodeController) sendAssignmentsUpdatesWithRetries() {
n.log.Warn(
"Failed to send assignments updates to storage node",
slog.Duration("retry-after", duration),
slog.Any("Error", err),
slog.Any("error", err),
)
})
}
Expand Down Expand Up @@ -280,7 +280,7 @@ func (n *nodeController) sendAssignmentsUpdates(backoff backoff.BackOff) error {
if err := stream.Send(assignments); err != nil {
n.log.Debug(
"Failed to send assignments",
slog.Any("Error", err),
slog.Any("error", err),
)
return err
}
Expand Down
14 changes: 7 additions & 7 deletions coordinator/impl/shard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (s *shardController) verifyCurrentEnsemble() bool {
if err != nil {
s.log.Warn(
"Failed to verify status for shard. Start a new election",
slog.Any("Error", err),
slog.Any("error", err),
slog.Any("node", node),
)
return false
Expand Down Expand Up @@ -224,7 +224,7 @@ func (s *shardController) electLeaderWithRetries() {
s.leaderElectionsFailed.Inc()
s.log.Warn(
"Leader election has failed, retrying later",
slog.Any("Error", err),
slog.Any("error", err),
slog.Duration("retry-after", duration),
)
})
Expand Down Expand Up @@ -385,7 +385,7 @@ func (s *shardController) keepFencingFollower(ctx context.Context, node model.Se
}, backOff, func(err error, duration time.Duration) {
s.log.Warn(
"Failed to newTerm, retrying later",
slog.Any("Error", err),
slog.Any("error", err),
slog.Any("follower", node),
slog.Int64("term", s.Term()),
slog.Duration("retry-after", duration),
Expand Down Expand Up @@ -454,7 +454,7 @@ func (s *shardController) newTermQuorum() (map[model.ServerAddress]*proto.EntryI
if err != nil {
s.log.Warn(
"Failed to newTerm node",
slog.Any("Error", err),
slog.Any("error", err),
slog.String("node", serverAddress.Internal),
)
} else {
Expand Down Expand Up @@ -625,7 +625,7 @@ func (s *shardController) DeleteShard() {
s.log.Warn(
"Delete shard failed, retrying later",
slog.Duration("retry-after", duration),
slog.Any("Error", err),
slog.Any("error", err),
)
})

Expand All @@ -639,7 +639,7 @@ func (s *shardController) deleteShard() error {
if err := s.deleteShardRpc(s.ctx, sa); err != nil {
s.log.Warn(
"Failed to delete shard",
slog.Any("Error", err),
slog.Any("error", err),
slog.String("node", sa.Internal),
)
return err
Expand Down Expand Up @@ -710,7 +710,7 @@ func (s *shardController) SwapNode(from model.ServerAddress, to model.ServerAddr
if err := s.waitForFollowersToCatchUp(ctx, *leader, ensemble); err != nil {
s.log.Error(
"Failed to wait for followers to catch up",
slog.Any("Error", err),
slog.Any("error", err),
)
return err
}
Expand Down
4 changes: 2 additions & 2 deletions maelstrom/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (d *dispatcher) RpcRequest(ctx context.Context, dest string, msgType MsgTyp
if err != nil {
slog.Error(
"failed to serialize json",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand Down Expand Up @@ -377,7 +377,7 @@ func toJson(message pb.Message) []byte {
if err != nil {
slog.Error(
"failed to serialize proto to json",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion maelstrom/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (m *maelstromGrpcProvider) HandleOxiaStreamRequest(msgType MsgType, msg *Me
if err != nil {
slog.Warn(
"failed to call replicate",
slog.Any("Error", err),
slog.Any("error", err),
)
}
}()
Expand Down
4 changes: 2 additions & 2 deletions maelstrom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func main() {
if err != nil {
slog.Error(
"failed to create data dir",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand All @@ -178,7 +178,7 @@ func main() {
if err != nil {
slog.Error(
"failed to create coordinator",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand Down
12 changes: 6 additions & 6 deletions maelstrom/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func parseRequest(line string) (msgType MsgType, msg any, protoMsg pb.Message) {
slog.Error(
"failed to unmarshal",
slog.String("line", line),
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand All @@ -257,7 +257,7 @@ func parseRequest(line string) (msgType MsgType, msg any, protoMsg pb.Message) {
if err := json.Unmarshal([]byte(line), sm); err != nil {
slog.Error(
"failed to unmarshal the proper struct",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand All @@ -272,7 +272,7 @@ func parseRequest(line string) (msgType MsgType, msg any, protoMsg pb.Message) {
if err := json.Unmarshal([]byte(line), om); err != nil {
slog.Error(
"failed to unmarshal the proper struct",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand All @@ -281,7 +281,7 @@ func parseRequest(line string) (msgType MsgType, msg any, protoMsg pb.Message) {
if err := protojson.Unmarshal(om.Body.OxiaMsg, protoMsg); err != nil {
slog.Error(
"failed to unmarshal proto json",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand All @@ -290,7 +290,7 @@ func parseRequest(line string) (msgType MsgType, msg any, protoMsg pb.Message) {
if err := json.Unmarshal([]byte(line), om); err != nil {
slog.Error(
"failed to unmarshal the proper struct",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand All @@ -299,7 +299,7 @@ func parseRequest(line string) (msgType MsgType, msg any, protoMsg pb.Message) {
if err := protojson.Unmarshal(om.Body.OxiaMsg, protoMsg); err != nil {
slog.Error(
"failed to unmarshal proto json",
slog.Any("Error", err),
slog.Any("error", err),
)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion oxia/internal/batch/read_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (b *readBatch) doRequestWithRetries(request *proto.ReadRequest) (response *
}, backOff, func(err error, duration time.Duration) {
slog.Debug(
"Failed to perform request, retrying later",
slog.Any("Error", err),
slog.Any("error", err),
slog.Duration("retry-after", duration),
)
})
Expand Down
2 changes: 1 addition & 1 deletion oxia/internal/batch/write_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (b *writeBatch) doRequestWithRetries(request *proto.WriteRequest) (response
}, backOff, func(err error, duration time.Duration) {
slog.Debug(
"Failed to perform request, retrying later",
slog.Any("Error", err),
slog.Any("error", err),
slog.Duration("retry-after", duration),
)
})
Expand Down
2 changes: 1 addition & 1 deletion oxia/internal/metrics/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func fatalOnErr(err error, name string) {
if err != nil {
slog.Error(
"Failed to create metric",
slog.Any("Error", err),
slog.Any("error", err),
slog.String("component", "oxia-client"),
slog.String("MetricName", name),
)
Expand Down
6 changes: 3 additions & 3 deletions oxia/internal/shard_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (s *shardManagerImpl) receiveWithRecovery() {
if s.isClosed() {
s.logger.Debug(
"Closed",
slog.Any("Error", err),
slog.Any("error", err),
)
return nil
}
Expand All @@ -157,7 +157,7 @@ func (s *shardManagerImpl) receiveWithRecovery() {
if status.Code(err) != codes.Canceled {
s.logger.Warn(
"Failed receiving shard assignments, retrying later",
slog.Any("Error", err),
slog.Any("error", err),
slog.Duration("retry-after", duration),
)
}
Expand All @@ -166,7 +166,7 @@ func (s *shardManagerImpl) receiveWithRecovery() {
if err != nil {
s.logger.Error(
"Failed receiving shard assignments",
slog.Any("Error", err),
slog.Any("error", err),
)
s.updatedWg.Fail(err)
}
Expand Down
2 changes: 1 addition & 1 deletion oxia/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (snm *shardNotificationsManager) getNotificationsWithRetries() {
if err != context.Canceled {
snm.log.Error(
"Error while getting notifications",
slog.Any("Error", err),
slog.Any("error", err),
slog.Duration("retry-after", duration),
)
}
Expand Down
Loading

0 comments on commit 254dc2f

Please sign in to comment.