Skip to content

Commit 53a34b4

Browse files
committed
introduce latency metrics and refactored shard statistics
1 parent 0228e3c commit 53a34b4

File tree

22 files changed

+1002
-293
lines changed

22 files changed

+1002
-293
lines changed

common/metrics/defs.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,7 @@ const (
14791479
ShardDistributorStoreAssignShardScope
14801480
ShardDistributorStoreAssignShardsScope
14811481
ShardDistributorStoreDeleteExecutorsScope
1482+
ShardDistributorStoreGetShardStatsScope
14821483
ShardDistributorStoreDeleteShardStatsScope
14831484
ShardDistributorStoreGetHeartbeatScope
14841485
ShardDistributorStoreGetStateScope
@@ -2167,6 +2168,7 @@ var ScopeDefs = map[ServiceIdx]map[ScopeIdx]scopeDefinition{
21672168
ShardDistributorStoreAssignShardScope: {operation: "StoreAssignShard"},
21682169
ShardDistributorStoreAssignShardsScope: {operation: "StoreAssignShards"},
21692170
ShardDistributorStoreDeleteExecutorsScope: {operation: "StoreDeleteExecutors"},
2171+
ShardDistributorStoreGetShardStatsScope: {operation: "StoreGetShardStats"},
21702172
ShardDistributorStoreDeleteShardStatsScope: {operation: "StoreDeleteShardStats"},
21712173
ShardDistributorStoreGetHeartbeatScope: {operation: "StoreGetHeartbeat"},
21722174
ShardDistributorStoreGetStateScope: {operation: "StoreGetState"},
@@ -2966,6 +2968,13 @@ const (
29662968
ShardDistributorStoreRequestsPerNamespace
29672969
ShardDistributorStoreLatencyHistogramPerNamespace
29682970

2971+
// ShardDistributorShardAssignmentDistributionLatency measures the time taken between assignment of a shard
2972+
// and the time it is fully distributed to executors
2973+
ShardDistributorShardAssignmentDistributionLatency
2974+
2975+
// ShardDistributorShardHandoverLatency measures the time taken to hand over a shard from one executor to another
2976+
ShardDistributorShardHandoverLatency
2977+
29692978
NumShardDistributorMetrics
29702979
)
29712980

@@ -3749,6 +3758,9 @@ var MetricDefs = map[ServiceIdx]map[MetricIdx]metricDefinition{
37493758
ShardDistributorStoreFailuresPerNamespace: {metricName: "shard_distributor_store_failures_per_namespace", metricType: Counter},
37503759
ShardDistributorStoreRequestsPerNamespace: {metricName: "shard_distributor_store_requests_per_namespace", metricType: Counter},
37513760
ShardDistributorStoreLatencyHistogramPerNamespace: {metricName: "shard_distributor_store_latency_histogram_per_namespace", metricType: Histogram, buckets: ShardDistributorExecutorStoreLatencyBuckets},
3761+
3762+
ShardDistributorShardAssignmentDistributionLatency: {metricName: "shard_distributor_shard_assignment_distribution_latency", metricType: Histogram, buckets: Default1ms100s.buckets()},
3763+
ShardDistributorShardHandoverLatency: {metricName: "shard_distributor_shard_handover_latency", metricType: Histogram, buckets: Default1ms100s.buckets()},
37523764
},
37533765
}
37543766

common/metrics/tags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ func NamespaceTypeTag(namespaceType string) Tag {
352352
return metricWithUnknown("namespace_type", namespaceType)
353353
}
354354

355+
func HandoverTypeTag(handoverType string) Tag {
356+
return metricWithUnknown("handover_type", handoverType)
357+
}
358+
355359
func TaskCategoryTag(category string) Tag {
356360
return metricWithUnknown("task_category", category)
357361
}

common/ptr/ptr.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package ptr
2+
3+
// ToPtr returns a pointer to the given value.
4+
func ToPtr[T any](v T) *T {
5+
return &v
6+
}

common/types/sharddistributor.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222

2323
package types
2424

25-
import "fmt"
25+
import (
26+
"fmt"
27+
)
2628

27-
//go:generate enumer -type=ExecutorStatus,ShardStatus,AssignmentStatus,MigrationMode -trimprefix=ExecutorStatus,ShardStatus,AssignmentStatus,MigrationMode -json -output sharddistributor_statuses_enumer_generated.go
29+
//go:generate enumer -type=ExecutorStatus,ShardStatus,AssignmentStatus,MigrationMode,HandoverType -trimprefix=ExecutorStatus,ShardStatus,AssignmentStatus,MigrationMode,HandoverType -json -output sharddistributor_statuses_enumer_generated.go
2830

2931
type GetShardOwnerRequest struct {
3032
ShardKey string
@@ -217,6 +219,30 @@ const (
217219
AssignmentStatusREADY AssignmentStatus = 1
218220
)
219221

222+
// HandoverType is used to indicate the type of handover that occurred during shard reassignment.
223+
// Type is persisted to the DB with a string value mapping.
224+
// Beware - if we want to change the name - it should be backward compatible and should be done in two steps.
225+
type HandoverType int32
226+
227+
const (
228+
HandoverTypeINVALID HandoverType = 0
229+
230+
// HandoverTypeGRACEFUL
231+
// Graceful handover indicates that the shard was transferred in a way that allowed
232+
// the previous owner had a chance to finish processing before the shard was reassigned.
233+
HandoverTypeGRACEFUL HandoverType = 1
234+
235+
// HandoverTypeEMERGENCY
236+
// Emergency handover indicates that the shard was transferred abruptly without
237+
// allowing the previous owner to finish processing.
238+
HandoverTypeEMERGENCY HandoverType = 2
239+
)
240+
241+
// Ptr returns a pointer to the HandoverType value.
242+
func (t HandoverType) Ptr() *HandoverType {
243+
return &t
244+
}
245+
220246
type MigrationMode int32
221247

222248
const (

common/types/sharddistributor_statuses_enumer_generated.go

Lines changed: 92 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)