Skip to content

Commit 4d5bbe3

Browse files
committed
Merge branch 'main' into workflows-merging-main
2 parents 7d1cd2b + 0e636da commit 4d5bbe3

33 files changed

Lines changed: 426 additions & 262 deletions

.github/workflows/makefile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup Go
1616
uses: actions/setup-go@v3
1717
with:
18-
go-version: "1.20.0"
18+
go-version: "1.21.0"
1919

2020
- uses: actions/checkout@v2
2121

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ bin/
33
.run/
44
__pycache__*
55
images/*/executor
6+
*.backup
7+
default.etcd

README.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,9 @@ As functions are executed within Docker containers, you need Docker to
5050
be installed on the host. Furthermore, Serverledge needs
5151
permissions to create containers.
5252

53-
If you have more than one context (docker context ls), be sure to set up the DOCKER_HOST environment variable to the correct Host context.
54-
To set correctly, use the following three commands from cli:
55-
56-
1) docker context ls
57-
2) docker context inspect <current-context>
58-
3) Take the Endpoints.docker.Host value and save it into the DOCKER_HOST environment variable. The default value is unix:///var/run/docker.sock
59-
60-
61-
62-
You also need an **etcd** server to run Serverledge. To quickly start a local
63-
server:
64-
65-
$ ./scripts/start-etcd.sh # stop it with ./scripts/stop-etcd.sh
53+
You also need an `etcd` server to run Serverledge. To quickly start a local
54+
server, just download [a recent
55+
release](https://github.com/etcd-io/etcd/releases) of `etcd` and just run `./etcd`.
6656

6757
Start a local Serverledge node:
6858

@@ -117,7 +107,7 @@ Note that we currently support output capture only for some runtimes (e.g., Pyth
117107

118108
## Distributed Deployment
119109

120-
[This repository](https://github.com/grussorusso/serverledge-deploy) provides an
110+
[This repository](https://github.com/serverledge-faas/serverledge-deploy) provides an
121111
Ansible playbook to deploy Serverledge in a distributed configuration.
122112

123113
In this case, you can instruct `serverledge-cli` to

cmd/serverledge/main.go

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ import (
1010
"os/signal"
1111
"time"
1212

13+
"github.com/serverledge-faas/serverledge/internal/node"
14+
15+
"github.com/labstack/echo/v4"
16+
"github.com/labstack/echo/v4/middleware"
1317
"github.com/serverledge-faas/serverledge/internal/api"
1418
"github.com/serverledge-faas/serverledge/internal/cache"
1519
"github.com/serverledge-faas/serverledge/internal/config"
1620
"github.com/serverledge-faas/serverledge/internal/metrics"
17-
"github.com/serverledge-faas/serverledge/internal/node"
1821
"github.com/serverledge-faas/serverledge/internal/registration"
1922
"github.com/serverledge-faas/serverledge/internal/scheduling"
23+
"github.com/serverledge-faas/serverledge/internal/telemetry"
2024
"github.com/serverledge-faas/serverledge/utils"
21-
22-
"github.com/labstack/echo/v4"
23-
"github.com/labstack/echo/v4/middleware"
2425
)
2526

2627
func startAPIServer(e *echo.Echo) {
@@ -133,6 +134,25 @@ func main() {
133134

134135
go metrics.Init()
135136

137+
if config.GetBool(config.TRACING_ENABLED, false) {
138+
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
139+
defer stop()
140+
141+
tracesOutfile := config.GetString(config.TRACING_OUTFILE, "")
142+
if len(tracesOutfile) < 1 {
143+
tracesOutfile = fmt.Sprintf("traces-%s.json", time.Now().Format("20060102-150405"))
144+
}
145+
log.Printf("Enabling tracing to %s\n", tracesOutfile)
146+
otelShutdown, err := telemetry.SetupOTelSDK(ctx, tracesOutfile)
147+
if err != nil {
148+
log.Fatal(err)
149+
}
150+
// Handle shutdown properly so nothing leaks.
151+
defer func() {
152+
err = errors.Join(err, otelShutdown(context.Background()))
153+
}()
154+
}
155+
136156
e := echo.New()
137157

138158
// Register a signal handler to cleanup things on termination
@@ -151,3 +171,17 @@ func main() {
151171
api.StartAPIServer(e)
152172

153173
}
174+
175+
func createSchedulingPolicy() scheduling.Policy {
176+
policyConf := config.GetString(config.SCHEDULING_POLICY, "default")
177+
log.Printf("Configured policy: %s\n", policyConf)
178+
if policyConf == "cloudonly" {
179+
return &scheduling.CloudOnlyPolicy{}
180+
} else if policyConf == "edgecloud" {
181+
return &scheduling.CloudEdgePolicy{}
182+
} else if policyConf == "edgeonly" {
183+
return &scheduling.EdgePolicy{}
184+
} else {
185+
return &scheduling.DefaultLocalPolicy{}
186+
}
187+
}

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.

docs/tracing.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Serverledge relies on [OpenTelemetry](https://opentelemetry.io) for optional
2+
request tracing, aimed at performance investigations.
3+
4+
## Enabling tracing
5+
6+
Tracing is disabled by default. It can enabled with the following configuration
7+
line:
8+
9+
tracing.enabled: true
10+
11+
By default, JSON-encoded traces are written to `./traces-<timestamp>.json`.
12+
The following line sets a custom output file:
13+
14+
tracing.outfile: /path/to/file.json
15+

go.mod

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/serverledge-faas/serverledge
22

3-
go 1.20
3+
go 1.21
4+
5+
toolchain go1.22.5
46

57
require (
68
github.com/LK4D4/trylock v0.0.0-20191027065348-ff7e133a5c54
@@ -11,10 +13,14 @@ require (
1113
github.com/labstack/echo/v4 v4.6.1
1214
github.com/labstack/gommon v0.3.0
1315
github.com/lithammer/shortuuid v3.0.0+incompatible
16+
github.com/mikoim/go-loadavg v0.0.0-20150917074714-35ece5f6d547
1417
github.com/prometheus/client_golang v1.14.0
15-
github.com/spf13/cobra v1.0.0
1618
github.com/spf13/viper v1.4.0
1719
go.etcd.io/etcd/client/v3 v3.5.1
20+
go.opentelemetry.io/otel v1.28.0
21+
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.28.0
22+
go.opentelemetry.io/otel/sdk v1.28.0
23+
go.opentelemetry.io/otel/trace v1.28.0
1824
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
1925
golang.org/x/net v0.15.0
2026
google.golang.org/grpc v1.57.0
@@ -30,12 +36,14 @@ require (
3036
github.com/docker/go-connections v0.4.0 // indirect
3137
github.com/docker/go-units v0.5.0 // indirect
3238
github.com/fsnotify/fsnotify v1.6.0 // indirect
39+
github.com/go-logr/logr v1.4.2 // indirect
40+
github.com/go-logr/stdr v1.2.2 // indirect
3341
github.com/gogo/protobuf v1.3.2 // indirect
3442
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
3543
github.com/golang/protobuf v1.5.3 // indirect
36-
github.com/google/uuid v1.3.0 // indirect
44+
github.com/google/uuid v1.6.0 // indirect
3745
github.com/hashicorp/hcl v1.0.0 // indirect
38-
github.com/inconshreveable/mousetrap v1.0.0 // indirect
46+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3947
github.com/kr/pretty v0.3.0 // indirect
4048
github.com/magiconair/properties v1.8.7 // indirect
4149
github.com/mattn/go-colorable v0.1.8 // indirect
@@ -54,19 +62,20 @@ require (
5462
github.com/rogpeppe/go-internal v1.8.1 // indirect
5563
github.com/spf13/afero v1.2.2 // indirect
5664
github.com/spf13/cast v1.3.0 // indirect
65+
github.com/spf13/cobra v1.9.1 // indirect
5766
github.com/spf13/jwalterweatherman v1.0.0 // indirect
58-
github.com/spf13/pflag v1.0.5 // indirect
59-
github.com/stretchr/testify v1.8.4 // indirect
67+
github.com/spf13/pflag v1.0.6 // indirect
6068
github.com/valyala/bytebufferpool v1.0.0 // indirect
6169
github.com/valyala/fasttemplate v1.2.1 // indirect
6270
go.etcd.io/etcd/api/v3 v3.5.1 // indirect
6371
go.etcd.io/etcd/client/pkg/v3 v3.5.1 // indirect
72+
go.opentelemetry.io/otel/metric v1.28.0 // indirect
6473
go.uber.org/atomic v1.7.0 // indirect
6574
go.uber.org/multierr v1.6.0 // indirect
6675
go.uber.org/zap v1.17.0 // indirect
6776
golang.org/x/crypto v0.13.0 // indirect
6877
golang.org/x/mod v0.12.0 // indirect
69-
golang.org/x/sys v0.12.0 // indirect
78+
golang.org/x/sys v0.21.0 // indirect
7079
golang.org/x/text v0.13.0 // indirect
7180
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
7281
golang.org/x/tools v0.13.0 // indirect

0 commit comments

Comments
 (0)