Skip to content

Commit d27abcf

Browse files
committed
Adds LoadAvg info in /status
1 parent b1eb11c commit d27abcf

6 files changed

Lines changed: 85 additions & 12 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/hexablock/vivaldi v0.0.0-20180727225019-07adad3f2b5f
1212
github.com/labstack/echo/v4 v4.6.1
1313
github.com/lithammer/shortuuid v3.0.0+incompatible
14+
github.com/mikoim/go-loadavg v0.0.0-20150917074714-35ece5f6d547
1415
github.com/prometheus/client_golang v1.13.0
1516
github.com/spf13/cobra v1.0.0
1617
github.com/spf13/viper v1.4.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
481481
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
482482
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
483483
github.com/miekg/pkcs11 v1.0.3/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs=
484+
github.com/mikoim/go-loadavg v0.0.0-20150917074714-35ece5f6d547 h1:sKOBS3TQA6gIeu7xDDIJnH1cPmGAa3535gg2/cWrwC4=
485+
github.com/mikoim/go-loadavg v0.0.0-20150917074714-35ece5f6d547/go.mod h1:Gv1gEAo58s56eUbsb59IAFnEr6flyFg9lgryVQnKwhM=
484486
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible/go.mod h1:8AuVvqP/mXw1px98n46wfvcGfQ4ci2FwoAjKYxuo3Z4=
485487
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
486488
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{
@@ -209,14 +210,23 @@ func DecodeServiceClass(serviceClass string) (p function.ServiceClass) {
209210
func GetServerStatus(c echo.Context) error {
210211
node.Resources.RLock()
211212
defer node.Resources.RUnlock()
213+
212214
portNumber := config.GetInt("api.port", 1323)
213215
url := fmt.Sprintf("http://%s:%d", utils.GetIpAddress().String(), portNumber)
216+
217+
loadAvg, err := loadavg.Parse()
218+
loadAvgValues := []float64{-1.0, -1.0, -1.0}
219+
if err == nil {
220+
loadAvgValues = []float64{loadAvg.LoadAverage1, loadAvg.LoadAverage5, loadAvg.LoadAverage10}
221+
}
222+
214223
response := registration.StatusInformation{
215-
Url: url,
216-
AvailableMemMB: node.Resources.AvailableMemMB,
217-
AvailableCPUs: node.Resources.AvailableCPUs,
218-
DropCount: node.Resources.DropCount,
219-
Coordinates: *registration.Reg.Client.GetCoordinate(),
224+
Url: url,
225+
AvailableWarmContainers: node.WarmStatus(),
226+
AvailableMemMB: node.Resources.AvailableMemMB,
227+
AvailableCPUs: node.Resources.AvailableCPUs,
228+
Coordinates: *registration.Reg.Client.GetCoordinate(),
229+
LoadAvg: loadAvgValues,
220230
}
221231

222232
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)