-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'AK-8430ArulJ' of https://github.com/datasage-io/datasage …
…into AK-8430ArulJ
- Loading branch information
Showing
12 changed files
with
555 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package integrations | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type Config struct { | ||
Integrations | ||
} | ||
|
||
type Integrations struct { | ||
Rpc []GRPCLogConfig | ||
Kafka []KafkaLogConfig | ||
} | ||
|
||
type GRPCLogConfig struct { | ||
Host string | ||
Port string | ||
} | ||
|
||
type KafkaLogConfig struct { | ||
Broker string | ||
Topic string | ||
Port string | ||
} | ||
|
||
func ReadLogConfig(path string) (Config, error) { | ||
config := Config{} | ||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
log.Printf("err: %s", err) | ||
return config, err | ||
} | ||
if yaml.Unmarshal(data, &config) != nil { | ||
log.Printf("err: %s", err) | ||
return config, err | ||
} | ||
return config, 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,37 @@ | ||
package integrations | ||
|
||
//go:generate echo "Generating gRPC files" | ||
//go:generate protoc --proto_path=grpc_config grpc_config/datasage.proto --go-grpc_out=. --go_out=. | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"time" | ||
|
||
"github.com/datasage-io/datasage/src/integrations/grpc_config" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
) | ||
|
||
func StreamLogToGRPC(Log string, grpcConfigs []GRPCLogConfig) error { | ||
for _, config := range grpcConfigs { | ||
var conn *grpc.ClientConn | ||
log.Printf("[GRPC] Dialing %s:%s \n", config.Host, config.Port) | ||
conn, err := grpc.Dial(config.Host+":"+config.Port, | ||
grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
log.Fatalf("did not connect: %s", err) | ||
return err | ||
} | ||
defer conn.Close() | ||
c := grpc_config.NewDataSageServerClient(conn) | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) | ||
defer cancel() | ||
if _, err = c.LogSend(ctx, &grpc_config.Log{Body: Log}); err != nil { | ||
log.Printf("could not send the data: %v", err) | ||
return err | ||
} | ||
log.Printf("[GRPC] Log send to %s:%s\n", config.Host, config.Port) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.