Skip to content

Commit fd9100a

Browse files
authored
feat: function store (#178)
1 parent 5807950 commit fd9100a

16 files changed

Lines changed: 600 additions & 38 deletions

File tree

.github/workflows/bench.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
with:
4949
tinygo-version: '0.30.0'
5050
- run: docker-compose -f ./tests/docker-compose.yaml up -d
51-
- run: make build_all
51+
- run: make build-all
5252
- name: Wait for Pulsar service
5353
run: until curl http://localhost:8080/metrics > /dev/null 2>&1 ; do sleep 1; done
5454
- run: make bench

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
args: --timeout=10m
5555
skip-pkg-cache: true
5656
- run: docker-compose -f ./tests/docker-compose.yaml up -d
57-
- run: make build_all
57+
- run: make build-all
5858
- name: Wait for Pulsar service
5959
run: until curl http://localhost:8080/metrics > /dev/null 2>&1 ; do sleep 1; done
6060
- run: make test

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
build:
1515
go build -v -o bin/function-stream ./cmd
1616

17-
build_example:
17+
build-example:
1818
tinygo build -o bin/example_basic.wasm -target=wasi ./examples/basic
1919

2020
lint:
@@ -23,7 +23,7 @@ lint:
2323
lint-fix:
2424
golangci-lint run --fix
2525

26-
build_all: build build_example
26+
build-all: build build-example
2727

2828
test:
2929
go test -race ./... -timeout 10m

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ The Function Stream project is organized as follows:
9393
To compile Function Stream, use this command:
9494

9595
```shell
96-
make build_all
96+
make build-all
9797
```
9898

9999
This creates the function-stream binary program and example wasm files in the `bin` directory,

admin/client/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Class | Method | HTTP request | Description
8282
*FunctionAPI* | [**DeleteFunction**](docs/FunctionAPI.md#deletefunction) | **Delete** /api/v1/function/{name} | delete a function
8383
*FunctionAPI* | [**DeleteNamespacedFunction**](docs/FunctionAPI.md#deletenamespacedfunction) | **Delete** /api/v1/function/{namespace}/{name} | delete a namespaced function
8484
*FunctionAPI* | [**GetAllFunctions**](docs/FunctionAPI.md#getallfunctions) | **Get** /api/v1/function | get all functions
85+
*FunctionStoreAPI* | [**ReloadFunctions**](docs/FunctionStoreAPI.md#reloadfunctions) | **Get** /api/v1/function-store/reload | reload functions from the function store
8586
*HttpTubeAPI* | [**TriggerHttpTubeEndpoint**](docs/HttpTubeAPI.md#triggerhttptubeendpoint) | **Post** /api/v1/http-tube/{endpoint} | trigger the http tube endpoint
8687
*StateAPI* | [**GetState**](docs/StateAPI.md#getstate) | **Get** /api/v1/state/{key} | get a state
8788
*StateAPI* | [**SetState**](docs/StateAPI.md#setstate) | **Post** /api/v1/state/{key} | set a state

admin/client/api_function_store.go

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

admin/client/client.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apidocs.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@
105105
}
106106
}
107107
},
108+
"/api/v1/function-store/reload": {
109+
"get": {
110+
"tags": [
111+
"function-store"
112+
],
113+
"summary": "reload functions from the function store",
114+
"operationId": "reloadFunctions",
115+
"responses": {
116+
"200": {
117+
"description": "OK"
118+
}
119+
}
120+
}
121+
},
108122
"/api/v1/function/{namespace}/{name}": {
109123
"delete": {
110124
"consumes": [
@@ -407,6 +421,10 @@
407421
{
408422
"description": "Managing HTTP tubes",
409423
"name": "http-tube"
424+
},
425+
{
426+
"description": "Managing function store",
427+
"name": "function-store"
410428
}
411429
]
412430
}

cmd/client/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
del "github.com/functionstream/function-stream/cmd/client/delete"
2424
"github.com/functionstream/function-stream/cmd/client/list"
2525
"github.com/functionstream/function-stream/cmd/client/produce"
26+
"github.com/functionstream/function-stream/cmd/client/reload"
2627
"github.com/spf13/cobra"
2728
)
2829

@@ -43,4 +44,5 @@ func init() {
4344
Cmd.AddCommand(del.Cmd)
4445
Cmd.AddCommand(produce.Cmd)
4546
Cmd.AddCommand(consume.Cmd)
47+
Cmd.AddCommand(reload.Cmd)
4648
}

cmd/client/reload/cmd.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2024 Function Stream Org.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package reload
18+
19+
import (
20+
"context"
21+
"fmt"
22+
adminclient "github.com/functionstream/function-stream/admin/client"
23+
"github.com/functionstream/function-stream/cmd/client/common"
24+
"github.com/spf13/cobra"
25+
"os"
26+
)
27+
28+
var Cmd = &cobra.Command{
29+
Use: "reload",
30+
Short: "Reload Functions",
31+
Long: `Reload functions from the function store`,
32+
Args: cobra.NoArgs,
33+
Run: exec,
34+
}
35+
36+
func exec(_ *cobra.Command, _ []string) {
37+
cfg := adminclient.NewConfiguration()
38+
cfg.Servers = []adminclient.ServerConfiguration{{
39+
URL: common.Config.ServiceAddr,
40+
}}
41+
cli := adminclient.NewAPIClient(cfg)
42+
43+
res, err := cli.FunctionStoreAPI.ReloadFunctions(context.Background()).Execute()
44+
if err != nil {
45+
fmt.Printf("Failed to reload functions: %v\n", err)
46+
os.Exit(1)
47+
}
48+
if res.StatusCode != 200 {
49+
fmt.Printf("Failed to reload functions with status code: %d\n", res.StatusCode)
50+
os.Exit(1)
51+
}
52+
}

0 commit comments

Comments
 (0)