Skip to content

Commit

Permalink
lift DeploymentUidKey attribute to newOtelResource (#2296)
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex authored Nov 26, 2024
1 parent 83350b5 commit 2d9dd21
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 0 additions & 2 deletions flow/connectors/postgres/cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/PeerDB-io/peer-flow/model"
"github.com/PeerDB-io/peer-flow/model/qvalue"
"github.com/PeerDB-io/peer-flow/otel_metrics"
"github.com/PeerDB-io/peer-flow/peerdbenv"
"github.com/PeerDB-io/peer-flow/shared"
)

Expand Down Expand Up @@ -481,7 +480,6 @@ func PullCdcRecords[Items model.Items](
if fetchedBytesCounter != nil {
fetchedBytesCounter.Add(ctx, int64(len(msg.Data)), metric.WithAttributeSet(attribute.NewSet(
attribute.String(otel_metrics.FlowNameKey, req.FlowJobName),
attribute.String(otel_metrics.DeploymentUidKey, peerdbenv.PeerDBDeploymentUID()),
)))
}

Expand Down
6 changes: 1 addition & 5 deletions flow/connectors/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -1223,8 +1223,7 @@ func (c *PostgresConnector) HandleSlotInfo(
attribute.String(otel_metrics.FlowNameKey, alertKeys.FlowName),
attribute.String(otel_metrics.PeerNameKey, alertKeys.PeerName),
attribute.String(otel_metrics.SlotNameKey, alertKeys.SlotName),
attribute.String(otel_metrics.DeploymentUidKey, peerdbenv.PeerDBDeploymentUID())),
))
)))
} else {
logger.Warn("warning: slotMetricGauges.SlotLagGauge is nil")
}
Expand All @@ -1241,7 +1240,6 @@ func (c *PostgresConnector) HandleSlotInfo(
slotMetricGauges.OpenConnectionsGauge.Record(ctx, res.CurrentOpenConnections, metric.WithAttributeSet(attribute.NewSet(
attribute.String(otel_metrics.FlowNameKey, alertKeys.FlowName),
attribute.String(otel_metrics.PeerNameKey, alertKeys.PeerName),
attribute.String(otel_metrics.DeploymentUidKey, peerdbenv.PeerDBDeploymentUID()),
)))
} else {
logger.Warn("warning: slotMetricGauges.OpenConnectionsGauge is nil")
Expand All @@ -1257,7 +1255,6 @@ func (c *PostgresConnector) HandleSlotInfo(
metric.WithAttributeSet(attribute.NewSet(
attribute.String(otel_metrics.FlowNameKey, alertKeys.FlowName),
attribute.String(otel_metrics.PeerNameKey, alertKeys.PeerName),
attribute.String(otel_metrics.DeploymentUidKey, peerdbenv.PeerDBDeploymentUID()),
)),
)
} else {
Expand All @@ -1281,7 +1278,6 @@ func (c *PostgresConnector) HandleSlotInfo(
metric.WithAttributeSet(attribute.NewSet(
attribute.String(otel_metrics.FlowNameKey, alertKeys.FlowName),
attribute.String(otel_metrics.PeerNameKey, alertKeys.PeerName),
attribute.String(otel_metrics.DeploymentUidKey, peerdbenv.PeerDBDeploymentUID()),
)),
)
} else {
Expand Down
7 changes: 5 additions & 2 deletions flow/otel_metrics/otel_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ func (om *OtelManager) GetOrInitInt64Counter(name string, opts ...metric.Int64Co

// newOtelResource returns a resource describing this application.
func newOtelResource(otelServiceName string, attrs ...attribute.KeyValue) (*resource.Resource, error) {
allAttrs := append([]attribute.KeyValue{semconv.ServiceNameKey.String(otelServiceName)}, attrs...)
allAttrs := append([]attribute.KeyValue{
semconv.ServiceNameKey.String(otelServiceName),
attribute.String(DeploymentUidKey, peerdbenv.PeerDBDeploymentUID()),
}, attrs...)
return resource.Merge(
resource.Default(),
resource.NewWithAttributes(
Expand Down Expand Up @@ -181,7 +184,7 @@ func SetupPeerDBMetricsProvider(otelServiceName string) (*sdkmetric.MeterProvide
}

func SetupTemporalMetricsProvider(otelServiceName string) (*sdkmetric.MeterProvider, error) {
otelResource, err := newOtelResource(otelServiceName, attribute.String(DeploymentUidKey, peerdbenv.PeerDBDeploymentUID()))
otelResource, err := newOtelResource(otelServiceName)
if err != nil {
return nil, fmt.Errorf("failed to create OpenTelemetry resource: %w", err)
}
Expand Down

0 comments on commit 2d9dd21

Please sign in to comment.