Skip to content

Commit

Permalink
Merge pull request #579 from nokia/leader-del
Browse files Browse the repository at this point in the history
add REST endpoints to switch the cluster leader and rebalance the instances load
  • Loading branch information
karimra authored Jan 24, 2025
2 parents 90be036 + 6803ace commit b038c8a
Show file tree
Hide file tree
Showing 11 changed files with 445 additions and 181 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
#
# SPDX-License-Identifier: Apache-2.0

FROM golang:1.21.9 as builder
FROM golang:1.21.9 AS builder
ADD . /build
WORKDIR /build
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o gnmic .
#RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o gnmic .
RUN CGO_ENABLED=0 go build -o gnmic .

FROM alpine
LABEL org.opencontainers.image.source https://github.com/openconfig/gnmic
LABEL org.opencontainers.image.source=https://github.com/openconfig/gnmic
COPY --from=builder /build/gnmic /app/
WORKDIR /app
ENTRYPOINT [ "/app/gnmic" ]
Expand Down
146 changes: 96 additions & 50 deletions docs/user_guide/api/cluster.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
## `GET /api/v1/cluster`
# Cluster

Request gNMIc cluster state and details
## /api/v1/cluster

Returns gNMIc cluster state and details
### `GET /api/v1/cluster`

Request gNMIc cluster state and details.

=== "Request"
```bash
Expand Down Expand Up @@ -119,7 +121,94 @@ Returns gNMIc cluster state and details
}
```

## `GET /api/v1/cluster/members`
### `POST /api/v1/cluster/rebalance`

If the cluster load is not balanced it moves targets from the high load instances to the low load instances.

=== "Request"
```bash
curl --request POST gnmic-api-address:port/api/v1/cluster/rebalance
```
=== "200 OK"
```
```
=== "400 Bad Request"
```json
{
"errors": [
"not leader"
]
}
```

### `GET /api/v1/cluster/leader`

Returns the cluster leader details.

=== "Request"
```bash
curl --request POST gnmic-api-address:port/api/v1/cluster/leader
```
=== "200 OK"
```json
[
{
"name": "clab-telemetry-gnmic1",
"api-endpoint": "http://clab-telemetry-gnmic1:7890",
"is-leader": true,
"number-of-locked-nodes": 23,
"locked-targets": [
"clab-lab4-leaf8",
"clab-lab5-leaf8",
"clab-lab1-spine2",
"clab-lab3-leaf7",
"clab-lab4-leaf4",
"clab-lab2-leaf8",
"clab-lab2-spine3",
"clab-lab4-leaf1",
"clab-lab4-leaf2",
"clab-lab4-spine3",
"clab-lab5-spine2",
"clab-lab1-spine1",
"clab-lab2-leaf6",
"clab-lab5-leaf7",
"clab-lab1-leaf8",
"clab-lab3-leaf8",
"clab-lab3-spine2",
"clab-lab3-super-spine1",
"clab-lab5-spine1",
"clab-lab2-super-spine2",
"clab-lab3-leaf2",
"clab-lab2-spine2",
"clab-lab4-spine1"
]
}
]
```
=== "500 Internal Server Error"
```json
{
"errors": [
"Error Text"
]
}
```

### `DELETE /api/v1/cluster/leader`

Forces the cluster leader to free its lock to allow another instance to become the leader.

=== "Request"
```bash
curl --request DELETE gnmic-api-address:port/api/v1/cluster/leader
```
=== "200 OK"
```json
```

## /api/v1/cluster/members

### `GET /api/v1/cluster/members`

Query gNMIc cluster members

Expand Down Expand Up @@ -235,57 +324,14 @@ Returns a list of gNMIc cluster members with details
}
```

## `GET /api/v1/cluster/leader`
### `POST /api/v1/cluster/members/{id}/drain`

Queries the cluster leader deatils

Returns details of the gNMIc cluster leader.
Drains the instance `id` from its targets, moving them to the other instances in the cluster.

=== "Request"
```bash
curl --request POST gnmic-api-address:port/api/v1/cluster/leader
curl --request POST gnmic-api-address:port/api/v1/cluster/members/{id}/drain
```
=== "200 OK"
```json
[
{
"name": "clab-telemetry-gnmic1",
"api-endpoint": "http://clab-telemetry-gnmic1:7890",
"is-leader": true,
"number-of-locked-nodes": 23,
"locked-targets": [
"clab-lab4-leaf8",
"clab-lab5-leaf8",
"clab-lab1-spine2",
"clab-lab3-leaf7",
"clab-lab4-leaf4",
"clab-lab2-leaf8",
"clab-lab2-spine3",
"clab-lab4-leaf1",
"clab-lab4-leaf2",
"clab-lab4-spine3",
"clab-lab5-spine2",
"clab-lab1-spine1",
"clab-lab2-leaf6",
"clab-lab5-leaf7",
"clab-lab1-leaf8",
"clab-lab3-leaf8",
"clab-lab3-spine2",
"clab-lab3-super-spine1",
"clab-lab5-spine1",
"clab-lab2-super-spine2",
"clab-lab3-leaf2",
"clab-lab2-spine2",
"clab-lab4-spine1"
]
}
]
```
=== "500 Internal Server Error"
```json
{
"errors": [
"Error Text"
]
}
```
5 changes: 5 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ nav:
- Duration Convert: user_guide/event_processors/event_duration_convert.md
- Extract Tags: user_guide/event_processors/event_extract_tags.md
- Group by: user_guide/event_processors/event_group_by.md
- IEEE Float32: user_guide/event_processors/event_ieeefloat32.md
- JQ: user_guide/event_processors/event_jq.md
- Merge: user_guide/event_processors/event_merge.md
- Override TS: user_guide/event_processors/event_override_ts.md
- Plugin: user_guide/event_processors/event_plugin.md
- Rate Limit: user_guide/event_processors/event_rate_limit.md
- Starlark: user_guide/event_processors/event_starlark.md
- Strings: user_guide/event_processors/event_strings.md
Expand All @@ -104,6 +106,7 @@ nav:
- Configuration: user_guide/api/configuration.md
- Targets: user_guide/api/targets.md
- Cluster: user_guide/api/cluster.md
- Other: user_guide/api/other.md

- Golang Package:
- Introduction: user_guide/golang_package/intro.md
Expand Down Expand Up @@ -132,6 +135,8 @@ nav:
- Generate: 'cmd/generate.md'
- Generate Path: cmd/generate/generate_path.md
- Generate Set-Request: cmd/generate/generate_set_request.md
- Processor: cmd/processor.md
- Proxy: cmd/proxy.md

- Deployment examples:
- Deployments: deployments/deployments_intro.md
Expand Down
Loading

0 comments on commit b038c8a

Please sign in to comment.