Skip to content

Commit 0e636da

Browse files
committed
Adds LoadAvg info in /status
1 parent 97c522c commit 0e636da

6 files changed

Lines changed: 86 additions & 13 deletions

File tree

docs/api.md

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,68 @@ An example response for a successful **asynchronous** request:
156156
> | `503` | `text/plain` | | Prewarming failed |
157157
158158
------------------------------------------------------------------------------------------
159+
### Status information
159160

160-
<!--
161-
status API
162-
function API
163-
-->
161+
<code>GET</code> <code><b>/status</b></code> (get current status of the node)
162+
163+
##### Parameters
164+
165+
None
166+
167+
##### Responses
168+
169+
> | http code | content-type | response | comments |
170+
> |---------------|-----------------------------------|---------------------------------|-----------------------------------|
171+
> | `200` | `application/json` | *See response example.* | |
172+
> | `500` | `text/plain` | `Could not retrieve results` |
173+
174+
An example response for a successful request:
175+
176+
```
177+
{
178+
"Url": "http://192.168.1.23:1323",
179+
"AvailableWarmContainers": {
180+
"isprime": 1,
181+
"sleepSec": 2
182+
},
183+
"AvailableMemMB": 3072,
184+
"AvailableCPUs": 8,
185+
"Coordinates": {
186+
"Vec": [
187+
0,
188+
0,
189+
0
190+
],
191+
"Error": 1.5,
192+
"Height": 0.00001
193+
},
194+
"LoadAvg": [
195+
1.34,
196+
1.43,
197+
0.94
198+
]
199+
}
200+
```
201+
202+
`AvailableMemMB` and `AvailableCPUs` indicate the currently amount of memory
203+
and CPUs (intended as vCPUs or fractions of them) that can be allocated to new
204+
requests in the node. `Coordinates.Vec` reports the coordinates of this node
205+
in the virtual coordinate space computed by Vivaldi algorithm.
206+
207+
### Listing functions
208+
209+
<code>GET</code> <code><b>/functions</b></code> (get list of registered functions)
210+
211+
##### Parameters
212+
213+
None
214+
215+
##### Responses
216+
217+
> | http code | content-type | response | comments |
218+
> |---------------|-----------------------------------|---------------------------------|-----------------------------------|
219+
> | `200` | `application/json` | *List of names of existing functions.* | |
220+
> | `500` | `text/plain` | `Could not retrieve results` |
221+
222+
Note that functions are globally registered in the system. Therefore, the same
223+
list is returned by every node in the same cluster.

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ require (
1010
github.com/hexablock/vivaldi v0.0.0-20180727225019-07adad3f2b5f
1111
github.com/labstack/echo/v4 v4.6.1
1212
github.com/lithammer/shortuuid v3.0.0+incompatible
13+
github.com/mikoim/go-loadavg v0.0.0-20150917074714-35ece5f6d547
1314
github.com/prometheus/client_golang v1.13.0
1415
github.com/spf13/cobra v1.0.0
1516
github.com/spf13/viper v1.4.0
1617
go.etcd.io/etcd/client/v3 v3.5.1
1718
go.opentelemetry.io/otel v1.28.0
1819
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.28.0
1920
go.opentelemetry.io/otel/sdk v1.28.0
21+
go.opentelemetry.io/otel/trace v1.28.0
2022
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
2123
)
2224

