mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
lint: upgrade golangci-lint
Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
This commit is contained in:
committed by
Ravi Chamarthy
parent
5f04092e71
commit
ac3801ea2d
@@ -1,6 +1,7 @@
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -28,8 +29,9 @@ func getDirSize(path string) (int64, error) {
|
||||
if !info.IsDir() {
|
||||
size += info.Size()
|
||||
}
|
||||
|
||||
return err
|
||||
})
|
||||
|
||||
return size, err
|
||||
return size, fmt.Errorf("getDirSize: %w", err)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"zotregistry.io/zot/errors"
|
||||
"zotregistry.io/zot/pkg/log"
|
||||
)
|
||||
|
||||
@@ -90,14 +91,26 @@ func NewMetricsServer(enabled bool, log log.Logger) MetricServer {
|
||||
// implementing the MetricServer interface.
|
||||
func (ms *metricServer) SendMetric(mfunc interface{}) {
|
||||
if ms.enabled {
|
||||
fn := mfunc.(func())
|
||||
fn()
|
||||
mfn, ok := mfunc.(func())
|
||||
if !ok {
|
||||
ms.log.Error().Err(errors.ErrInvalidMetric).Msg("type conversion")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
mfn()
|
||||
}
|
||||
}
|
||||
|
||||
func (ms *metricServer) ForceSendMetric(mfunc interface{}) {
|
||||
fn := mfunc.(func())
|
||||
fn()
|
||||
mfn, ok := mfunc.(func())
|
||||
if !ok {
|
||||
ms.log.Error().Err(errors.ErrInvalidMetric).Msg("type conversion")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
mfn()
|
||||
}
|
||||
|
||||
func (ms *metricServer) ReceiveMetrics() interface{} {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//go:build minimal
|
||||
// +build minimal
|
||||
|
||||
// nolint: varnamelen,forcetypeassert
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
@@ -16,16 +17,16 @@ import (
|
||||
|
||||
const (
|
||||
metricsNamespace = "zot"
|
||||
// Counters
|
||||
// Counters.
|
||||
httpConnRequests = metricsNamespace + ".http.requests"
|
||||
repoDownloads = metricsNamespace + ".repo.downloads"
|
||||
repoUploads = metricsNamespace + ".repo.uploads"
|
||||
//Gauge
|
||||
// Gauge.
|
||||
repoStorageBytes = metricsNamespace + ".repo.storage.bytes"
|
||||
serverInfo = metricsNamespace + ".info"
|
||||
//Summary
|
||||
// Summary.
|
||||
httpRepoLatencySeconds = metricsNamespace + ".http.repo.latency.seconds"
|
||||
//Histogram
|
||||
// Histogram.
|
||||
httpMethodLatencySeconds = metricsNamespace + ".http.method.latency.seconds"
|
||||
|
||||
metricsScrapeTimeout = 2 * time.Minute
|
||||
@@ -109,6 +110,7 @@ func (ms *metricServer) ReceiveMetrics() interface{} {
|
||||
func (ms *metricServer) IsEnabled() (b bool) {
|
||||
// send a bool value on the request channel to avoid data race
|
||||
ms.reqChan <- b
|
||||
|
||||
return (<-ms.reqChan).(bool)
|
||||
}
|
||||
|
||||
@@ -288,13 +290,14 @@ func findHistogramValueIndex(metricSlice []*HistogramValue, name string, labelVa
|
||||
}
|
||||
|
||||
func (ms *metricServer) CounterInc(cv *CounterValue) {
|
||||
kLabels, ok := GetCounters()[cv.Name] // known label names for the 'name' counter
|
||||
err := sanityChecks(cv.Name, kLabels, ok, cv.LabelNames, cv.LabelValues)
|
||||
labels, ok := GetCounters()[cv.Name] // known label names for the 'name' counter
|
||||
|
||||
err := sanityChecks(cv.Name, labels, ok, cv.LabelNames, cv.LabelValues)
|
||||
if err != nil {
|
||||
// The last thing we want is to panic/stop the server due to instrumentation
|
||||
// thus log a message (should be detected during development of new metrics)
|
||||
ms.log.Error().Err(err).Msg("Instrumentation error")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -309,11 +312,12 @@ func (ms *metricServer) CounterInc(cv *CounterValue) {
|
||||
}
|
||||
|
||||
func (ms *metricServer) GaugeSet(gv *GaugeValue) {
|
||||
kLabels, ok := GetGauges()[gv.Name] // known label names for the 'name' counter
|
||||
err := sanityChecks(gv.Name, kLabels, ok, gv.LabelNames, gv.LabelValues)
|
||||
labels, ok := GetGauges()[gv.Name] // known label names for the 'name' counter
|
||||
|
||||
err := sanityChecks(gv.Name, labels, ok, gv.LabelNames, gv.LabelValues)
|
||||
if err != nil {
|
||||
ms.log.Error().Err(err).Msg("Instrumentation error")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -327,11 +331,12 @@ func (ms *metricServer) GaugeSet(gv *GaugeValue) {
|
||||
}
|
||||
|
||||
func (ms *metricServer) SummaryObserve(sv *SummaryValue) {
|
||||
kLabels, ok := GetSummaries()[sv.Name] // known label names for the 'name' summary
|
||||
err := sanityChecks(sv.Name, kLabels, ok, sv.LabelNames, sv.LabelValues)
|
||||
labels, ok := GetSummaries()[sv.Name] // known label names for the 'name' summary
|
||||
|
||||
err := sanityChecks(sv.Name, labels, ok, sv.LabelNames, sv.LabelValues)
|
||||
if err != nil {
|
||||
ms.log.Error().Err(err).Msg("Instrumentation error")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -347,11 +352,12 @@ func (ms *metricServer) SummaryObserve(sv *SummaryValue) {
|
||||
}
|
||||
|
||||
func (ms *metricServer) HistogramObserve(hv *HistogramValue) {
|
||||
kLabels, ok := GetHistograms()[hv.Name] // known label names for the 'name' counter
|
||||
err := sanityChecks(hv.Name, kLabels, ok, hv.LabelNames, hv.LabelValues)
|
||||
labels, ok := GetHistograms()[hv.Name] // known label names for the 'name' counter
|
||||
|
||||
err := sanityChecks(hv.Name, labels, ok, hv.LabelNames, hv.LabelValues)
|
||||
if err != nil {
|
||||
ms.log.Error().Err(err).Msg("Instrumentation error")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -465,8 +471,8 @@ func IncUploadCounter(ms MetricServer, repo string) {
|
||||
|
||||
func SetStorageUsage(ms MetricServer, rootDir string, repo string) {
|
||||
dir := path.Join(rootDir, repo)
|
||||
repoSize, err := getDirSize(dir)
|
||||
|
||||
repoSize, err := getDirSize(dir)
|
||||
if err != nil {
|
||||
ms.(*metricServer).log.Error().Err(err).Msg("failed to set storage usage")
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -66,21 +68,20 @@ func (mc *MetricsClient) GetMetrics() (*MetricsInfo, error) {
|
||||
}
|
||||
|
||||
func (mc *MetricsClient) makeGETRequest(url string, resultsPtr interface{}) (http.Header, error) {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
|
||||
req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("metric scraping: %w", err)
|
||||
}
|
||||
|
||||
resp, err := mc.config.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("metric scraping error: %w", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err := json.NewDecoder(resp.Body).Decode(resultsPtr); err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("metric scraping failed: %w", err)
|
||||
}
|
||||
|
||||
return resp.Header, nil
|
||||
|
||||
Reference in New Issue
Block a user