Commit 23f0a170 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Clean up storage write reject count metric name.

parent 81c4ef1e
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -523,7 +523,7 @@ func storageWriteObject(ctx context.Context, logger *zap.Logger, metrics Metrics
		if err == sql.ErrNoRows {
			if object.Version != "" && object.Version != "*" {
				// Conditional write with a specific version but the object did not exist at all.
				metrics.StorageRejectCount(map[string]string{"collection": object.Collection}, 1)
				metrics.StorageWriteRejectCount(map[string]string{"collection": object.Collection}, 1)
				return nil, runtime.ErrStorageRejectedVersion
			}
		} else {
@@ -536,7 +536,7 @@ func storageWriteObject(ctx context.Context, logger *zap.Logger, metrics Metrics
		// An object existed, and it's a conditional write that either:
		// - Expects no object.
		// - Or expects a given version, but it does not match.
		metrics.StorageRejectCount(map[string]string{"collection": object.Collection}, 1)
		metrics.StorageWriteRejectCount(map[string]string{"collection": object.Collection}, 1)
		return nil, runtime.ErrStorageRejectedVersion
	}

@@ -605,14 +605,14 @@ func storageWriteObject(ctx context.Context, logger *zap.Logger, metrics Metrics
		logger.Debug("Could not write storage object, exec error.", zap.Any("object", object), zap.String("query", query), zap.Error(err))
		var pgErr *pgconn.PgError
		if errors.As(err, &pgErr) && pgErr.Code == dbErrorUniqueViolation {
			metrics.StorageRejectCount(map[string]string{"collection": object.Collection}, 1)
			metrics.StorageWriteRejectCount(map[string]string{"collection": object.Collection}, 1)
			return nil, runtime.ErrStorageRejectedVersion
		}
		return nil, err
	}
	if rowsAffected, err := res.RowsAffected(); rowsAffected != 1 {
		logger.Debug("Could not write storage object, rowsAffected error.", zap.Any("object", object), zap.String("query", query), zap.Error(err))
		metrics.StorageRejectCount(map[string]string{"collection": object.Collection}, 1)
		metrics.StorageWriteRejectCount(map[string]string{"collection": object.Collection}, 1)
		return nil, runtime.ErrStorageRejectedVersion
	}

+3 −3
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ type Metrics interface {

	PresenceEvent(dequeueElapsed, processElapsed time.Duration)

	StorageRejectCount(tags map[string]string, delta int64)
	StorageWriteRejectCount(tags map[string]string, delta int64)

	CustomCounter(name string, tags map[string]string, delta int64)
	CustomGauge(name string, tags map[string]string, value float64)
@@ -431,12 +431,12 @@ func (m *LocalMetrics) PresenceEvent(dequeueElapsed, processElapsed time.Duratio
	m.PrometheusScope.Timer("presence_event_process_latency_ms").Record(processElapsed)
}

func (m *LocalMetrics) StorageRejectCount(tags map[string]string, delta int64) {
func (m *LocalMetrics) StorageWriteRejectCount(tags map[string]string, delta int64) {
	scope := m.PrometheusScope
	if len(tags) != 0 {
		scope = scope.Tagged(tags)
	}
	scope.Counter("storage_reject_count").Inc(delta)
	scope.Counter("storage_write_reject_count").Inc(delta)
}

// CustomCounter adds the given delta to a counter with the specified name and tags.