@@ -65,7 +67,6 @@ require (
6567
go.etcd.io/etcd/api/v3 v3.5.1 // indirect
6668
go.etcd.io/etcd/client/pkg/v3 v3.5.1 // indirect
6769
go.opentelemetry.io/otel/metric v1.28.0 // indirect
68-
go.opentelemetry.io/otel/trace v1.28.0 // indirect
6970
go.uber.org/atomic v1.7.0 // indirect
7071
go.uber.org/multierr v1.6.0 // indirect
7172
go.uber.org/zap v1.17.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
480480
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
481481
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
482482
github.com/miekg/pkcs11 v1.0.3/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs=
483+
github.com/mikoim/go-loadavg v0.0.0-20150917074714-35ece5f6d547 h1:sKOBS3TQA6gIeu7xDDIJnH1cPmGAa3535gg2/cWrwC4=
484+
github.com/mikoim/go-loadavg v0.0.0-20150917074714-35ece5f6d547/go.mod h1:Gv1gEAo58s56eUbsb59IAFnEr6flyFg9lgryVQnKwhM=
483485
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible/go.mod h1:8AuVvqP/mXw1px98n46wfvcGfQ4ci2FwoAjKYxuo3Z4=
484486
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
485487
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=

internal/api/api.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import (
2121
"github.com/serverledge-faas/serverledge/utils"
2222
"go.opentelemetry.io/otel/attribute"
2323

24-
"github.com/serverledge-faas/serverledge/internal/scheduling"
2524
"github.com/labstack/echo/v4"
25+
"github.com/mikoim/go-loadavg"
26+
"github.com/serverledge-faas/serverledge/internal/scheduling"
2627
)
2728

2829
var requestsPool = sync.Pool{
@@ -204,14 +205,23 @@ func DecodeServiceClass(serviceClass string) (p function.ServiceClass) {
204205
func GetServerStatus(c echo.Context) error {
205206
node.Resources.RLock()
206207
defer node.Resources.RUnlock()
208+
207209
portNumber := config.GetInt("api.port", 1323)
208210
url := fmt.Sprintf("http://%s:%d", utils.GetIpAddress().String(), portNumber)
211+
212+
loadAvg, err := loadavg.Parse()
213+
loadAvgValues := []float64{-1.0, -1.0, -1.0}
214+
if err == nil {
215+
loadAvgValues = []float64{loadAvg.LoadAverage1, loadAvg.LoadAverage5, loadAvg.LoadAverage10}
216+
}
217+
209218
response := registration.StatusInformation{
210-
Url: url,
211-
AvailableMemMB: node.Resources.AvailableMemMB,
212-
AvailableCPUs: node.Resources.AvailableCPUs,
213-
DropCount: node.Resources.DropCount,
214-
Coordinates: *registration.Reg.Client.GetCoordinate(),
219+
Url: url,
220+
AvailableWarmContainers: node.WarmStatus(),
221+
AvailableMemMB: node.Resources.AvailableMemMB,
222+
AvailableCPUs: node.Resources.AvailableCPUs,
223+
Coordinates: *registration.Reg.Client.GetCoordinate(),
224+
LoadAvg: loadAvgValues,
215225
}
216226

217227
return c.JSON(http.StatusOK, response)

internal/registration/edgeNetUDPDiscovery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func handleUDPConnection(conn *net.UDPConn) {
6666
}
6767
}
6868

69+
// TODO: this function should reuse the code in api.go for the /status API
6970
func getCurrentStatusInformation() (status []byte, err error) {
7071
portNumber := config.GetInt("api.port", 1323)
7172
url := fmt.Sprintf("http://%s:%d", utils.GetIpAddress().String(), portNumber)
@@ -74,7 +75,6 @@ func getCurrentStatusInformation() (status []byte, err error) {
7475
AvailableWarmContainers: node.WarmStatus(),
7576
AvailableMemMB: node.Resources.AvailableMemMB,
7677
AvailableCPUs: node.Resources.AvailableCPUs,
77-
DropCount: node.Resources.DropCount,
7878
Coordinates: *Reg.Client.GetCoordinate(),
7979
}
8080

internal/registration/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ type StatusInformation struct {
2626
AvailableWarmContainers map[string]int // <k, v> = <function name, warm container number>
2727
AvailableMemMB int64
2828
AvailableCPUs float64
29-
DropCount int64
3029
Coordinates vivaldi.Coordinate
30+
LoadAvg []float64
3131
}

0 commit comments

Comments
 (0)