Skip to content

Commit

Permalink
feat: use stewardship api
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed Nov 9, 2023
1 parent 900dc9f commit f85f509
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
10 changes: 4 additions & 6 deletions pkg/check/longavailability/longavailability.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,19 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, o interf

c.logger.Infof("node %s: download attempt %d for %s", node.Name(), i+1, addr)
start := time.Now()
size, _, err := node.Client().DownloadFile(ctx, addr)
if err != nil {
isRetrievable, err := node.Client().IsRetrievable(ctx, addr)
if err != nil || !isRetrievable {
c.metrics.FailedDownloadAttempts.WithLabelValues(labelValue).Inc()
c.logger.Errorf("node %s: download %s error: %v", node.Name(), addr, err)
c.logger.Errorf("node %s, address: %s, err: %v, retrievable: %v", node.Name(), addr, err, isRetrievable)
c.logger.Infof("retrying in: %v", opts.RetryWait)
time.Sleep(opts.RetryWait)
continue
}
c.logger.Infof("download size %d", size)
c.metrics.DownloadSize.WithLabelValues(labelValue).Set(float64(size))

dur := time.Since(start)
c.metrics.DownloadDuration.WithLabelValues(labelValue).Observe(dur.Seconds())
c.logger.Infof("node %s: downloaded %s successfully in %v", node.Name(), addr, dur)
c.metrics.DownloadStatus.WithLabelValues(labelValue).Set(1)
c.metrics.Retrieved.WithLabelValues(labelValue).Inc()
break
}
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/check/longavailability/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
type metrics struct {
DownloadErrors *prometheus.CounterVec
DownloadAttempts *prometheus.CounterVec
Retrieved *prometheus.CounterVec
FailedDownloadAttempts *prometheus.CounterVec
DownloadDuration *prometheus.HistogramVec
DownloadSize *prometheus.GaugeVec
DownloadStatus *prometheus.GaugeVec
}

Expand All @@ -25,12 +25,21 @@ func newMetrics(subsystem string, labels []string) metrics {
},
labels,
),
Retrieved: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "retrieved",
Help: "Number of successful downloads.",
},
labels,
),
FailedDownloadAttempts: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "failed_download_attempts",
Help: "Number of download attempts.",
Help: "Number of failed download attempts.",
},
labels,
),
Expand All @@ -52,15 +61,6 @@ func newMetrics(subsystem string, labels []string) metrics {
},
labels,
),
DownloadSize: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "d_download_size_bytes",
Help: "Amount of data downloaded per download.",
},
labels,
),
DownloadStatus: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: m.Namespace,
Expand Down

0 comments on commit f85f509

Please sign in to comment.