-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add collector based design (#17)
* feat: raccoon http+grpc * test: completing coding and unit tests * fix: resolved merge conflicts and changed integration tests * refactor: addressed review comments * ci: changing protoc version * ci: fixing protoc compilation in docker build * test: fixing tests * ci: fixing github build and integration tests * refactor: Removed pkg directory combined EventsBatch and CollectRequest
- Loading branch information
Showing
58 changed files
with
1,852 additions
and
386 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
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 |
---|---|---|
|
@@ -15,5 +15,6 @@ coverage | |
*.idea/ | ||
clickstream-service | ||
raccoon | ||
websocket/proto/*.pb.go | ||
pkg/proto/*.pb.go | ||
proto/*.pb.go | ||
.temp |
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ install-protoc: | |
@echo "> installing dependencies" | ||
go get -u github.com/golang/protobuf/[email protected] | ||
go get -u github.com/golang/protobuf/[email protected] | ||
go get -u google.golang.org/grpc/cmd/[email protected] | ||
|
||
update-deps: | ||
go mod tidy -v | ||
|
@@ -22,12 +23,13 @@ update-deps: | |
copy-config: | ||
cp .env.sample .env | ||
|
||
PROTO_PACKAGE=/websocket/proto | ||
PROTO_PACKAGE=/proto | ||
generate-proto: | ||
rm -rf .temp | ||
mkdir -p .temp | ||
curl -o .temp/proton.tar.gz -L http://api.github.com/repos/odpf/proton/tarball/main; tar xvf .temp/proton.tar.gz -C .temp/ --strip-components 1 | ||
protoc --proto_path=.temp/ .temp/odpf/raccoon/*.proto --go_out=./ --go_opt=paths=import --go_opt=Modpf/raccoon/Event.proto=$(PROTO_PACKAGE) --go_opt=Modpf/raccoon/EventRequest.proto=$(PROTO_PACKAGE) --go_opt=Modpf/raccoon/EventResponse.proto=$(PROTO_PACKAGE) | ||
protoc --proto_path=.temp/ .temp/odpf/raccoon/Event.proto .temp/odpf/raccoon/EventRequest.proto .temp/odpf/raccoon/EventResponse.proto --go_out=./ --go_opt=paths=import --go_opt=Modpf/raccoon/Event.proto=$(PROTO_PACKAGE) --go_opt=Modpf/raccoon/EventRequest.proto=$(PROTO_PACKAGE) --go_opt=Modpf/raccoon/EventResponse.proto=$(PROTO_PACKAGE) | ||
protoc --proto_path=.temp/ .temp/odpf/raccoon/*.proto --go-grpc_opt=paths=import --go-grpc_opt=Modpf/raccoon/Event.proto=$(PROTO_PACKAGE) --go-grpc_opt=Modpf/raccoon/EventRequest.proto=$(PROTO_PACKAGE) --go-grpc_opt=Modpf/raccoon/EventResponse.proto=$(PROTO_PACKAGE) --go-grpc_opt=Modpf/raccoon/EventService.proto=$(PROTO_PACKAGE) --go-grpc_out=./ | ||
|
||
# Build Lifecycle | ||
compile: | ||
|
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,20 @@ | ||
package collection | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"raccoon/identification" | ||
pb "raccoon/proto" | ||
) | ||
|
||
type CollectRequest struct { | ||
ConnectionIdentifier *identification.Identifier | ||
TimeConsumed time.Time | ||
TimePushed time.Time | ||
*pb.EventRequest | ||
} | ||
|
||
type Collector interface { | ||
Collect(ctx context.Context, req *CollectRequest) error | ||
} |
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,16 @@ | ||
package collection | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type MockCollector struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *MockCollector) Collect(ctx context.Context, req *CollectRequest) error { | ||
args := m.Called(ctx, req) | ||
return args.Error(0) | ||
} |
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,20 @@ | ||
package collection | ||
|
||
import ( | ||
"context" | ||
"time" | ||
) | ||
|
||
type CollectFunction func(ctx context.Context, req *CollectRequest) error | ||
|
||
func (c CollectFunction) Collect(ctx context.Context, req *CollectRequest) error { | ||
return c(ctx, req) | ||
} | ||
|
||
func NewChannelCollector(c chan *CollectRequest) Collector { | ||
return CollectFunction(func(ctx context.Context, req *CollectRequest) error { | ||
req.TimePushed = time.Now() | ||
c <- req | ||
return nil | ||
}) | ||
} |
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,36 @@ | ||
package collection | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestNewChannelCollector(t *testing.T) { | ||
type args struct { | ||
c chan *CollectRequest | ||
} | ||
c := make(chan *CollectRequest) | ||
tests := []struct { | ||
name string | ||
args args | ||
want Collector | ||
}{ | ||
{ | ||
name: "Creating collector", | ||
args: args{ | ||
c: c, | ||
}, | ||
want: CollectFunction(func(ctx context.Context, req *CollectRequest) error { | ||
return nil | ||
}), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := NewChannelCollector(tt.args.c); reflect.TypeOf(got) != reflect.TypeOf(tt.want) { | ||
t.Errorf("NewChannelCollector() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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,11 @@ | ||
package deserialization | ||
|
||
type Deserializer interface { | ||
Deserialize(b []byte, i interface{}) error | ||
} | ||
|
||
type DeserializeFunc func(b []byte, i interface{}) error | ||
|
||
func (f DeserializeFunc) Deserialize(b []byte, i interface{}) error { | ||
return f(b, i) | ||
} |
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,9 @@ | ||
package deserialization | ||
|
||
import "encoding/json" | ||
|
||
func JSONDeserializer() Deserializer { | ||
return DeserializeFunc(func(b []byte, i interface{}) error { | ||
return json.Unmarshal(b, i) | ||
}) | ||
} |
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,27 @@ | ||
package deserialization | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestJSONDeserializer(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
want Deserializer | ||
}{ | ||
{ | ||
name: "Creating new JSON Deserializer", | ||
want: DeserializeFunc(func(b []byte, i interface{}) error { | ||
return nil | ||
}), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := JSONDeserializer(); reflect.TypeOf(got) != reflect.TypeOf(tt.want) { | ||
t.Errorf("JSONDeserializer() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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,20 @@ | ||
package deserialization | ||
|
||
import ( | ||
"errors" | ||
|
||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
var ErrInvalidProtoMessage = errors.New("invalld proto message") | ||
|
||
func ProtoDeserilizer() Deserializer { | ||
return DeserializeFunc(func(b []byte, i interface{}) error { | ||
msg, ok := i.(proto.Message) | ||
if !ok { | ||
return ErrInvalidProtoMessage | ||
} | ||
return proto.Unmarshal(b, msg) | ||
}) | ||
|
||
} |
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,27 @@ | ||
package deserialization | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestProtoDeserilizer(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
want Deserializer | ||
}{ | ||
{ | ||
name: "Create new proto Deserializer", | ||
want: DeserializeFunc(func(b []byte, i interface{}) error { | ||
return nil | ||
}), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := ProtoDeserilizer(); reflect.TypeOf(got) != reflect.TypeOf(tt.want) { | ||
t.Errorf("ProtoDeserilizer() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -50,5 +50,6 @@ services: | |
- kafka | ||
ports: | ||
- "8080:8080" | ||
- "8081:8081" | ||
networks: | ||
- cs-network |
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.