-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
870 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
{ | ||
"name": "Go", | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
"dockerfile": "Dockerfile" | ||
}, | ||
"extensions": [ | ||
"golang.go", | ||
"hashicorp.terraform", | ||
"zxh404.vscode-proto3" | ||
], | ||
"remoteUser": "vscode", | ||
"mounts": [ | ||
"source=${localEnv:HOME}/.aws/,target=/home/vscode/.aws/,type=bind,consistency=cached" | ||
] | ||
"postCreateCommand": "bash .devcontainer/install-dev-tools.sh" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# compile proto | ||
sh build/scripts/proto/compile.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,4 +136,4 @@ issues: | |
- goconst | ||
- gosec | ||
- noctx | ||
- wrapcheck | ||
- wrapcheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
protoc --go_out=. --go_opt=paths=source_relative \ | ||
--go-grpc_out=. --go-grpc_opt=paths=source_relative \ | ||
proto/*/*.proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# service | ||
|
||
This example is a toy implementation of Substation's gRPC service and shows how it can be used for inter-process communication (IPC) to send processed data from the sink back to the source. Refer to the [gRPC quickstart guide](https://grpc.io/docs/languages/go/quickstart/#regenerate-grpc-code) for compiling the protobuf. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
local sinklib = import '../../build/config/sink.libsonnet'; | ||
|
||
{ | ||
sink: sinklib.grpc(server='localhost:50051'), | ||
transform: { | ||
type: 'transfer' | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"sync" | ||
|
||
"github.com/brexhq/substation/cmd" | ||
"github.com/brexhq/substation/config" | ||
"github.com/brexhq/substation/internal/service" | ||
|
||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
func main() { | ||
sub := cmd.New() | ||
|
||
bytes, err := os.ReadFile("./config.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
if err := json.Unmarshal(bytes, &sub.Config); err != nil { | ||
panic(err) | ||
} | ||
|
||
// maintains app state | ||
group, ctx := errgroup.WithContext(context.TODO()) | ||
|
||
// create the gRPC server | ||
server := service.Server{} | ||
server.Setup() | ||
|
||
// deferring guarantees that the gRPC server will shutdown | ||
defer server.Stop() | ||
|
||
// create the server API for the Sink service and register it with the server | ||
srv := &service.Sink{} | ||
server.RegisterSink(srv) | ||
|
||
// gRPC server runs in a goroutine to prevent blocking main | ||
group.Go(func() error { | ||
return server.Start("localhost:50051") | ||
}) | ||
|
||
// sink goroutine | ||
var sinkWg sync.WaitGroup | ||
sinkWg.Add(1) | ||
group.Go(func() error { | ||
return sub.Sink(ctx, &sinkWg) | ||
}) | ||
|
||
// transform goroutine | ||
var transformWg sync.WaitGroup | ||
transformWg.Add(1) | ||
group.Go(func() error { | ||
return sub.Transform(ctx, &transformWg) | ||
}) | ||
|
||
// ingest goroutine | ||
group.Go(func() error { | ||
data := [][]byte{ | ||
[]byte(`{"foo":"bar"}`), | ||
[]byte(`{"baz":"qux"}`), | ||
[]byte(`{"quux":"corge"}`), | ||
} | ||
|
||
cap := config.NewCapsule() | ||
|
||
fmt.Println("sending capsules into Substation ...") | ||
for _, d := range data { | ||
fmt.Println(string(d)) | ||
cap.SetData(d) | ||
sub.Send(cap) | ||
} | ||
|
||
sub.WaitTransform(&transformWg) | ||
sub.WaitSink(&sinkWg) | ||
|
||
return nil | ||
}) | ||
|
||
// block until all Substation processing is complete | ||
if err := sub.Block(ctx, group); err != nil { | ||
panic(err) | ||
} | ||
|
||
// block until the gRPC server has received all capsules and the stream is closed | ||
srv.Block() | ||
|
||
fmt.Println("returning capsules sent from gRPC sink ...") | ||
for _, cap := range srv.Capsules { | ||
fmt.Println(string(cap.Data())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.