Skip to content

Commit 8bed97a

Browse files
authored
Disable usage msg after Start and suppress known errors from loggingexporter (#638)
Two fit and finish issues on this change: - With the improved shutdown merged recently the Collector started to show error messages on shutdown. - Call to Sync on loggingexporter generates non-actionable error messages.
1 parent 49a0f96 commit 8bed97a

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

exporter/loggingexporter/logging_exporter.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import (
1818
"context"
1919
"encoding/hex"
2020
"fmt"
21+
"os"
2122
"strconv"
2223
"strings"
24+
"syscall"
2325

2426
"go.uber.org/zap"
2527

@@ -158,7 +160,7 @@ func NewTraceExporter(config configmodels.Exporter, level string, logger *zap.Lo
158160
return exporterhelper.NewTraceExporter(
159161
config,
160162
s.pushTraceData,
161-
exporterhelper.WithShutdown(logger.Sync),
163+
exporterhelper.WithShutdown(loggerSync(logger)),
162164
)
163165
}
164166

@@ -174,6 +176,27 @@ func NewMetricsExporter(config configmodels.Exporter, logger *zap.Logger) (expor
174176
// TODO: Add ability to record the received data
175177
return 0, nil
176178
},
177-
exporterhelper.WithShutdown(logger.Sync),
179+
exporterhelper.WithShutdown(loggerSync(logger)),
178180
)
179181
}
182+
183+
func loggerSync(logger *zap.Logger) func() error {
184+
return func() error {
185+
// Currently Sync() on stdout and stderr return errors on Linux and macOS,
186+
// respectively:
187+
//
188+
// - sync /dev/stdout: invalid argument
189+
// - sync /dev/stdout: inappropriate ioctl for device
190+
//
191+
// Since these are not actionable ignore them.
192+
err := logger.Sync()
193+
if osErr, ok := err.(*os.PathError); ok {
194+
wrappedErr := osErr.Unwrap()
195+
switch wrappedErr {
196+
case syscall.EINVAL, syscall.ENOTSUP, syscall.ENOTTY:
197+
err = nil
198+
}
199+
}
200+
return err
201+
}
202+
}

service/service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ func (app *Application) execute() error {
460460
// Start starts the collector according to the command and configuration
461461
// given by the user.
462462
func (app *Application) Start() error {
463+
// From this point on do not show usage in case of error.
464+
app.rootCmd.SilenceUsage = true
465+
463466
return app.rootCmd.Execute()
464467
}
465468

0 commit comments

Comments
 (0)