From b50d4f5b99e4e3563491dc04ce71e1a600033e3a Mon Sep 17 00:00:00 2001 From: Jevon Jackson Date: Tue, 29 Jun 2021 11:37:27 -0700 Subject: [PATCH 1/2] clearing up inline comments --- cmd/configschema/configwiz/configwiz/cli.go | 8 ++++++++ .../configwiz/configwiz/component.go | 17 ++++++----------- .../configwiz/configwiz/pipelines.go | 6 +++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cmd/configschema/configwiz/configwiz/cli.go b/cmd/configschema/configwiz/configwiz/cli.go index a50543f01b5c..c93467921c62 100644 --- a/cmd/configschema/configwiz/configwiz/cli.go +++ b/cmd/configschema/configwiz/configwiz/cli.go @@ -36,6 +36,14 @@ func CLI(factories component.Factories) { handleComponent(factories, m, componentGroup, names, dr) } + /* + We are having a problem with the order in which the config file is being outputted + Maps key values are automatically sorted alphabetically -> we need it in the order of the pipeline + + Because we have to output this to a file, can we just take care of it then by checking the + bytes that we are about to print out? Possibly save the offset of string to get to the starting byte? + Might not be the best way to go about this, will figure something out. + */ bytes, _ := yaml.Marshal(m) fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") fmt.Println(string(bytes)) diff --git a/cmd/configschema/configwiz/configwiz/component.go b/cmd/configschema/configwiz/configwiz/component.go index f313dc7e7d05..b2e2416be4da 100644 --- a/cmd/configschema/configwiz/configwiz/component.go +++ b/cmd/configschema/configwiz/configwiz/component.go @@ -56,15 +56,10 @@ func handleComponent( ) { typeMap := map[string]interface{}{} m[componentGroup+"s"] = typeMap - var err error - var cfgInfo configschema.CfgInfo + //var err error + //var cfgInfo configschema.CfgInfo for _, name := range names { - if strings.Contains(name, "/") { - compName := strings.Split(name, "/")[0] - cfgInfo, err = configschema.GetCfgInfo(factories, componentGroup, compName) - } else { - cfgInfo, err = configschema.GetCfgInfo(factories, componentGroup, name) - } + cfgInfo, err := configschema.GetCfgInfo(factories, componentGroup, strings.Split(name, "/")[0]) if err != nil { panic(err) } @@ -100,11 +95,11 @@ func handleField(p indentingPrinter, field *configschema.Field, out map[string]i p.println("Field: " + field.Name) typ := resolveType(field) if typ != "" { - p.print("Type: " + typ) + typString := "Type: " + typ if typ == "time.Duration" { - fmt.Print(" (examples: 1h2m3s, 5m10s, 45s)") + typString += " (examples: 1h2m3s, 5m10s, 45s)" } - p.print("\n") + p.println(typString) } if field.Doc != "" { p.println("Docs: " + strings.ReplaceAll(field.Doc, "\n", " ")) diff --git a/cmd/configschema/configwiz/configwiz/pipelines.go b/cmd/configschema/configwiz/configwiz/pipelines.go index 2d6c908ae5bd..0dc4e83f5ccb 100644 --- a/cmd/configschema/configwiz/configwiz/pipelines.go +++ b/cmd/configschema/configwiz/configwiz/pipelines.go @@ -25,7 +25,7 @@ import ( "go.opentelemetry.io/collector/component/componenterror" ) -const invalid string = "Invalid input. Try again." +const invalidMsg = "Invalid input. Try again." func pipelinesWizard(factories component.Factories) map[string]interface{} { out := map[string]interface{}{} @@ -72,7 +72,7 @@ func singlePipelineWizard(factories component.Factories) (string, rpe) { exporterNames(factories, isTracesExporter), extensionNames(factories, isExtension)) } - fmt.Println(invalid) + fmt.Println(invalidMsg) return singlePipelineWizard(factories) } @@ -139,7 +139,7 @@ func componentNameWizard(pr indentingPrinter, componentType string, componentNam } i, _ := strconv.Atoi(choice) if i < 0 || i > len(componentNames)-1 { - fmt.Println(invalid) + fmt.Println(invalidMsg) return componentNameWizard(pr, componentType, componentNames) } key := componentNames[i] From 97b9b0daae9f04b6c76743b2ad3bc521645e615d Mon Sep 17 00:00:00 2001 From: Jevon Jackson Date: Tue, 29 Jun 2021 11:49:26 -0700 Subject: [PATCH 2/2] Reformatted and removed comments --- cmd/configschema/configwiz/configwiz/cli.go | 8 -------- cmd/configschema/configwiz/configwiz/component.go | 2 -- 2 files changed, 10 deletions(-) diff --git a/cmd/configschema/configwiz/configwiz/cli.go b/cmd/configschema/configwiz/configwiz/cli.go index c93467921c62..a50543f01b5c 100644 --- a/cmd/configschema/configwiz/configwiz/cli.go +++ b/cmd/configschema/configwiz/configwiz/cli.go @@ -36,14 +36,6 @@ func CLI(factories component.Factories) { handleComponent(factories, m, componentGroup, names, dr) } - /* - We are having a problem with the order in which the config file is being outputted - Maps key values are automatically sorted alphabetically -> we need it in the order of the pipeline - - Because we have to output this to a file, can we just take care of it then by checking the - bytes that we are about to print out? Possibly save the offset of string to get to the starting byte? - Might not be the best way to go about this, will figure something out. - */ bytes, _ := yaml.Marshal(m) fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") fmt.Println(string(bytes)) diff --git a/cmd/configschema/configwiz/configwiz/component.go b/cmd/configschema/configwiz/configwiz/component.go index b2e2416be4da..6609a3f82bb1 100644 --- a/cmd/configschema/configwiz/configwiz/component.go +++ b/cmd/configschema/configwiz/configwiz/component.go @@ -56,8 +56,6 @@ func handleComponent( ) { typeMap := map[string]interface{}{} m[componentGroup+"s"] = typeMap - //var err error - //var cfgInfo configschema.CfgInfo for _, name := range names { cfgInfo, err := configschema.GetCfgInfo(factories, componentGroup, strings.Split(name, "/")[0]) if err != nil {