Skip to content

Commit

Permalink
feat: num conds
Browse files Browse the repository at this point in the history
  • Loading branch information
akurilov committed Aug 13, 2023
1 parent 127c9f5 commit f2a6756
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 60 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ TODO

Build a helm package:
```shell
for i in core conditions-text evaluator matches messages queue-nats reader resolver subscriptions-proxy semaphore-nats writer; do git clone git@github.com:awakari/$i.git; done
for i in core conditions-number conditions-text evaluator matches messages queue-nats reader resolver subscriptions-proxy semaphore-nats writer; do git clone git@github.com:awakari/$i.git; done
cd core
helm dependency update helm/core
helm package helm/core
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/awakari/core
go 1.20

require (
github.com/awakari/client-sdk-go v1.0.2
github.com/awakari/client-sdk-go v1.0.4
github.com/cloudevents/sdk-go/binding/format/protobuf/v2 v2.14.0
github.com/google/uuid v1.3.0
github.com/kelseyhightower/envconfig v1.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/awakari/client-sdk-go v1.0.2 h1:lrt3fuhlok+Pa+cHNenK8QUdnfnnTbFG1akeGIm3cEk=
github.com/awakari/client-sdk-go v1.0.2/go.mod h1:QMPZGt4vNYscux4MjeSQUloFY8iYhR81ztG44FuUmzI=
github.com/awakari/client-sdk-go v1.0.4 h1:8Jm1hZQMV7zmF2rKOx5z2Y9GP0zFhkBYz0ux2y4l2vY=
github.com/awakari/client-sdk-go v1.0.4/go.mod h1:QMPZGt4vNYscux4MjeSQUloFY8iYhR81ztG44FuUmzI=
github.com/cloudevents/sdk-go/binding/format/protobuf/v2 v2.14.0 h1:dEopBSOSjB5fM9r76ufM44AVj9Dnz2IOM0Xs6FVxZRM=
github.com/cloudevents/sdk-go/binding/format/protobuf/v2 v2.14.0/go.mod h1:qDSbb0fgIfFNjZrNTPtS5MOMScAGyQtn1KlSvoOdqYw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
5 changes: 5 additions & 0 deletions helm/core/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ dependencies:
condition: queue.backend.nats
alias: queue

- name: conditions-number
alias: conditionsnumber
version: 0.0.0
repository: "file://../../../conditions-number/helm/conditions-number"

- name: conditions-text
alias: conditionstext
version: 0.0.0
Expand Down
15 changes: 15 additions & 0 deletions helm/core/values-mongodb-ext.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
mongodb:
internal: false

conditionsnumber:
db:
table:
shard: false
protocol: "mongodb+srv"
# hostname: "db.cluster.mongodb.net"
# username: "user-placeholder"
password:
secret:
enabled: false
# raw: "password-placeholder"
tls:
enabled: true
insecure: true

conditionstext:
db:
table:
Expand Down
21 changes: 21 additions & 0 deletions helm/core/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ queue:
nats:
uri: "nats://core-nats:4222"

conditionsnumber:
image:
pullPolicy: "IfNotPresent"
db:
hostname: "core-mongodb:27017"
name: "conditions-number"
table:
# Database table name to use.
name: "conditions-number"
lockTtl:
create: "1000s"
username: "root"
password:
secret:
enabled: true
name: "core-mongodb"

conditionstext:
image:
pullPolicy: "IfNotPresent"
Expand Down Expand Up @@ -143,6 +160,8 @@ subscriptionsproxy:
pullPolicy: "IfNotPresent"
api:
conditions:
num:
uri: "core-conditionsnumber:50051"
text:
uri: "core-conditionstext:50051"
subscriptions:
Expand Down Expand Up @@ -200,6 +219,8 @@ resolver:
pullPolicy: "IfNotPresent"
api:
conditions:
number:
uri: "core-conditionsnumber:50051"
text:
uri: "core-conditionstext:50051"
subscriptions:
Expand Down
106 changes: 53 additions & 53 deletions test/data/subs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,101 +3,101 @@ package data
import (
"github.com/awakari/client-sdk-go/model/subscription"
"github.com/awakari/client-sdk-go/model/subscription/condition"
"time"
)

var Subs = []subscription.Data{
{
Description: "disabled",
Condition: condition.
NewBuilder().
MatchAttrKey("author").
MatchText("Edna").
AttributeKey("author").
AnyOfWords("Edna").
BuildTextCondition(),
},
{
Description: "exact complete value match for a key",
Enabled: true,
Condition: condition.
NewBuilder().
MatchAttrKey("author").
MatchText("Edna").
AttributeKey("author").
TextEquals("Edna").
BuildTextCondition(),
},
{
Description: "partial exact match",
Enabled: true,
Condition: condition.
NewBuilder().
MatchAttrKey("tags").
MatchText("neutrino").
AttributeKey("tags").
AnyOfWords("neutrino").
BuildTextCondition(),
},
{
Description: "basic group condition with \"and\" logic and partial sub-conditions",
Enabled: true,
Condition: condition.
NewBuilder().
GroupLogic(condition.GroupLogicAnd).
GroupChildren(
[]condition.Condition{
condition.
NewBuilder().
MatchAttrKey("title").
MatchText("Elon").
BuildTextCondition(),
condition.
NewBuilder().
MatchAttrKey("title").
MatchText("Musk").
BuildTextCondition(),
},
).
All([]condition.Condition{
condition.
NewBuilder().
AttributeKey("title").
AnyOfWords("Elon").
BuildTextCondition(),
condition.
NewBuilder().
AttributeKey("title").
AnyOfWords("Musk").
BuildTextCondition(),
}).
BuildGroupCondition(),
},
{
Description: "basic group condition with \"or\" logic",
Enabled: true,
Condition: condition.
NewBuilder().
GroupLogic(condition.GroupLogicOr).
GroupChildren(
[]condition.Condition{
condition.
NewBuilder().
MatchAttrKey("language").
MatchText("fi").
BuildTextCondition(),
condition.
NewBuilder().
MatchAttrKey("language").
MatchText("ru").
BuildTextCondition(),
},
).
Any([]condition.Condition{
condition.
NewBuilder().
AttributeKey("language").
AnyOfWords("fi").
BuildTextCondition(),
condition.
NewBuilder().
AttributeKey("language").
AnyOfWords("ru").
BuildTextCondition(),
}).
BuildGroupCondition(),
},
{
Description: "basic group condition with \"and\" logic and a negative sub-condition",
Enabled: true,
Condition: condition.
NewBuilder().
GroupLogic(condition.GroupLogicAnd).
GroupChildren(
[]condition.Condition{
condition.
NewBuilder().
Negation().
MatchAttrKey("type").
MatchText("com.github.awakari.tgbot").
MatchExact().
BuildTextCondition(),
condition.
NewBuilder().
MatchAttrKey("summary").
MatchText("propose").
BuildTextCondition(),
},
).
All([]condition.Condition{
condition.
NewBuilder().
Not().
AttributeKey("type").
TextEquals("com.github.awakari.tgbot").
BuildTextCondition(),
condition.
NewBuilder().
AttributeKey("summary").
AnyOfWords("propose").
BuildTextCondition(),
}).
BuildGroupCondition(),
},
{
Description: "before a certain time",
Enabled: true,
Condition: condition.
NewBuilder().
AttributeKey("time").
LessThan(float64(time.Date(2023, 05, 12, 17, 0, 0, 0, time.UTC).UnixMilli())).
BuildNumberCondition(),
},
}
9 changes: 8 additions & 1 deletion test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Test_MessageDelivery(t *testing.T) {
subIds = append(subIds, subId)
}
//
time.Sleep(100 * time.Second) // wait for the cond/sub cache entries expiration
//time.Sleep(100 * time.Second) // wait for the cond/sub cache entries expiration
//
var msgsWriter model.Writer[*pb.CloudEvent]
msgsWriter, err = client.OpenMessagesWriter(groupIdCtx, "test-user-1")
Expand Down Expand Up @@ -92,6 +92,13 @@ func Test_MessageDelivery(t *testing.T) {
data.Msgs[1],
},
},
"time is before - a numeric condition": {
subId: subIds[6],
msgs: []*pb.CloudEvent{
data.Msgs[1],
data.Msgs[3],
},
},
}
//
for k, c := range cases {
Expand Down
4 changes: 2 additions & 2 deletions test/perf_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func Test_Perf_EndToEnd(t *testing.T) {
subData := subscription.Data{
Condition: condition.
NewBuilder().
MatchText(fmt.Sprintf("yohoho term%d", i)).
AnyOfWords(fmt.Sprintf("yohoho term%d", i)).
BuildTextCondition(),
Description: fmt.Sprintf("perf-test-sub-%d", i),
Enabled: true,
Expand Down Expand Up @@ -613,7 +613,7 @@ func Test_Perf_MaxRate_WriteRead(t *testing.T) {
subData := subscription.Data{
Condition: condition.
NewBuilder().
MatchText(fmt.Sprintf("yohoho term%d", i)).
AnyOfWords(fmt.Sprintf("yohoho term%d", i)).
BuildTextCondition(),
Description: fmt.Sprintf("perf-test-sub-%d", i),
Enabled: true,
Expand Down

0 comments on commit f2a6756

Please sign in to comment.