From 8bd4f6568bc397ef8e615a5b4df0df15813a8c67 Mon Sep 17 00:00:00 2001 From: Anis Eleuch Date: Fri, 22 Dec 2023 10:25:08 -0800 Subject: [PATCH] server-info: Avoid initializing audit/log http/kafka targets (#18703) This can cause unnecessary ServerInfo() call delay. --- cmd/admin-handlers.go | 15 +++++++++++---- internal/logger/targets.go | 13 ------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index d54bb9b0f..c49bd60b7 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -1911,7 +1911,7 @@ func getServerInfo(ctx context.Context, poolsInfoEnabled bool, r *http.Request) } } - log, audit := fetchLoggerInfo() + log, audit := fetchLoggerInfo(ctx) // Get the notification target info notifyTarget := fetchLambdaInfo() @@ -2660,19 +2660,26 @@ func fetchKMSStatusV2(ctx context.Context) []madmin.KMS { return stats } +func targetStatus(ctx context.Context, h logger.Target) madmin.Status { + if h.IsOnline(ctx) { + return madmin.Status{Status: string(madmin.ItemOnline)} + } + return madmin.Status{Status: string(madmin.ItemOffline)} +} + // fetchLoggerDetails return log info -func fetchLoggerInfo() ([]madmin.Logger, []madmin.Audit) { +func fetchLoggerInfo(ctx context.Context) ([]madmin.Logger, []madmin.Audit) { var loggerInfo []madmin.Logger var auditloggerInfo []madmin.Audit for _, tgt := range logger.SystemTargets() { if tgt.Endpoint() != "" { - loggerInfo = append(loggerInfo, madmin.Logger{tgt.String(): logger.TargetStatus(GlobalContext, tgt)}) + loggerInfo = append(loggerInfo, madmin.Logger{tgt.String(): targetStatus(ctx, tgt)}) } } for _, tgt := range logger.AuditTargets() { if tgt.Endpoint() != "" { - auditloggerInfo = append(auditloggerInfo, madmin.Audit{tgt.String(): logger.TargetStatus(GlobalContext, tgt)}) + auditloggerInfo = append(auditloggerInfo, madmin.Audit{tgt.String(): targetStatus(ctx, tgt)}) } } diff --git a/internal/logger/targets.go b/internal/logger/targets.go index d31975ae0..893e06664 100644 --- a/internal/logger/targets.go +++ b/internal/logger/targets.go @@ -23,7 +23,6 @@ import ( "strings" "sync" - "github.com/minio/madmin-go/v3" "github.com/minio/minio/internal/logger/target/http" "github.com/minio/minio/internal/logger/target/kafka" "github.com/minio/minio/internal/logger/target/types" @@ -57,18 +56,6 @@ var ( consoleTgt Target ) -// TargetStatus returns status of the target (online|offline) -func TargetStatus(ctx context.Context, h Target) madmin.Status { - if h.IsOnline(ctx) { - return madmin.Status{Status: string(madmin.ItemOnline)} - } - // Previous initialization had failed. Try again. - if e := h.Init(ctx); e == nil { - return madmin.Status{Status: string(madmin.ItemOnline)} - } - return madmin.Status{Status: string(madmin.ItemOffline)} -} - // SystemTargets returns active targets. // Returned slice may not be modified in any way. func SystemTargets() []Target {