added level based logging using uber/zap

This commit is contained in:
aishwarya-raimule
2023-01-09 19:34:48 +05:30
parent 1ad5c94ee2
commit 755b85ef15
8 changed files with 164 additions and 398 deletions

View File

@@ -2,9 +2,10 @@ package schema
import (
"com.navi.medici.janus/config"
"com.navi.medici.janus/utils"
"fmt"
"github.com/riferrei/srclient"
"log"
"go.uber.org/zap"
"strings"
)
@@ -12,9 +13,11 @@ var (
SchemaRegistryEndpoint string
TopicList []string
SchemaVersionMap = make(map[string]int)
logger *zap.Logger
)
func InitializeSchemaHandler(configuration config.Configurations) {
logger = utils.GetLogger()
SchemaRegistryEndpoint = configuration.SchemaRegistry.Endpoint
TopicList = strings.Split(configuration.SchemaRegistry.Topics, ",")
// initialize schema version map which contains latest schema version for topic(s)
@@ -28,14 +31,13 @@ func GetSchemaVersions() {
for _, topic := range TopicList {
schema, err := schemaRegistryClient.GetLatestSchema(topic, false)
if err != nil {
log.Println(err)
logger.Error("error in fetching latest schema", zap.Error(err))
} else {
schemaId := schema.ID()
SchemaVersionMap[topic] = schemaId
}
}
log.Println(SchemaVersionMap)
logger.Debug("Schema Version Map", zap.String("", fmt.Sprintf("%v", SchemaVersionMap)))
}
func AddSchema(topic string, schemaType string, schema string) error {
@@ -43,8 +45,7 @@ func AddSchema(topic string, schemaType string, schema string) error {
schemaRegistryClient := srclient.CreateSchemaRegistryClient(SchemaRegistryEndpoint)
schemaRegistryClient.CodecCreationEnabled(false)
existingSchema, _ := schemaRegistryClient.GetLatestSchema(topic, false)
fmt.Println("EXISTINGSCHEMA: ")
fmt.Println(existingSchema)
logger.Debug("EXISTINGSCHEMA", zap.String("", fmt.Sprintf("%v", existingSchema)))
if existingSchema != nil {
compatible, errorCompatible := schemaRegistryClient.IsSchemaCompatible(topic, schema, "latest", srclient.SchemaType(schemaType), false)
@@ -56,8 +57,6 @@ func AddSchema(topic string, schemaType string, schema string) error {
}
_, errroCreate := schemaRegistryClient.CreateSchema(topic, schema, srclient.SchemaType(schemaType), false)
// fmt.Println("SCHEMA_ID: ")
// fmt.Println(schemaObj.ID())
if errroCreate != nil {
return errroCreate