37
37
import org .apache .logging .log4j .message .ParameterizedMessage ;
38
38
import org .opensearch .Version ;
39
39
import org .opensearch .cluster .ClusterInfoService ;
40
+ import org .opensearch .cluster .ClusterManagerMetrics ;
40
41
import org .opensearch .cluster .ClusterState ;
41
42
import org .opensearch .cluster .RestoreInProgress ;
42
43
import org .opensearch .cluster .health .ClusterHealthStatus ;
56
57
import org .opensearch .cluster .routing .allocation .decider .AllocationDeciders ;
57
58
import org .opensearch .cluster .routing .allocation .decider .Decision ;
58
59
import org .opensearch .common .settings .Settings ;
60
+ import org .opensearch .common .unit .TimeValue ;
59
61
import org .opensearch .gateway .GatewayAllocator ;
60
62
import org .opensearch .gateway .PriorityComparator ;
61
63
import org .opensearch .gateway .ShardsBatchGatewayAllocator ;
62
64
import org .opensearch .snapshots .SnapshotsInfoService ;
65
+ import org .opensearch .telemetry .metrics .noop .NoopMetricsRegistry ;
63
66
64
67
import java .util .ArrayList ;
65
68
import java .util .Collections ;
@@ -96,6 +99,7 @@ public class AllocationService {
96
99
private final ShardsAllocator shardsAllocator ;
97
100
private final ClusterInfoService clusterInfoService ;
98
101
private SnapshotsInfoService snapshotsInfoService ;
102
+ private final ClusterManagerMetrics clusterManagerMetrics ;
99
103
100
104
// only for tests that use the GatewayAllocator as the unique ExistingShardsAllocator
101
105
public AllocationService (
@@ -105,32 +109,40 @@ public AllocationService(
105
109
ClusterInfoService clusterInfoService ,
106
110
SnapshotsInfoService snapshotsInfoService
107
111
) {
108
- this (allocationDeciders , shardsAllocator , clusterInfoService , snapshotsInfoService );
112
+ this (
113
+ allocationDeciders ,
114
+ shardsAllocator ,
115
+ clusterInfoService ,
116
+ snapshotsInfoService ,
117
+ new ClusterManagerMetrics (NoopMetricsRegistry .INSTANCE )
118
+ );
109
119
setExistingShardsAllocators (Collections .singletonMap (GatewayAllocator .ALLOCATOR_NAME , gatewayAllocator ));
110
120
}
111
121
112
122
public AllocationService (
113
123
AllocationDeciders allocationDeciders ,
114
124
ShardsAllocator shardsAllocator ,
115
125
ClusterInfoService clusterInfoService ,
116
- SnapshotsInfoService snapshotsInfoService
126
+ SnapshotsInfoService snapshotsInfoService ,
127
+ ClusterManagerMetrics clusterManagerMetrics
117
128
) {
118
- this (allocationDeciders , shardsAllocator , clusterInfoService , snapshotsInfoService , Settings .EMPTY );
129
+ this (allocationDeciders , shardsAllocator , clusterInfoService , snapshotsInfoService , Settings .EMPTY , clusterManagerMetrics );
119
130
}
120
131
121
132
public AllocationService (
122
133
AllocationDeciders allocationDeciders ,
123
134
ShardsAllocator shardsAllocator ,
124
135
ClusterInfoService clusterInfoService ,
125
136
SnapshotsInfoService snapshotsInfoService ,
126
- Settings settings
127
-
137
+ Settings settings ,
138
+ ClusterManagerMetrics clusterManagerMetrics
128
139
) {
129
140
this .allocationDeciders = allocationDeciders ;
130
141
this .shardsAllocator = shardsAllocator ;
131
142
this .clusterInfoService = clusterInfoService ;
132
143
this .snapshotsInfoService = snapshotsInfoService ;
133
144
this .settings = settings ;
145
+ this .clusterManagerMetrics = clusterManagerMetrics ;
134
146
}
135
147
136
148
/**
@@ -550,11 +562,15 @@ private void reroute(RoutingAllocation allocation) {
550
562
assert AutoExpandReplicas .getAutoExpandReplicaChanges (allocation .metadata (), allocation ).isEmpty ()
551
563
: "auto-expand replicas out of sync with number of nodes in the cluster" ;
552
564
assert assertInitialized ();
553
-
565
+ long rerouteStartTimeNS = System . nanoTime ();
554
566
removeDelayMarkers (allocation );
555
567
556
568
allocateExistingUnassignedShards (allocation ); // try to allocate existing shard copies first
557
569
shardsAllocator .allocate (allocation );
570
+ clusterManagerMetrics .recordLatency (
571
+ clusterManagerMetrics .rerouteHistogram ,
572
+ (double ) Math .max (0 , TimeValue .nsecToMSec (System .nanoTime () - rerouteStartTimeNS ))
573
+ );
558
574
assert RoutingNodes .assertShardStats (allocation .routingNodes ());
559
575
}
560
576
0 commit comments