Skip to content

Commit f545158

Browse files
Feature/add mis endpoints in cluster (#703)
1 parent 08ba989 commit f545158

File tree

4 files changed

+978
-0
lines changed

4 files changed

+978
-0
lines changed

v2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Add missing endpoints from replication to v2
55
- Add missing endpoints from monitoring to v2
66
- Add missing endpoints from administration to v2
7+
- Add missing endpoints from cluster to v2
78

89
## [2.1.5](https://github.com/arangodb/go-driver/tree/v2.1.5) (2025-08-31)
910
- Add tasks endpoints to v2

v2/arangodb/client_admin_cluster.go

Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,53 @@ type ClientAdminCluster interface {
4848
// This function is suitable for servers of type coordinator or dbServer.
4949
// The use of `ClientServerAdmin.Shutdown` is highly recommended above this function.
5050
RemoveServer(ctx context.Context, serverID ServerID) error
51+
52+
// ClusterStatistics retrieves statistical information from a specific DBServer
53+
// in an ArangoDB cluster. The statistics include system, client, HTTP, and server
54+
// metrics such as CPU usage, memory, connections, requests, and transaction details.
55+
ClusterStatistics(ctx context.Context, dbServer string) (ClusterStatisticsResponse, error)
56+
57+
// ClusterEndpoints returns the endpoints of a cluster.
58+
ClusterEndpoints(ctx context.Context) (ClusterEndpointsResponse, error)
59+
60+
// GetDBServerMaintenance retrieves the maintenance status of a given DB-Server.
61+
// It checks whether the specified DB-Server is in maintenance mode and,
62+
// if so, until what date and time (in ISO 8601 format) the maintenance will last.
63+
GetDBServerMaintenance(ctx context.Context, dbServer string) (ClusterMaintenanceResponse, error)
64+
65+
// SetDBServerMaintenance sets the maintenance mode for a specific DB-Server.
66+
// This endpoint affects only the given DB-Server. When in maintenance mode,
67+
// the server is excluded from supervision actions such as shard distribution
68+
// or failover. This is typically used during planned restarts or upgrades.
69+
SetDBServerMaintenance(ctx context.Context, dbServer string, opts *ClusterMaintenanceOpts) error
70+
71+
// SetClusterMaintenance sets the cluster-wide supervision maintenance mode.
72+
// This endpoint affects the supervision (Agency) component of the cluster.
73+
// While enabled, automatic failovers, shard movements, and repair jobs
74+
// are suspended. The mode can be:
75+
//
76+
// - "on": Enable maintenance mode for the default 60 minutes.
77+
// - "off": Disable maintenance mode immediately.
78+
// - "<number>": Enable maintenance mode for <number> seconds.
79+
//
80+
// Be aware that no automatic failovers of any kind will take place while
81+
// the maintenance mode is enabled. The supervision will reactivate itself
82+
// automatically after the duration expires.
83+
SetClusterMaintenance(ctx context.Context, mode *string) error
84+
85+
// GetClusterRebalance retrieves the current cluster imbalance status.
86+
// It computes the imbalance across leaders and shards, and includes the number of
87+
// ongoing and pending move shard operations.
88+
GetClusterRebalance(ctx context.Context) (RebalanceResponse, error)
89+
90+
// ComputeClusterRebalance computes a set of move shard operations to improve cluster balance.
91+
ComputeClusterRebalance(ctx context.Context, opts *RebalanceRequestBody) (RebalancePlan, error)
92+
93+
// ExecuteClusterRebalance executes a set of shard move operations on the cluster.
94+
ExecuteClusterRebalance(ctx context.Context, opts *ExecuteRebalanceRequestBody) error
95+
96+
// ComputeAndExecuteClusterRebalance computes moves internally then executes them.
97+
ComputeAndExecuteClusterRebalance(ctx context.Context, opts *RebalanceRequestBody) (RebalancePlan, error)
5198
}
5299

53100
type NumberOfServersResponse struct {
@@ -126,3 +173,269 @@ func (i DatabaseInventory) ViewByName(name string) (InventoryView, bool) {
126173
}
127174
return InventoryView{}, false
128175
}
176+
177+
// ClusterStatisticsResponse contains statistical data about the server as a whole.
178+
type ClusterStatisticsResponse struct {
179+
Time *float64 `json:"time,omitempty"`
180+
Enabled *bool `json:"enabled,omitempty"`
181+
System *SystemStats `json:"system,omitempty"`
182+
Client *ClientStats `json:"client,omitempty"`
183+
ClientUser *ClientStats `json:"clientUser,omitempty"`
184+
HTTP *HTTPStats `json:"http,omitempty"`
185+
Server *ServerStats `json:"server,omitempty"`
186+
}
187+
188+
// SystemStats contains statistical data about the system, this is part of
189+
type SystemStats struct {
190+
MinorPageFaults *int64 `json:"minorPageFaults,omitempty"`
191+
MajorPageFaults *int64 `json:"majorPageFaults,omitempty"`
192+
UserTime *float32 `json:"userTime,omitempty"`
193+
SystemTime *float32 `json:"systemTime,omitempty"`
194+
NumberOfThreads *int `json:"numberOfThreads,omitempty"`
195+
ResidentSize *int64 `json:"residentSize,omitempty"`
196+
ResidentSizePercent *float64 `json:"residentSizePercent,omitempty"`
197+
VirtualSize *int64 `json:"virtualSize,omitempty"`
198+
}
199+
200+
type ClientStats struct {
201+
HttpConnections *int `json:"httpConnections,omitempty"`
202+
ConnectionTime *TimeStats `json:"connectionTime,omitempty"`
203+
TotalTime *TimeStats `json:"totalTime,omitempty"`
204+
RequestTime *TimeStats `json:"requestTime,omitempty"`
205+
QueueTime *TimeStats `json:"queueTime,omitempty"`
206+
IoTime *TimeStats `json:"ioTime,omitempty"`
207+
BytesSent *TimeStats `json:"bytesSent,omitempty"`
208+
BytesReceived *TimeStats `json:"bytesReceived,omitempty"`
209+
}
210+
211+
// TimeStats is used for various time-related statistics.
212+
type TimeStats struct {
213+
Sum *float64 `json:"sum,omitempty"`
214+
Count *int `json:"count,omitempty"`
215+
Counts []int `json:"counts"`
216+
}
217+
218+
// HTTPStats contains statistics about the HTTP traffic.
219+
type HTTPStats struct {
220+
RequestsTotal *int `json:"requestsTotal,omitempty"`
221+
RequestsSuperuser *int `json:"requestsSuperuser,omitempty"`
222+
RequestsUser *int `json:"requestsUser,omitempty"`
223+
RequestsAsync *int `json:"requestsAsync,omitempty"`
224+
RequestsGet *int `json:"requestsGet,omitempty"`
225+
RequestsHead *int `json:"requestsHead,omitempty"`
226+
RequestsPost *int `json:"requestsPost,omitempty"`
227+
RequestsPut *int `json:"requestsPut,omitempty"`
228+
RequestsPatch *int `json:"requestsPatch,omitempty"`
229+
RequestsDelete *int `json:"requestsDelete,omitempty"`
230+
RequestsOptions *int `json:"requestsOptions,omitempty"`
231+
RequestsOther *int `json:"requestsOther,omitempty"`
232+
}
233+
234+
// ServerStats contains statistics about the server.
235+
type ServerStats struct {
236+
Uptime *float64 `json:"uptime,omitempty"`
237+
PhysicalMemory *int64 `json:"physicalMemory,omitempty"`
238+
Transactions *TransactionStats `json:"transactions,omitempty"`
239+
V8Context *V8ContextStats `json:"v8Context,omitempty"`
240+
Threads *ThreadStats `json:"threads,omitempty"`
241+
}
242+
243+
// TransactionStats contains statistics about transactions.
244+
type TransactionStats struct {
245+
Started *int `json:"started,omitempty"`
246+
Aborted *int `json:"aborted,omitempty"`
247+
Committed *int `json:"committed,omitempty"`
248+
IntermediateCommits *int `json:"intermediateCommits,omitempty"`
249+
ReadOnly *int `json:"readOnly,omitempty"`
250+
DirtyReadOnly *int `json:"dirtyReadOnly,omitempty"`
251+
}
252+
253+
// V8ContextStats contains statistics about V8 contexts.
254+
type V8ContextStats struct {
255+
Available *int `json:"available,omitempty"`
256+
Busy *int `json:"busy,omitempty"`
257+
Dirty *int `json:"dirty,omitempty"`
258+
Free *int `json:"free,omitempty"`
259+
Max *int `json:"max,omitempty"`
260+
Min *int `json:"min,omitempty"`
261+
Memory []MemoryStats `json:"memory"`
262+
}
263+
264+
// MemoryStats contains statistics about memory usage.
265+
type MemoryStats struct {
266+
ContextId *int `json:"contextId,omitempty"`
267+
TMax *float64 `json:"tMax,omitempty"`
268+
CountOfTimes *int `json:"countOfTimes,omitempty"`
269+
HeapMax *int64 `json:"heapMax,omitempty"`
270+
HeapMin *int64 `json:"heapMin,omitempty"`
271+
Invocations *int `json:"invocations,omitempty"`
272+
}
273+
274+
// ThreadStats contains statistics about threads.
275+
type ThreadStats struct {
276+
SchedulerThreads *int `json:"scheduler-threads,omitempty"`
277+
Blocked *int `json:"blocked,omitempty"`
278+
Queued *int `json:"queued,omitempty"`
279+
InProgress *int `json:"in-progress,omitempty"`
280+
DirectExec *int `json:"direct-exec,omitempty"`
281+
}
282+
283+
// It contains a list of cluster endpoints that a client can use
284+
// to connect to the ArangoDB cluster.
285+
type ClusterEndpointsResponse struct {
286+
// Endpoints is the list of cluster endpoints (usually coordinators)
287+
// that the client can use to connect to the cluster.
288+
Endpoints []ClusterEndpoint `json:"endpoints,omitempty"`
289+
}
290+
291+
// ClusterEndpoint represents a single cluster endpoint.
292+
// Each endpoint provides a URL to connect to a coordinator.
293+
type ClusterEndpoint struct {
294+
// Endpoint is the connection string (protocol + host + port)
295+
// of a coordinator in the cluster, e.g. "tcp://127.0.0.1:8529".
296+
Endpoint *string `json:"endpoint,omitempty"`
297+
}
298+
299+
// ClusterMaintenanceResponse represents the maintenance status of a DB-Server.
300+
type ClusterMaintenanceResponse struct {
301+
// The mode of the DB-Server. The value is "maintenance".
302+
Mode *string `json:"mode,omitempty"`
303+
304+
// Until what date and time the maintenance mode currently lasts,
305+
// in the ISO 8601 date/time format.
306+
Until *string `json:"until,omitempty"`
307+
}
308+
309+
// ClusterMaintenanceOpts represents the options for setting maintenance mode
310+
// on a DB-Server in an ArangoDB cluster.
311+
type ClusterMaintenanceOpts struct {
312+
// Mode specifies the maintenance mode to apply to the DB-Server.
313+
// Possible values:
314+
// - "maintenance": enable maintenance mode
315+
// - "normal": disable maintenance mode
316+
// This field is required.
317+
Mode *string `json:"mode"`
318+
319+
// Timeout specifies how long the maintenance mode should last, in seconds.
320+
// This field is optional; if nil, the server will use the default timeout (usually 3600 seconds).
321+
Timeout *int `json:"timeout"`
322+
}
323+
324+
// It contains leader statistics, shard statistics, and the count of ongoing/pending move shard operations.
325+
type RebalanceResponse struct {
326+
// Statistics related to leader distribution
327+
Leader *LeaderStats `json:"leader,omitempty"`
328+
// Statistics related to shard distribution (JSON key is "shards", not "shard")
329+
Shards *ShardStats `json:"shards,omitempty"`
330+
// Number of ongoing move shard operations
331+
PendingMoveShards *int64 `json:"pendingMoveShards,omitempty"`
332+
// Number of pending (scheduled) move shard operations
333+
TodoMoveShards *int64 `json:"todoMoveShards,omitempty"`
334+
}
335+
336+
// LeaderStats holds information about leader balancing across DB-Servers.
337+
type LeaderStats struct {
338+
// Actual leader weight used per server
339+
WeightUsed []int `json:"weightUsed,omitempty"`
340+
// Target leader weight per server
341+
TargetWeight []float64 `json:"targetWeight,omitempty"`
342+
// Number of leader shards per server
343+
NumberShards []int `json:"numberShards,omitempty"`
344+
// Number of duplicated leaders per server
345+
LeaderDupl []int `json:"leaderDupl,omitempty"`
346+
// Total leader weight
347+
TotalWeight *int `json:"totalWeight,omitempty"`
348+
// Computed imbalance percentage
349+
Imbalance *float64 `json:"imbalance,omitempty"`
350+
// Total number of leader shards
351+
TotalShards *int64 `json:"totalShards,omitempty"`
352+
}
353+
354+
// ShardStats holds information about shard balancing across DB-Servers.
355+
type ShardStats struct {
356+
// Actual size used per server
357+
SizeUsed []int64 `json:"sizeUsed,omitempty"`
358+
// Target size per server
359+
TargetSize []float64 `json:"targetSize,omitempty"`
360+
// Number of shards per server
361+
NumberShards []int `json:"numberShards,omitempty"`
362+
// Total size used across servers
363+
TotalUsed *int64 `json:"totalUsed,omitempty"`
364+
// Total number of shards
365+
TotalShards *int64 `json:"totalShards,omitempty"`
366+
// Number of shards belonging to system collections
367+
TotalShardsFromSystemCollections *int64 `json:"totalShardsFromSystemCollections,omitempty"`
368+
// Computed imbalance factor for shards
369+
Imbalance *float64 `json:"imbalance,omitempty"`
370+
}
371+
372+
// RebalanceRequestBody provides a default configuration for rebalancing requests.
373+
// RebalanceRequestBody provides the options for computing a rebalance plan.
374+
// It corresponds to the request body for POST /_admin/cluster/rebalance.
375+
type RebalanceRequestBody struct {
376+
// DatabasesExcluded is a list of database names to exclude from analysis.
377+
DatabasesExcluded []string `json:"databasesExcluded,omitempty"`
378+
// ExcludeSystemCollections indicates whether to exclude system collections.
379+
ExcludeSystemCollections *bool `json:"excludeSystemCollections,omitempty"`
380+
// LeaderChanges indicates whether leader changes are allowed.
381+
LeaderChanges *bool `json:"leaderChanges,omitempty"`
382+
// MaximumNumberOfMoves is the maximum number of shard move operations to generate.
383+
MaximumNumberOfMoves *int `json:"maximumNumberOfMoves,omitempty"`
384+
// MoveFollowers indicates whether follower shard moves are allowed.
385+
MoveFollowers *bool `json:"moveFollowers,omitempty"`
386+
// MoveLeaders indicates whether leader shard moves are allowed.
387+
MoveLeaders *bool `json:"moveLeaders,omitempty"`
388+
// PiFactor is the weighting factor used in imbalance computation.
389+
PiFactor *int `json:"piFactor,omitempty"`
390+
// Version must be set to 1.
391+
Version *int `json:"version"`
392+
}
393+
394+
// RebalancePlan contains the imbalance statistics before
395+
// and after rebalancing, along with the list of suggested move operations.
396+
type RebalancePlan struct {
397+
// ImbalanceBefore shows the imbalance metrics before applying the plan.
398+
ImbalanceBefore *ImbalanceStats `json:"imbalanceBefore,omitempty"`
399+
// ImbalanceAfter shows the imbalance metrics after applying the plan.
400+
ImbalanceAfter *ImbalanceStats `json:"imbalanceAfter,omitempty"`
401+
// Moves contains the list of suggested shard move operations.
402+
Moves []MoveOperation `json:"moves"`
403+
}
404+
405+
// ImbalanceStats holds leader and shard distribution statistics
406+
// used to measure cluster imbalance.
407+
type ImbalanceStats struct {
408+
// Leader contains statistics related to leader distribution.
409+
Leader *LeaderStats `json:"leader,omitempty"`
410+
// Shards contains statistics related to shard distribution.
411+
Shards *ShardStats `json:"shards,omitempty"`
412+
}
413+
414+
// MoveOperation describes a suggested shard move as part of the rebalance plan.
415+
type MoveOperation struct {
416+
// Collection is the collection identifier for the shard.
417+
Collection *string `json:"collection,omitempty"`
418+
// From is the source server ID.
419+
From *string `json:"from,omitempty"`
420+
// IsLeader indicates if the move involves a leader shard.
421+
IsLeader *bool `json:"isLeader,omitempty"`
422+
// Shard is the shard identifier being moved.
423+
Shard *string `json:"shard,omitempty"`
424+
// To is the destination server ID.
425+
To *string `json:"to,omitempty"`
426+
427+
// Database is the database name containing the collection.
428+
Database *string `json:"database,omitempty"`
429+
}
430+
431+
// It contains the set of shard move operations to perform and the version of the rebalance plan.
432+
type ExecuteRebalanceRequestBody struct {
433+
// Moves is a list of shard move operations that should be executed.
434+
// Each move specifies which shard to move, from which server to which server,
435+
// whether it is a leader shard, the collection, and the database.
436+
Moves []MoveOperation `json:"moves"`
437+
438+
// Version specifies the version of the rebalance plan that this request applies to.
439+
// This should match the version returned by ComputeClusterRebalance.
440+
Version *int `json:"version,omitempty"`
441+
}

0 commit comments

Comments
 (0)