Skip to content

Commit e41dba4

Browse files
committed
add log and metric to instrument count of catalog source snapshots
Signed-off-by: Joe Lanford <[email protected]>
1 parent edb751b commit e41dba4

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

pkg/controller/operators/catalog/operator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ func (o *Operator) syncSourceState(state grpc.SourceState) {
781781

782782
o.logger.Infof("state.Key.Namespace=%s state.Key.Name=%s state.State=%s", state.Key.Namespace, state.Key.Name, state.State.String())
783783
metrics.RegisterCatalogSourceState(state.Key.Name, state.Key.Namespace, state.State)
784+
metrics.RegisterCatalogSourceSnapshotsTotal(state.Key.Name, state.Key.Namespace)
784785

785786
switch state.State {
786787
case connectivity.Ready:
@@ -896,6 +897,7 @@ func (o *Operator) handleCatSrcDeletion(obj interface{}) {
896897
o.logger.WithField("source", sourceKey).Info("removed client for deleted catalogsource")
897898

898899
metrics.DeleteCatalogSourceStateMetric(catsrc.GetName(), catsrc.GetNamespace())
900+
metrics.DeleteCatalogSourceSnapshotsTotal(catsrc.GetName(), catsrc.GetNamespace())
899901
}
900902

901903
func validateSourceType(logger *logrus.Entry, in *v1alpha1.CatalogSource) (out *v1alpha1.CatalogSource, continueSync bool, _ error) {

pkg/controller/registry/resolver/source_registry.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
v1alpha1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
1313
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
1414
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache"
15+
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
1516
"github.com/operator-framework/operator-registry/pkg/api"
1617
"github.com/operator-framework/operator-registry/pkg/client"
1718
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
@@ -143,6 +144,9 @@ type registrySource struct {
143144
}
144145

145146
func (s *registrySource) Snapshot(ctx context.Context) (*cache.Snapshot, error) {
147+
s.logger.Printf("requesting snapshot for catalog source %s/%s", s.key.Namespace, s.key.Name)
148+
metrics.IncrementCatalogSourceSnapshotsTotal(s.key.Name, s.key.Namespace)
149+
146150
// Fetching default channels this way makes many round trips
147151
// -- may need to either add a new API to fetch all at once,
148152
// or embed the information into Bundle.

pkg/metrics/metrics.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ var (
152152
[]string{NamespaceLabel, NameLabel},
153153
)
154154

155+
catalogSourceSnapshotsTotal = prometheus.NewCounterVec(
156+
prometheus.CounterOpts{
157+
Name: "catalog_source_snapshots_total",
158+
Help: "The number of times the catalog operator has requested a snapshot of data from a catalog source",
159+
},
160+
[]string{NamespaceLabel, NameLabel},
161+
)
162+
155163
// exported since it's not handled by HandleMetrics
156164
CSVUpgradeCount = prometheus.NewCounter(
157165
prometheus.CounterOpts{
@@ -250,6 +258,7 @@ func RegisterCatalog() {
250258
prometheus.MustRegister(subscriptionCount)
251259
prometheus.MustRegister(catalogSourceCount)
252260
prometheus.MustRegister(catalogSourceReady)
261+
prometheus.MustRegister(catalogSourceSnapshotsTotal)
253262
prometheus.MustRegister(SubscriptionSyncCount)
254263
prometheus.MustRegister(dependencyResolutionSummary)
255264
prometheus.MustRegister(installPlanWarningCount)
@@ -272,6 +281,18 @@ func DeleteCatalogSourceStateMetric(name, namespace string) {
272281
catalogSourceReady.DeleteLabelValues(namespace, name)
273282
}
274283

284+
func RegisterCatalogSourceSnapshotsTotal(name, namespace string) {
285+
catalogSourceSnapshotsTotal.WithLabelValues(namespace, name).Add(0)
286+
}
287+
288+
func IncrementCatalogSourceSnapshotsTotal(name, namespace string) {
289+
catalogSourceSnapshotsTotal.WithLabelValues(namespace, name).Inc()
290+
}
291+
292+
func DeleteCatalogSourceSnapshotsTotal(name, namespace string) {
293+
catalogSourceSnapshotsTotal.DeleteLabelValues(namespace, name)
294+
}
295+
275296
func DeleteCSVMetric(oldCSV *operatorsv1alpha1.ClusterServiceVersion) {
276297
// Delete the old CSV metrics
277298
csvAbnormal.DeleteLabelValues(oldCSV.Namespace, oldCSV.Name, oldCSV.Spec.Version.String(), string(oldCSV.Status.Phase), string(oldCSV.Status.Reason))

0 commit comments

Comments
 (0)