Skip to content

Commit

Permalink
chore: update trace id
Browse files Browse the repository at this point in the history
Signed-off-by: surajgour-d11 <[email protected]>
  • Loading branch information
surajgour-d11 committed Dec 10, 2024
1 parent 8ad4b94 commit 2812544
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 104 deletions.
6 changes: 3 additions & 3 deletions cmd/create/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func init() {

func execute(cmd *cobra.Command) {
ctx := cmd.Context()
traceId := util.GenerateTraceId()
traceID := util.GenerateTraceID()
// Validate accounts parameter
if err := validateAccounts(accounts); err != nil {
log.Fatal("Invalid accounts parameter: ", err)
Expand All @@ -71,10 +71,10 @@ func execute(cmd *cobra.Command) {
EnvName: envName,
Accounts: util.SplitProviderAccount(accounts),
ProvisioningType: provisioningType,
}, traceId)
}, traceID)

if err != nil {
log.Info("TraceId: ", traceId)
log.Info("TraceId: ", traceID)
log.Fatal("Failed to create environment ", err)
}
}
6 changes: 3 additions & 3 deletions cmd/delete/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ func init() {

func execute(cmd *cobra.Command) {
ctx := cmd.Context()
traceId := util.GenerateTraceId()
traceID := util.GenerateTraceID()
err := environmentClient.DeleteEnvironment(&ctx, &environment.DeleteEnvironmentRequest{
EnvName: name,
}, traceId)
}, traceID)

if err != nil {
log.Info("TraceId: ", traceId)
log.Info("TraceId: ", traceID)
log.Fatal("Failed to delete environment ", err)
}
}
7 changes: 4 additions & 3 deletions cmd/deploy/service-set.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func executeDeployServiceSet(cmd *cobra.Command) {
env = config.EnsureEnvPresent(env)

ctx := cmd.Context()
traceId := util.GenerateTraceId()
traceID := util.GenerateTraceID()
if serviceSetName == "" && provisioningFile == "" {
log.Fatal("Please provide either --name or --file.")
}
Expand All @@ -63,8 +63,9 @@ func executeDeployServiceSet(cmd *cobra.Command) {
deployServiceSetRequest.Name = serviceSetName
}

err := serviceClient.DeployServiceSet(&ctx, &deployServiceSetRequest, traceId)
err := serviceClient.DeployServiceSet(&ctx, &deployServiceSetRequest, traceID)
if err != nil {
log.Fatal("Failed to deploy service ", err)
log.Info("TraceId: ", traceID)
log.Fatal("Failed to deploy service set", err)
}
}
10 changes: 5 additions & 5 deletions cmd/deploy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func init() {
func execute(cmd *cobra.Command) {
env = config.EnsureEnvPresent(env)
ctx := cmd.Context()
traceId := util.GenerateTraceId()
traceID := util.GenerateTraceID()
if (serviceName == "" && serviceVersion == "") && (definitionFile != "" && provisioningFile != "") {
definitionData, err := os.ReadFile(definitionFile)
if err != nil {
Expand All @@ -71,10 +71,10 @@ func execute(cmd *cobra.Command) {
EnvName: env,
ServiceDefinition: &definitionProto,
ProvisioningConfig: provisioningProto,
}, traceId)
}, traceID)

if err != nil {
log.Info("TraceId: ", traceId)
log.Info("TraceId: ", traceID)
log.Fatal("Failed to deploy service ", err)
}
} else if (serviceName != "" && serviceVersion != "") && (definitionFile == "" && provisioningFile == "") {
Expand All @@ -85,10 +85,10 @@ func execute(cmd *cobra.Command) {
ServiceName: serviceName,
ServiceVersion: serviceVersion,
},
}, traceId)
}, traceID)

if err != nil {
log.Info("TraceId: ", traceId)
log.Info("TraceId: ", traceID)
log.Fatal("Failed to deploy service ", err)
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions cmd/describe/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ func executeDescribeComponentType(cmd *cobra.Command) {
"version": componentVersion,
}
ctx := cmd.Context()
traceId := util.GenerateTraceId()
traceID := util.GenerateTraceID()
response, err := componentClient.DescribeComponentType(&ctx, &comp.DescribeComponentTypeRequest{
ComponentType: componentName,
Params: params,
}, traceId)
}, traceID)

