diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..32ac9b9 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,18 @@ +all: run-kafka-server run-grpc-server + +run-kafka-server: + docker-compose -f ./resources/docker-compose.yaml up -d + docker exec broker kafka-topics --bootstrap-server broker:9092 --create --topic dblogs + +run-grpc-server: + go run server/grpc_server.go + +send-log-to-endpoint: + curl --header "Content-Type: application/json" --request POST --data '{"DataDomainID":"5", "Database":"accuknox","Operation":"select", "OperationDetails":"none", "Timestamp":"2022-06-17T09:35:38Z","User":"ada_demo_user"}' http://127.0.0.1:8080/log + +demo: + go run main.go + +clean: + docker-compose -f ./resources/docker-compose.yaml down + diff --git a/test/docker-compose.yaml b/test/docker-compose.yaml new file mode 100644 index 0000000..33a45a4 --- /dev/null +++ b/test/docker-compose.yaml @@ -0,0 +1,27 @@ +--- +version: '3' +services: + zookeeper: + image: confluentinc/cp-zookeeper:7.0.1 + container_name: zookeeper + environment: + ZOOKEEPER_CLIENT_PORT: 2181 + ZOOKEEPER_TICK_TIME: 2000 + + broker: + image: confluentinc/cp-kafka:7.0.1 + container_name: broker + ports: + # To learn about configuring Kafka for access across networks see + # https://www.confluent.io/blog/kafka-client-cannot-connect-to-broker-on-aws-on-docker-etc/ + - "9092:9092" + depends_on: + - zookeeper + environment: + KAFKA_BROKER_ID: 1 + KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181' + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT + KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092,PLAINTEXT_INTERNAL://broker:29092 + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 + KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 + KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 diff --git a/test/main.go b/test/main.go new file mode 100644 index 0000000..c6be9cb --- /dev/null +++ b/test/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "github.com/datasage-io/datasage/src/integrations" +) + +func main() { + integrations.RunServer() +} diff --git a/test/server/grpc_server.go b/test/server/grpc_server.go new file mode 100644 index 0000000..b7b55f0 --- /dev/null +++ b/test/server/grpc_server.go @@ -0,0 +1,37 @@ +package main + +import ( + "context" + "fmt" + "log" + "net" + + config "github.com/datasage-io/datasage/src/integrations/grpc_config" + "google.golang.org/grpc" +) + +type server struct { + config.UnimplementedDataSageServerServer +} + +func (s *server) LogSend(ctx context.Context, in *config.Log) (*config.Null, error) { + log.Printf("GRPC: Receive message body from client: %s", in.Body) + return &config.Null{}, nil +} + +func RunGRPCServer() { + listen, err := net.Listen("tcp", ":2222") + if err != nil { + log.Fatalf("failed to listen: %v", err) + } + grpcServer := grpc.NewServer() + fmt.Println("gRPC Server listening on :2222") + config.RegisterDataSageServerServer(grpcServer, &server{}) + if err := grpcServer.Serve(listen); err != nil { + log.Fatalf("failed to serve: %s", err) + } +} + +func main() { + RunGRPCServer() +} diff --git a/test/src/conf/datasage.yaml b/test/src/conf/datasage.yaml new file mode 100644 index 0000000..3d55d31 --- /dev/null +++ b/test/src/conf/datasage.yaml @@ -0,0 +1,40 @@ +application: + name: Datasage + +logging: + level: INFO + +server: + port: 1989 + database: sqlite + +database: + external: + name: datasage + host: localhost + user: datasage + pass: datasage + port: 1234 + +adaptors: + name: mysql + version: 5.7 + env: k8s + is_operator: yes + percona: yes + host: 122.122.122.1 + username: root + password: abcdef + +integrations: + kafka: + - topic: dblogs + broker: 127.0.0.1 + port: 9092 + rpc: + - host: 127.0.0.1 + port: 2222 + http: + - endpoint: https://accuknox.com/service/log + method: post +