Skip to content

Commit

Permalink
[patch] Merge pull request #1 from feature/add-lua-scripting-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
rinx authored Apr 2, 2021
2 parents dfa29b8 + c653347 commit 85a0927
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 47 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ $ # after Servers become ready, deploy Agents
$ kubectl apply -f k8s/agent.yaml
```

Egress filter feature
---

alvd has an egress filter feature that is extensible by using Lua scripts.

To enable it, run alvd server by passing a path to the Lua scripts.

$ ./alvd server --egress-filter-lua-filepath=examples/egress-filter/sort.lua

There're various types of examples of filters are available in [examples/egress-filter](examples/egress-filter) directory.
Current Status
---
Expand Down Expand Up @@ -139,7 +151,7 @@ Just running
License
---
alvd is distributed under Apache 2.0 license, same as Vald.
Same as Vald, alvd is distributed under Apache 2.0 license. (Partially distributed under Mozilla Public License 2.0)
alvd depends on Vald codebase, the files came from Vald (such as `internal`, `pkg/vald`. They are downloaded when running `make` command.) are excluded from my license and ownership.
Expand Down
6 changes: 6 additions & 0 deletions examples/egress-filter/dump.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- dump.lua is useful for debugging.
-- `results` is a slice of search results.

for i, r in results() do
print(string.format("Id: %s, Distance: %3.7f", r.Id, r.Distance))
end
14 changes: 14 additions & 0 deletions examples/egress-filter/jsonize.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- `results` is a slice of search results.

-- using vadv/gopher-lua-libs
local json = require("json")
local time = require("time")

for i, r in results() do
results[i].Id = json.encode(
{
id = r.Id,
time = time.format(time.unix(), "Jan 2 15:04:05 2006", "Asia/Tokyo")
}
)
end
15 changes: 15 additions & 0 deletions examples/egress-filter/reduce.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- `results` is a slice of search results.

local remains = {}
for i, r in results() do
-- remove elements by distances
if r.Distance < 10.9 then
remains[#remains+1] = r
end

results[i] = nil
end

for i, r in pairs(remains) do
results[i] = r
end
5 changes: 5 additions & 0 deletions examples/egress-filter/reverse-id.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- `results` is a slice of search results.

for i, r in results() do
results[i].Id = string.reverse(r.Id)
end
18 changes: 18 additions & 0 deletions examples/egress-filter/sort.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- `results` is a slice of search results.
-- to apply `table.sort`, put the data into `sorter`

local sorter = {}
for i, r in results() do
sorter[i] = r
end

-- sort
table.sort(sorter, function(a, b)
-- reverse order
return a.Distance > b.Distance
end)

-- put the sorted data into `results`
for i, r in pairs(sorter) do
results[i] = r
end
23 changes: 13 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ replace (
)

require (
cloud.google.com/go v0.74.0
cloud.google.com/go v0.79.0
code.cloudfoundry.org/bytefmt v0.0.0-20200131002437-cf55d5288a48
contrib.go.opencensus.io/exporter/jaeger v0.2.1
contrib.go.opencensus.io/exporter/prometheus v0.2.0
contrib.go.opencensus.io/exporter/prometheus v0.3.0
contrib.go.opencensus.io/exporter/stackdriver v0.13.5
github.com/aws/aws-sdk-go v1.27.0
github.com/aws/aws-sdk-go v1.32.1
github.com/cespare/xxhash/v2 v2.1.1
github.com/fsnotify/fsnotify v1.4.9
github.com/go-redis/redis/v8 v8.6.0
github.com/go-redis/redis/v8 v8.7.1
github.com/go-sql-driver/mysql v1.5.0
github.com/gocql/gocql v0.0.0-20200131111108-92af2e088537
github.com/gocraft/dbr/v2 v2.7.1
github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a
github.com/gogo/protobuf v1.3.1
github.com/gogo/protobuf v1.3.2
github.com/gogo/status v1.1.0
github.com/google/go-cmp v0.5.4
github.com/google/go-cmp v0.5.5
github.com/gorilla/mux v1.8.0
github.com/hashicorp/go-version v1.2.1
github.com/json-iterator/go v1.1.10
Expand All @@ -68,22 +68,25 @@ require (
github.com/scylladb/gocqlx v1.5.0
github.com/tensorflow/tensorflow v0.0.0-00010101000000-000000000000
github.com/urfave/cli/v2 v2.3.0
github.com/vadv/gopher-lua-libs v0.1.2
github.com/vdaas/vald v0.0.0-00010101000000-000000000000
github.com/yuin/gopher-lua v0.0.0-20200603152657-dc2b0ca8b37e
go.opencensus.io v0.23.0
go.opentelemetry.io/otel v0.18.0
go.opentelemetry.io/otel/exporters/metric/prometheus v0.18.0
go.opentelemetry.io/otel/metric v0.18.0
go.uber.org/automaxprocs v1.4.0
go.uber.org/goleak v1.1.10
go.uber.org/zap v1.16.0
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110
golang.org/x/sys v0.0.0-20210304203840-7b4935edff86
google.golang.org/api v0.40.0
google.golang.org/grpc v1.35.0
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4
golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa
google.golang.org/api v0.42.0
google.golang.org/grpc v1.36.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.20.4
k8s.io/apimachinery v0.20.4
k8s.io/client-go v0.20.4
k8s.io/metrics v0.0.0-00010101000000-000000000000
layeh.com/gopher-luar v1.0.8
sigs.k8s.io/controller-runtime v0.0.0-00010101000000-000000000000
)
Loading

0 comments on commit 85a0927

Please sign in to comment.