if err != nil {
log.Info("TraceId: ", traceId)
log.Info("TraceId: ", traceID)
log.Fatal("Failed to describe service: ", err)
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/describe/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func init() {

func executeEnv(cmd *cobra.Command) {
ctx := cmd.Context()
traceId := util.GenerateTraceId()
traceID := util.GenerateTraceID()
params := map[string]string{}

if serviceName != "" {
Expand All @@ -49,10 +49,10 @@ func executeEnv(cmd *cobra.Command) {
response, err := environmentClient.DescribeEnvironment(&ctx, &environment.DescribeEnvironmentRequest{
Params: params,
EnvName: name,
}, traceId)
}, traceID)

if err != nil {
log.Info("TraceId: ", traceId)
log.Info("TraceId: ", traceID)
log.Fatal("Failed to describe environment ", err)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/describe/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ func execute(cmd *cobra.Command) {
}

ctx := cmd.Context()
traceId := util.GenerateTraceId()
traceID := util.GenerateTraceID()
response, err := serviceClient.DescribeService(&ctx, &service.DescribeServiceRequest{
ServiceName: serviceName,
Version: serviceVersion,
Params: params,
}, traceId)
}, traceID)

if err != nil {
log.Fatal("Failed to describe service: ", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/list/componentType.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func init() {

func componentExecute(cmd *cobra.Command) {
ctx := cmd.Context()
traceId := util.GenerateTraceId()
traceID := util.GenerateTraceID()
params := make(map[string]string)

// Add non-empty parameters to the map
Expand All @@ -51,7 +51,7 @@ func componentExecute(cmd *cobra.Command) {
// Make the API call with the populated parameters
response, err := componentTypeClient.ListComponentType(&ctx, &component.ListComponentTypeRequest{
Params: params,
}, traceId)
}, traceID)

if err != nil {
log.Fatal("Failed to list component types ", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/list/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func init() {

func execute(cmd *cobra.Command) {
ctx := cmd.Context()
traceId := util.GenerateTraceId()
traceID := util.GenerateTraceID()
response, err := environmentClient.ListEnvironments(&ctx, &environment.ListEnvironmentRequest{
Params: map[string]string{
"name": name,
"account": account,
"provisioningType": provisioningType,
"displayAll": strconv.FormatBool(displayAll)},
}, traceId)
}, traceID)

if err != nil {
log.Fatal("Failed to list environments ", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/list/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func init() {

func listService(cmd *cobra.Command) {
ctx := cmd.Context()
traceId := util.GenerateTraceId()
traceID := util.GenerateTraceID()
response, err := serviceClient.ListService(&ctx, &serviceProto.ListServiceRequest{
Name: serviceName,
Version: version,
Tags: tags,
}, traceId)
}, traceID)

if err != nil {
log.Fatal("Failed to list services ", err)
Expand Down
7 changes: 3 additions & 4 deletions cmd/operate/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/dream11/odin/internal/service"
"github.com/dream11/odin/pkg/config"
fileUtil "github.com/dream11/odin/pkg/util"
serviceProto "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -55,7 +54,7 @@ func execute(cmd *cobra.Command) {
env = config.EnsureEnvPresent(env)

ctx := cmd.Context()
traceId := util.GenerateTraceId()
traceID := util.GenerateTraceID()
//validate the variables
var optionsData map[string]interface{}

Expand All @@ -67,7 +66,7 @@ func execute(cmd *cobra.Command) {
}

if isFilePresent {
parsedConfig, err := fileUtil.ParseFile(file)
parsedConfig, err := util.ParseFile(file)
if err != nil {
log.Fatal("Error while parsing file " + file + " : " + err.Error())
}
Expand All @@ -91,7 +90,7 @@ func execute(cmd *cobra.Command) {
IsComponentOperation: true,
Operation: operation,
Config: config,
}, traceId)
}, traceID)

if err != nil {
log.Fatal("Failed to operate on component", err)
Expand Down
7 changes: 3 additions & 4 deletions cmd/operate/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/dream11/odin/internal/service"
"github.com/dream11/odin/pkg/config"
fileUtil "github.com/dream11/odin/pkg/util"
serviceProto "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -45,7 +44,7 @@ func executeOperateService(cmd *cobra.Command) {
env = config.EnsureEnvPresent(env)

ctx := cmd.Context()
traceId := util.GenerateTraceId()
traceID := util.GenerateTraceID()
//validate the variables
var optionsData map[string]interface{}

Expand All @@ -57,7 +56,7 @@ func executeOperateService(cmd *cobra.Command) {
}

if isFilePresent {
parsedConfig, err := fileUtil.ParseFile(file)
parsedConfig, err := util.ParseFile(file)
if err != nil {
log.Fatal("Error while parsing file " + file + " : " + err.Error())
}
Expand All @@ -80,7 +79,7 @@ func executeOperateService(cmd *cobra.Command) {
IsComponentOperation: false,
Operation: operation,
Config: config,
}, traceId)
}, traceID)

if err != nil {
log.Fatal("Failed to operate on service", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/release/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func init() {

func execute(cmd *cobra.Command) {
ctx := cmd.Context()
traceId := util.GenerateTraceId()
traceID := util.GenerateTraceID()

var err error

Expand Down Expand Up @@ -104,7 +104,7 @@ func execute(cmd *cobra.Command) {
}
serviceReleaseRequest.ProvisioningConfigs = provisioningConfigMap
serviceReleaseRequest.ServiceDefinition = &definitionProto
err = serviceClient.ReleaseService(&ctx, &serviceReleaseRequest, traceId)
err = serviceClient.ReleaseService(&ctx, &serviceReleaseRequest, traceID)
if err != nil {
log.Fatal("Failed to release service ", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/undeploy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ func execute(cmd *cobra.Command) {
envName = config.EnsureEnvPresent(envName)

ctx := cmd.Context()
traceId := util.GenerateTraceId()
traceID := util.GenerateTraceID()

err := serviceClient.UndeployService(&ctx, &serviceProto.UndeployServiceRequest{
EnvName: envName,
ServiceName: name,
}, traceId)
}, traceID)

if err != nil {
log.Fatal("Failed to undeploy service ", err)
Expand Down
10 changes: 5 additions & 5 deletions internal/service/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
"google.golang.org/grpc/metadata"
)

func grpcClient(ctx *context.Context, traceIdOptional ...string) (*grpc.ClientConn, *context.Context, error) {
func grpcClient(ctx *context.Context, traceIDOptional ...string) (*grpc.ClientConn, *context.Context, error) {
appConfig := config.GetConfig()

traceId := ""
if len(traceIdOptional) > 0 {
traceId = traceIdOptional[0]
traceID := ""
if len(traceIDOptional) > 0 {
traceID = traceIDOptional[0]
}

if appConfig.BackendAddress == "" {
Expand Down Expand Up @@ -49,6 +49,6 @@ func grpcClient(ctx *context.Context, traceIdOptional ...string) (*grpc.ClientCo
return nil, nil, err
}
// Enrich context with authorisation metadata
requestCtx := metadata.AppendToOutgoingContext(*ctx, "Authorization", fmt.Sprintf("Bearer %s", appConfig.AccessToken), "TraceId", traceId)
requestCtx := metadata.AppendToOutgoingContext(*ctx, "Authorization", fmt.Sprintf("Bearer %s", appConfig.AccessToken), "TraceId", traceID)
return conn, &requestCtx, nil
}
12 changes: 6 additions & 6 deletions internal/service/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
type Component struct{}

// OperateComponent operate Component
func (e *Component) OperateComponent(ctx *context.Context, request *serviceProto.OperateServiceRequest, traceId string) error {
conn, requestCtx, err := grpcClient(ctx, traceId)
func (e *Component) OperateComponent(ctx *context.Context, request *serviceProto.OperateServiceRequest, traceID string) error {
conn, requestCtx, err := grpcClient(ctx, traceID)
if err != nil {
return err
}
Expand Down Expand Up @@ -56,8 +56,8 @@ func (e *Component) OperateComponent(ctx *context.Context, request *serviceProto
}

// ListComponentType List component types
func (e *Component) ListComponentType(ctx *context.Context, request *component.ListComponentTypeRequest, traceId string) (*component.ListComponentTypeResponse, error) {
conn, requestCtx, err := grpcClient(ctx, traceId)
func (e *Component) ListComponentType(ctx *context.Context, request *component.ListComponentTypeRequest, traceID string) (*component.ListComponentTypeResponse, error) {
conn, requestCtx, err := grpcClient(ctx, traceID)
if err != nil {
return nil, err
}
Expand All @@ -71,8 +71,8 @@ func (e *Component) ListComponentType(ctx *context.Context, request *component.L
}

// DescribeComponentType List component types
func (e *Component) DescribeComponentType(ctx *context.Context, request *component.DescribeComponentTypeRequest, traceId string) (*component.DescribeComponentTypeResponse, error) {
conn, requestCtx, err := grpcClient(ctx, traceId)
func (e *Component) DescribeComponentType(ctx *context.Context, request *component.DescribeComponentTypeRequest, traceID string) (*component.DescribeComponentTypeResponse, error) {
conn, requestCtx, err := grpcClient(ctx, traceID)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 2812544

Please sign in to comment.