Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ linters:
- legacy
- std-error-handling
rules:
# Shutdown needs a fresh timeout after the server context is cancelled.
- path: ^base/utils/gin\.go$
linters: [gosec]
text: "G118:"
# The inline analyzer cannot handle generic type inference yet.
- path: ^manager/middlewares/rbac\.go$
linters: [govet]
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ RUN if [ "$INSTALL_TOOLS" == "yes" ] ; then \
go install github.com/swaggo/swag/cmd/swag@v1.16.4 && \
go install gotest.tools/gotestsum@v1.13.0 && \
curl -sSfL https://golangci-lint.run/install.sh \
| sh -s -- -b $(go env GOPATH)/bin ; \
| sh -s -- -b $(go env GOPATH)/bin v2.15.0 ; \
fi

ADD --chown=insights:insights dev/kafka/secrets/ca.crt /opt/kafka/
Expand Down
4 changes: 2 additions & 2 deletions base/metrics/certificate_expiry.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const candlepinCertLabel = "candlepin"
// It is registered only where metrics are pushed (e.g. vmaas_sync), not on every pod's default registry.
var CertificateExpiryDays = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Help: "Number of days until the certificate expires by the certificate label",
Namespace: "patchman_engine",
Subsystem: "core",
Namespace: Namespace,
Subsystem: SubsystemCore,
Name: "certificate_expiry_days",
}, []string{"certificate_label"})

Expand Down
12 changes: 6 additions & 6 deletions base/metrics/certificate_expiry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func testCandlepinPEMs(t *testing.T) (certPEM, keyPEM string) {

func TestApplyCandlepinCertExpiry_setsGauge(t *testing.T) {
gv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "patchman_engine",
Subsystem: "core",
Namespace: Namespace,
Subsystem: SubsystemCore,
Name: "certificate_expiry_days_test_helper",
Help: "test",
}, []string{"certificate_label"})
Expand All @@ -57,8 +57,8 @@ func TestApplyCandlepinCertExpiry_setsGauge(t *testing.T) {

func TestApplyCandlepinCertExpiry_badPEMDeletesSeries(t *testing.T) {
gv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "patchman_engine",
Subsystem: "core",
Namespace: Namespace,
Subsystem: SubsystemCore,
Name: "certificate_expiry_days_test_helper_bad",
Help: "test",
}, []string{"certificate_label"})
Expand All @@ -78,8 +78,8 @@ func TestApplyCandlepinCertExpiry_badPEMDeletesSeries(t *testing.T) {

func TestApplyCandlepinCertExpiry_missingConfigDeletesSeries(t *testing.T) {
gv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "patchman_engine",
Subsystem: "core",
Namespace: Namespace,
Subsystem: SubsystemCore,
Name: "certificate_expiry_days_test_helper_clear",
Help: "test",
}, []string{"certificate_label"})
Expand Down
25 changes: 19 additions & 6 deletions base/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,33 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

const (
Namespace = "patchman_engine"
SubsystemCore = "core"
SubsystemEvaluator = "evaluator"
SubsystemListener = "listener"
SubsystemManager = "manager"
SubsystemTasks = "tasks"
SubsystemVmaasSync = "vmaas_sync"
LabelType = "type"
LabelVersion = "version"
LabelEvent = "event"
)

var (
KafkaConnectionErrorCnt = prometheus.NewCounterVec(prometheus.CounterOpts{
Help: "Counter vector measuring Kafka connection issues when trying to read or write a message",
Namespace: "patchman_engine",
Subsystem: "core",
Namespace: Namespace,
Subsystem: SubsystemCore,
Name: "kafka_connection_errors",
}, []string{"type"})
}, []string{LabelType})

EngineVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Help: "Patchman project deployment information",
Namespace: "patchman_engine",
Subsystem: "core",
Namespace: Namespace,
Subsystem: SubsystemCore,
Name: "info",
}, []string{"version"})
}, []string{LabelVersion})
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion base/utils/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ func RunServer(ctx context.Context, handler http.Handler, port int) error {
defer close(shutdownDone)
<-ctx.Done()
LogDebug("gracefully shutting down server...")
shutdownCtx, cancel := context.WithTimeout(context.Background(), serverShutdownTimeout)
// Parent ctx is already cancelled; WithoutCancel keeps values and gives Shutdown a fresh timeout budget.
shutdownCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), serverShutdownTimeout)
defer cancel()
err := srv.Shutdown(shutdownCtx)
if err != nil {
Expand Down
41 changes: 21 additions & 20 deletions evaluator/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package evaluator
import (
"app/base"
"app/base/core"
"app/base/metrics"
"app/base/utils"
"app/manager/middlewares"

Expand All @@ -13,59 +14,59 @@ import (
var (
evaluationCnt = prometheus.NewCounterVec(prometheus.CounterOpts{
Help: "How many systems were evaluated with which result",
Namespace: "patchman_engine",
Subsystem: "evaluator",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemEvaluator,
Name: "evaluation",
}, []string{"type"})
}, []string{metrics.LabelType})

updatesCnt = prometheus.NewCounterVec(prometheus.CounterOpts{
Help: "How many updates were found of which type",
Namespace: "patchman_engine",
Subsystem: "evaluator",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemEvaluator,
Name: "updates",
}, []string{"type"})
}, []string{metrics.LabelType})

evaluationDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Help: "How long it took system evaluation of which type (upload, recalc)",
Namespace: "patchman_engine",
Subsystem: "evaluator",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemEvaluator,
Name: "evaluation_duration_seconds",
}, []string{"type"})
}, []string{metrics.LabelType})

evaluationPartDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Help: "How long it took particular evaluation part",
Namespace: "patchman_engine",
Subsystem: "evaluator",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemEvaluator,
Name: "evaluation_part_duration_seconds",
}, []string{"part"})

uploadEvaluationDelay = prometheus.NewHistogram(prometheus.HistogramOpts{
Help: "How long it takes from upload to evaluation",
Namespace: "patchman_engine",
Subsystem: "evaluator",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemEvaluator,
Name: "upload_evaluation_delay_seconds",
Buckets: []float64{1, 5, 15, 30, 60, 300},
})

twoEvaluationsInterval = prometheus.NewHistogram(prometheus.HistogramOpts{
Help: "How long it takes between two evaluations",
Namespace: "patchman_engine",
Subsystem: "evaluator",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemEvaluator,
Name: "two_evaluations_interval_hours",
Buckets: []float64{1, 2, 6, 24, 72, 168},
})

packageCacheCnt = prometheus.NewCounterVec(prometheus.CounterOpts{
Help: "How many packages hit/miss package cache",
Namespace: "patchman_engine",
Subsystem: "evaluator",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemEvaluator,
Name: "package_cache",
}, []string{"type", "by"})
}, []string{metrics.LabelType, "by"})

packageCacheGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Help: "Package cache size",
Namespace: "patchman_engine",
Subsystem: "evaluator",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemEvaluator,
Name: "package_cache_size",
}, []string{"by"})
)
Expand Down
37 changes: 19 additions & 18 deletions listener/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package listener
import (
"app/base"
"app/base/core"
"app/base/metrics"
"app/base/utils"
"app/manager/middlewares"

Expand Down Expand Up @@ -30,49 +31,49 @@ const (
var (
eventMsgsReceivedCnt = prometheus.NewCounterVec(prometheus.CounterOpts{
Help: "How many messages received by listener, which event type, which process result",
Namespace: "patchman_engine",
Subsystem: "listener",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemListener,
Name: "kafka_message_received",
}, []string{"event", "type"})
}, []string{metrics.LabelEvent, metrics.LabelType})

templateMsgReceivedCnt = prometheus.NewCounterVec(prometheus.CounterOpts{
Help: "Number of template messages received by type",
Namespace: "patchman_engine",
Subsystem: "listener",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemListener,
Name: "template_message_received",
}, []string{"event", "type"})
}, []string{metrics.LabelEvent, metrics.LabelType})

messageHandlingDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Help: "How long it took to process the message",
Namespace: "patchman_engine",
Subsystem: "listener",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemListener,
Name: "kafka_message_handling_duration_seconds",
}, []string{"event"})
}, []string{metrics.LabelEvent})

templateMsgHandlingDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Help: "How long it took to process the message",
Namespace: "patchman_engine",
Subsystem: "listener",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemListener,
Name: "template_message_handling_duration_seconds",
}, []string{"event"})
}, []string{metrics.LabelEvent})
reposAddedCnt = prometheus.NewCounter(prometheus.CounterOpts{
Help: "How many repositories were added",
Namespace: "patchman_engine",
Subsystem: "listener",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemListener,
Name: "repos_added",
})

