Skip to content

Commit d09cd73

Browse files
committed
always enable errorLogger and replace the error message with errorLogger
1 parent 54eec9a commit d09cd73

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

dns/dnsperfgo/main.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ import (
4040
const clusterDomain = "cluster.local"
4141

4242
type Config struct {
43-
qps int
44-
testDuration, idleDuration, queryTimeout time.Duration
45-
hostnameFile string
46-
queryClusterNames, logQueries, enableErrorLogging, enableLatencyLogging bool
43+
qps int
44+
testDuration, idleDuration, queryTimeout time.Duration
45+
hostnameFile string
46+
queryClusterNames, logQueries, enableLatencyLogging bool
4747
}
4848

4949
type dnsClient struct {
@@ -77,14 +77,11 @@ func main() {
7777
flag.BoolVar(&config.queryClusterNames, "query-cluster-names", false, "Indicates whether the query names should be the service names in the cluster.")
7878
flag.BoolVar(&config.logQueries, "log-queries", false, "Indicates whether each query should be logged.")
7979
flag.BoolVar(&config.enableLatencyLogging, "enable-latency-logging", false, "Indicate whether to enable structured logging for each DNS lookup latency.")
80-
flag.BoolVar(&config.enableErrorLogging, "enable-error-logging", false, "Indicate whether to enable structured logging for each DNS lookup errors.")
8180
flag.Parse()
8281
if config.enableLatencyLogging {
8382
infoLogger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}))
8483
}
85-
if config.enableErrorLogging {
86-
errorLogger = slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError}))
87-
}
84+
errorLogger = slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError}))
8885
log.Printf("Starting dnstest with config parameters - %+v", config)
8986
client := &dnsClient{config: &config, stopChan: make(chan os.Signal, 1)}
9087
signal.Notify(client.stopChan, syscall.SIGTERM)
@@ -218,13 +215,6 @@ func (c *dnsClient) updateResults(timedOut bool, err error, name string) {
218215
c.resultsLock.Lock()
219216
defer c.resultsLock.Unlock()
220217
if err != nil {
221-
if errorLogger != nil {
222-
errorLogger.Error("DNS lookup failed",
223-
"hostname", name,
224-
"error", err.Error(),
225-
"timed_out", timedOut,
226-
)
227-
}
228218
c.result.errorCount++
229219
dnsErrorsCounter.Inc()
230220
}
@@ -263,7 +253,11 @@ func (c *dnsClient) runQuery(name string, timeout time.Duration, lookupFunc Look
263253
log.Printf("DNS lookup of name %q, err - %v\n", name, err)
264254
}
265255
if err != nil {
266-
log.Printf("Failed DNS lookup of name %q, err - %v\n", name, err)
256+
errorLogger.Error("Failed DNS lookup",
257+
"hostname", name,
258+
"error", err.Error(),
259+
"timed_out", timedOut,
260+
)
267261
}
268262
c.updateResults(timedOut, err, name)
269263
}()

0 commit comments

Comments
 (0)