Skip to content

Commit

Permalink
Merge pull request #1 from Kristoff-starling/main
Browse files Browse the repository at this point in the history
Frontend Language Update
  • Loading branch information
Romero027 authored Jun 25, 2024
2 parents bbbdc5c + 0738a0b commit bbd2721
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 83 deletions.
2 changes: 1 addition & 1 deletion config/samples/echo/echo.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

package pb;
package echo;
option go_package = "./pb";

service EchoService {
Expand Down
30 changes: 12 additions & 18 deletions config/samples/echo/fault.appnet
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
state {
state:
prob: float
}

fn init() {
prob := 0.99;
}
init():
prob = 0.99

fn req(rpc) {
match(randomf(0,1) < prob) {
true => {
send(err('fault injected'), Down);
}
false => {
send(err('fault injected'), Up);
}
};
}
req(rpc):
match randomf(0, 1) < prob:
true =>
send(rpc, Down)
false =>
send(err('fault_injected'), Up)

resp(rpc):
send(rpc, Up)

fn resp(rpc) {
send(rpc, Up);
}
46 changes: 17 additions & 29 deletions config/samples/echo/firewall.appnet
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
state
{
firewall: Map<string, string>
}
state:
acl: Map<string, string>

fn init() {
firewall.set('test', 'No');
}
init():
set(acl, 'test', 'No')

fn req(rpc) {
match (firewall.get(rpc.get('body'))) {
Some(permission) => {
match (permission) {
'Yes' => {
send(rpc, Down);
}
'No' => {
send(err('blocked by firewall'), Up);
}
_ => {
}
};
}
None => {
send(rpc, Down);
}
};
}
req(rpc):
match get(acl, get(rpc, 'body')):
Some(permission) =>
match permission:
'Yes' =>
send(rpc, Down)
'No' =>
send(err('acl'), Up)
None =>
send(rpc, Down)

resp(rpc):
send(rpc, Up)

fn resp(rpc) {
send(rpc, Up);
}
22 changes: 9 additions & 13 deletions config/samples/echo/logging.appnet
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
state
{
state:
record_req: Vec<string>
record_resp: Vec<string>
}

fn init() {
}
init():
pass

fn req(rpc) {
record_req.set(record_req.size(), rpc.get('body'));
send(rpc, Down);
}
req(rpc):
set(record_req, size(record_req), get(rpc, 'body'))
send(rpc, Down)

fn resp(rpc) {
record_resp.set(record_resp.size(), rpc.get('body'));
send(rpc, Up);
}
resp(rpc):
set(record_resp, size(record_resp), get(rpc, 'body'))
send(rpc, Up)
38 changes: 16 additions & 22 deletions config/samples/echo/metrics.appnet
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
state
{
record: Map<uint, Instant>
latency: Vec<float>
}
state:
record: Map<uint, Instant>
latency: Vec<float>

fn init() {
}
init():
pass

fn req(rpc) {
record.set(rpc_id(), current_time());
send(rpc, Down);
}
req(rpc):
set(record, rpc_id(), current_time())
send(rpc, Down)

fn resp(rpc) {
match(record.get(rpc_id())) {
Some(t) => {
lat := time_diff(current_time(), t);
latency.set(latency.size(), lat);
}
None => {
}
};
send(rpc, Up);
}
resp(rpc):
match get(record, rpc_id()):
Some(t) =>
lat = time_diff(current_time(), t)
set(latency, size(latency), lat)
None =>
pass
send(rpc, Up)

0 comments on commit bbd2721

Please sign in to comment.