receivedFromReporter = prometheus.NewCounterVec(prometheus.CounterOpts{
Help: "How many messages were received from which reporter",
Namespace: "patchman_engine",
Subsystem: "listener",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemListener,
Name: "received_from_reporter",
}, []string{"reporter"})

messagePartDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Help: "How long particular listener part took",
Namespace: "patchman_engine",
Subsystem: "listener",
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemListener,
Name: "kafka_message_part_duration_seconds",
}, []string{"part"})
)
Expand Down
4 changes: 2 additions & 2 deletions manager/controllers/advisory_systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ var AdvisorySystemOpts = ListOpts{
},
},
DefaultSort: "-last_upload",
StableSort: "si.id",
SearchFields: []string{"si.display_name"},
StableSort: systemInventoryID,
SearchFields: []string{systemInventoryDisplayName},
}

func advisorySystemsCommon(c *gin.Context) (*gorm.DB, *ListMeta, []string, error) {
Expand Down
6 changes: 3 additions & 3 deletions manager/controllers/advisory_systems_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var AdvisorySystemExportOpts = ListOpts{
},
},
DefaultSort: "-last_upload",
StableSort: "si.id",
SearchFields: []string{"si.display_name"},
StableSort: systemInventoryID,
SearchFields: []string{systemInventoryDisplayName},
}

// @Summary Export systems for my account
Expand Down Expand Up @@ -86,7 +86,7 @@ func AdvisorySystemsExportHandler(c *gin.Context) {
} // Error handled in method itself
query, _ = ApplyInventoryFilter(filters, query, "si.inventory_id")

query = query.Order("si.id")
query = query.Order(systemInventoryID)
query, err = ExportListCommon(query, c, AdvisorySystemExportOpts)
if err != nil {
return
Expand Down
4 changes: 2 additions & 2 deletions manager/controllers/package_systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ var PackageSystemsOpts = ListOpts{
// By default, we show only fresh systems. If all systems are required, you must pass in:true,false filter into the api
DefaultFilters: map[string]FilterData{},
DefaultSort: "inventory_id",
StableSort: "si.id",
SearchFields: []string{"si.display_name"},
StableSort: systemInventoryID,
SearchFields: []string{systemInventoryDisplayName},
}

//nolint:lll
Expand Down
4 changes: 2 additions & 2 deletions manager/controllers/systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ var SystemsSelect = database.MustGetSelect(&SystemDBLookup{})
var SystemOpts = ListOpts{
Fields: SystemsFields,
DefaultSort: "-last_upload",
StableSort: "si.id",
SearchFields: []string{"si.display_name"},
StableSort: systemInventoryID,
SearchFields: []string{systemInventoryDisplayName},
}

type SystemsID struct {
Expand Down
2 changes: 1 addition & 1 deletion manager/controllers/systems_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func SystemsExportHandler(c *gin.Context) {

var systems []SystemDBLookupExtended

query = query.Order("si.id")
query = query.Order(systemInventoryID)
query, err = ExportListCommon(query, c, SystemOpts)
if err != nil {
return
Expand Down
4 changes: 2 additions & 2 deletions manager/controllers/template_systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var TemplateSystemOpts = ListOpts{
Fields: templateSystemFields,
DefaultFilters: map[string]FilterData{},
DefaultSort: "-display_name",
StableSort: "si.id",
SearchFields: []string{"si.display_name"},
StableSort: systemInventoryID,
SearchFields: []string{systemInventoryDisplayName},
}

type TemplateSystemsDBLookup struct {
Expand Down
2 changes: 2 additions & 0 deletions manager/controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const InvalidFilter = "Invalid filter field: %v"
const InvalidTagMsg = "Invalid tag '%s'. Use 'namespace/key=val format'"
const InvalidNestedFilter = "Nested operators not yet implemented for standard filters"
const FilterNotSupportedMsg = "filtering not supported on this endpoint"
const systemInventoryID = "si.id"
const systemInventoryDisplayName = "si.display_name"

var tagRegex = regexp.MustCompile(`([^/=]+)/([^/=]+)(=([^/=]+))?`)

Expand Down
Loading
Loading