memory: fix panics if metrics does not exists (#1960)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2025-04-04 23:21:26 +02:00
committed by GitHub
parent 88c929ac6f
commit ecc805f0fa
39 changed files with 565 additions and 364 deletions

View File

@@ -201,7 +201,7 @@ func (c *Collection) Enable(enabledCollectors []string) error {
// Build To be called by the exporter for collector initialization.
// Instead, fail fast, it will try to build all collectors and return all errors.
// errors are joined with errors.Join.
func (c *Collection) Build(logger *slog.Logger) error {
func (c *Collection) Build(ctx context.Context, logger *slog.Logger) error {
c.startTime = gotime.Now()
err := c.initMI()
@@ -236,7 +236,7 @@ func (c *Collection) Build(logger *slog.Logger) error {
errors.Is(err, pdh.NewPdhError(pdh.CstatusNoObject)) ||
errors.Is(err, pdh.NewPdhError(pdh.CstatusNoCounter)) ||
errors.Is(err, mi.MI_RESULT_INVALID_NAMESPACE) {
logger.LogAttrs(context.Background(), slog.LevelWarn, "couldn't initialize collector", slog.Any("err", err))
logger.LogAttrs(ctx, slog.LevelWarn, "couldn't initialize collector", slog.Any("err", err))
continue
}