Skip to content

Commit 286a892

Browse files
committed
feat: Expose invocation ID in OpenTelemetry metrics
1 parent 7076899 commit 286a892

File tree

7 files changed

+11
-10
lines changed

7 files changed

+11
-10
lines changed

scheduler/metrics/metrics.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (s *Metrics) Equal(other *Metrics) bool {
8585
return true
8686
}
8787

88-
func getOtelMeters(tableName string, clientID string) *OtelMeters {
88+
func getOtelMeters(tableName, clientID, invocationID string) *OtelMeters {
8989
resources, err := otel.Meter(OtelName).Int64Counter("sync.table.resources",
9090
metric.WithDescription("Number of resources synced for a table"),
9191
metric.WithUnit("/{tot}"),
@@ -136,21 +136,22 @@ func getOtelMeters(tableName string, clientID string) *OtelMeters {
136136
attributes: []attribute.KeyValue{
137137
attribute.Key("sync.client.id").String(clientID),
138138
attribute.Key("sync.table.name").String(tableName),
139+
attribute.Key("sync.invocation.id").String(invocationID),
139140
},
140141
}
141142
}
142143

143-
func (s *Metrics) InitWithClients(table *schema.Table, clients []schema.ClientMeta) {
144+
func (s *Metrics) InitWithClients(table *schema.Table, clients []schema.ClientMeta, invocationID string) {
144145
s.TableClient[table.Name] = make(map[string]*TableClientMetrics, len(clients))
145146
for _, client := range clients {
146147
tableName := table.Name
147148
clientID := client.ID()
148149
s.TableClient[tableName][clientID] = &TableClientMetrics{
149-
otelMeters: getOtelMeters(tableName, clientID),
150+
otelMeters: getOtelMeters(tableName, clientID, invocationID),
150151
}
151152
}
152153
for _, relation := range table.Relations {
153-
s.InitWithClients(relation, clients)
154+
s.InitWithClients(relation, clients, invocationID)
154155
}
155156
}
156157

scheduler/queue/scheduler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestScheduler(t *testing.T) {
7979
}
8080

8181
for _, tc := range tableClients {
82-
m.InitWithClients(tc.Table, []schema.ClientMeta{tc.Client})
82+
m.InitWithClients(tc.Table, []schema.ClientMeta{tc.Client}, scheduler.invocationID)
8383
}
8484

8585
resolvedResources := make(chan *schema.Resource)

scheduler/scheduler_debug.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (s *syncClient) syncTest(ctx context.Context, syncMultiplier int, resolvedR
5050
preInitialisedClients[i] = clients
5151
// we do this here to avoid locks so we initialize the metrics structure once in the main goroutine
5252
// and then we can just read from it in the other goroutines concurrently given we are not writing to it.
53-
s.metrics.InitWithClients(table, clients)
53+
s.metrics.InitWithClients(table, clients, s.invocationID)
5454
}
5555

5656
// First interleave the tables like in round-robin

scheduler/scheduler_dfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (s *syncClient) syncDfs(ctx context.Context, resolvedResources chan<- *sche
3939
preInitialisedClients[i] = clients
4040
// we do this here to avoid locks so we initial the metrics structure once in the main goroutines
4141
// and then we can just read from it in the other goroutines concurrently given we are not writing to it.
42-
s.metrics.InitWithClients(table, clients)
42+
s.metrics.InitWithClients(table, clients, s.invocationID)
4343
}
4444

4545
tableClients := make([]tableClient, 0)

scheduler/scheduler_round_robin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (s *syncClient) syncRoundRobin(ctx context.Context, resolvedResources chan<
3333
preInitialisedClients[i] = clients
3434
// we do this here to avoid locks so we initial the metrics structure once in the main goroutines
3535
// and then we can just read from it in the other goroutines concurrently given we are not writing to it.
36-
s.metrics.InitWithClients(table, clients)
36+
s.metrics.InitWithClients(table, clients, s.invocationID)
3737
}
3838

3939
tableClients := roundRobinInterleave(s.tables, preInitialisedClients)

scheduler/scheduler_shuffle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (s *syncClient) syncShuffle(ctx context.Context, resolvedResources chan<- *
3333
preInitialisedClients[i] = clients
3434
// we do this here to avoid locks so we initial the metrics structure once in the main goroutines
3535
// and then we can just read from it in the other goroutines concurrently given we are not writing to it.
36-
s.metrics.InitWithClients(table, clients)
36+
s.metrics.InitWithClients(table, clients, s.invocationID)
3737
}
3838

3939
// First interleave the tables like in round-robin

scheduler/scheduler_shuffle_queue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (s *syncClient) syncShuffleQueue(ctx context.Context, resolvedResources cha
2121
preInitialisedClients[i] = clients
2222
// we do this here to avoid locks so we initial the metrics structure once in the main goroutines
2323
// and then we can just read from it in the other goroutines concurrently given we are not writing to it.
24-
s.metrics.InitWithClients(table, clients)
24+
s.metrics.InitWithClients(table, clients, s.invocationID)
2525
}
2626

2727
tableClients := roundRobinInterleave(s.tables, preInitialisedClients)

0 commit comments

Comments
 (0)