Switch to log/slog
This change switches GARM to the new structured logging standard library. This will allow us to set log levels and reduce some of the log spam. Given that we introduced new knobs to tweak logging, the number of config options for logging now warrants it's own section. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
f72e97209f
commit
e441b6ce89
50 changed files with 989 additions and 601 deletions
|
|
@ -1,7 +1,7 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
|
||||
"github.com/cloudbase/garm/auth"
|
||||
|
|
@ -14,7 +14,7 @@ func (c *GarmCollector) CollectEnterpriseMetric(ch chan<- prometheus.Metric, hos
|
|||
|
||||
enterprises, err := c.runner.ListEnterprises(ctx)
|
||||
if err != nil {
|
||||
log.Printf("listing providers: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing providers")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ func (c *GarmCollector) CollectEnterpriseMetric(ch chan<- prometheus.Metric, hos
|
|||
enterprise.ID, // label: id
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("cannot collect enterpriseInfo metric: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect enterpriseInfo metric")
|
||||
continue
|
||||
}
|
||||
ch <- enterpriseInfo
|
||||
|
|
@ -42,7 +42,7 @@ func (c *GarmCollector) CollectEnterpriseMetric(ch chan<- prometheus.Metric, hos
|
|||
strconv.FormatBool(enterprise.PoolManagerStatus.IsRunning), // label: running
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("cannot collect enterprisePoolManagerStatus metric: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect enterprisePoolManagerStatus metric")
|
||||
continue
|
||||
}
|
||||
ch <- enterprisePoolManagerStatus
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log/slog"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
|
@ -15,7 +15,7 @@ func (c *GarmCollector) CollectHealthMetric(ch chan<- prometheus.Metric, hostnam
|
|||
controllerID,
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("error on creating health metric: %s", err)
|
||||
slog.With(slog.Any("error", err)).Error("error on creating health metric")
|
||||
return
|
||||
}
|
||||
ch <- m
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log/slog"
|
||||
|
||||
"github.com/cloudbase/garm/auth"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
|
@ -14,13 +14,13 @@ func (c *GarmCollector) CollectInstanceMetric(ch chan<- prometheus.Metric, hostn
|
|||
|
||||
instances, err := c.runner.ListAllInstances(ctx)
|
||||
if err != nil {
|
||||
log.Printf("cannot collect metrics, listing instances: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect metrics, listing instances")
|
||||
return
|
||||
}
|
||||
|
||||
pools, err := c.runner.ListAllPools(ctx)
|
||||
if err != nil {
|
||||
log.Printf("listing pools: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing pools")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ func (c *GarmCollector) CollectInstanceMetric(ch chan<- prometheus.Metric, hostn
|
|||
)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("cannot collect runner metric: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect runner metric")
|
||||
continue
|
||||
}
|
||||
ch <- m
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log/slog"
|
||||
|
||||
"github.com/cloudbase/garm/auth"
|
||||
"github.com/cloudbase/garm/params"
|
||||
|
|
@ -192,7 +192,7 @@ func (c *GarmCollector) Describe(ch chan<- *prometheus.Desc) {
|
|||
func (c *GarmCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
controllerInfo, err := c.runner.GetControllerInfo(auth.GetAdminContext())
|
||||
if err != nil {
|
||||
log.Printf("failed to get controller info: %s", err)
|
||||
slog.With(slog.Any("error", err)).Error("failed to get controller info")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
|
||||
"github.com/cloudbase/garm/auth"
|
||||
|
|
@ -14,7 +14,7 @@ func (c *GarmCollector) CollectOrganizationMetric(ch chan<- prometheus.Metric, h
|
|||
|
||||
organizations, err := c.runner.ListOrganizations(ctx)
|
||||
if err != nil {
|
||||
log.Printf("listing providers: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing providers")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ func (c *GarmCollector) CollectOrganizationMetric(ch chan<- prometheus.Metric, h
|
|||
organization.ID, // label: id
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("cannot collect organizationInfo metric: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect organizationInfo metric")
|
||||
continue
|
||||
}
|
||||
ch <- organizationInfo
|
||||
|
|
@ -42,7 +42,7 @@ func (c *GarmCollector) CollectOrganizationMetric(ch chan<- prometheus.Metric, h
|
|||
strconv.FormatBool(organization.PoolManagerStatus.IsRunning), // label: running
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("cannot collect organizationPoolManagerStatus metric: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect organizationPoolManagerStatus metric")
|
||||
continue
|
||||
}
|
||||
ch <- organizationPoolManagerStatus
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ func (c *GarmCollector) CollectPoolMetric(ch chan<- prometheus.Metric, hostname
|
|||
|
||||
pools, err := c.runner.ListAllPools(ctx)
|
||||
if err != nil {
|
||||
log.Printf("listing pools: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing pools")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ func (c *GarmCollector) CollectPoolMetric(ch chan<- prometheus.Metric, hostname
|
|||
poolNames[pool.ID].Type, // label: pool_type
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("cannot collect poolInfo metric: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect poolInfo metric")
|
||||
continue
|
||||
}
|
||||
ch <- poolInfo
|
||||
|
|
@ -77,7 +77,7 @@ func (c *GarmCollector) CollectPoolMetric(ch chan<- prometheus.Metric, hostname
|
|||
strconv.FormatBool(pool.Enabled), // label: enabled
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("cannot collect poolStatus metric: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect poolStatus metric")
|
||||
continue
|
||||
}
|
||||
ch <- poolStatus
|
||||
|
|
@ -89,7 +89,7 @@ func (c *GarmCollector) CollectPoolMetric(ch chan<- prometheus.Metric, hostname
|
|||
pool.ID, // label: id
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("cannot collect poolMaxRunners metric: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect poolMaxRunners metric")
|
||||
continue
|
||||
}
|
||||
ch <- poolMaxRunners
|
||||
|
|
@ -101,7 +101,7 @@ func (c *GarmCollector) CollectPoolMetric(ch chan<- prometheus.Metric, hostname
|
|||
pool.ID, // label: id
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("cannot collect poolMinIdleRunners metric: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect poolMinIdleRunners metric")
|
||||
continue
|
||||
}
|
||||
ch <- poolMinIdleRunners
|
||||
|
|
@ -113,7 +113,7 @@ func (c *GarmCollector) CollectPoolMetric(ch chan<- prometheus.Metric, hostname
|
|||
pool.ID, // label: id
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("cannot collect poolBootstrapTimeout metric: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect poolBootstrapTimeout metric")
|
||||
continue
|
||||
}
|
||||
ch <- poolBootstrapTimeout
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log/slog"
|
||||
|
||||
"github.com/cloudbase/garm/auth"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
|
@ -13,7 +13,7 @@ func (c *GarmCollector) CollectProviderMetric(ch chan<- prometheus.Metric, hostn
|
|||
|
||||
providers, err := c.runner.ListProviders(ctx)
|
||||
if err != nil {
|
||||
log.Printf("listing providers: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing providers")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ func (c *GarmCollector) CollectProviderMetric(ch chan<- prometheus.Metric, hostn
|
|||
provider.Description, // label: description
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("cannot collect providerInfo metric: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect providerInfo metric")
|
||||
continue
|
||||
}
|
||||
ch <- providerInfo
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
|
||||
"github.com/cloudbase/garm/auth"
|
||||
|
|
@ -14,7 +14,7 @@ func (c *GarmCollector) CollectRepositoryMetric(ch chan<- prometheus.Metric, hos
|
|||
|
||||
repositories, err := c.runner.ListRepositories(ctx)
|
||||
if err != nil {
|
||||
log.Printf("listing providers: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing providers")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ func (c *GarmCollector) CollectRepositoryMetric(ch chan<- prometheus.Metric, hos
|
|||
repository.ID, // label: id
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("cannot collect repositoryInfo metric: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect repositoryInfo metric")
|
||||
continue
|
||||
}
|
||||
ch <- repositoryInfo
|
||||
|
|
@ -43,7 +43,7 @@ func (c *GarmCollector) CollectRepositoryMetric(ch chan<- prometheus.Metric, hos
|
|||
strconv.FormatBool(repository.PoolManagerStatus.IsRunning), // label: running
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("cannot collect repositoryPoolManagerStatus metric: %s", err)
|
||||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect repositoryPoolManagerStatus metric")
|
||||
continue
|
||||
}
|
||||
ch <- repositoryPoolManagerStatus
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue