Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable gocritic in exporter/awsemfexporter #12750

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions exporter/awsemfexporter/grouped_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package awsemfexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter"

import (
Expand Down Expand Up @@ -136,7 +135,7 @@ type internalPodOwnersObj struct {
}

func addKubernetesWrapper(labels map[string]string) {
//fill in obj
// fill in obj
filledInObj := kubernetesObj{
ContainerName: mapGetHelper(labels, "container"),
Docker: &internalDockerObj{
Expand All @@ -157,7 +156,7 @@ func addKubernetesWrapper(labels map[string]string) {
ServiceName: mapGetHelper(labels, "Service"),
}

//handle nested empty object
// handle nested empty object
if filledInObj.Docker.ContainerID == "" {
filledInObj.Docker = nil
}
Expand Down
3 changes: 1 addition & 2 deletions exporter/awsemfexporter/metric_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package awsemfexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter"

import (
Expand Down Expand Up @@ -345,7 +344,7 @@ func translateCWMetricToEMF(cWMetric *cWMetrics, config *Config) *cwlogs.Event {
cWMetricMap := make(map[string]interface{})
fieldMap := cWMetric.fields

//restore the json objects that are stored as string in attributes
// restore the json objects that are stored as string in attributes
for _, key := range config.ParseJSONEncodedAttributeValues {
if fieldMap[key] == nil {
continue
Expand Down
21 changes: 11 additions & 10 deletions exporter/awsemfexporter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package awsemfexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter"

import (
Expand Down Expand Up @@ -55,7 +54,7 @@ func replacePatternWithAttrValue(s, patternKey string, attrMap map[string]string
return replace(s, pattern, value, logger)
} else {
logger.Debug("No resource attribute found for pattern " + pattern)
return strings.Replace(s, pattern, "undefined", -1), false
return strings.ReplaceAll(s, pattern, "undefined"), false
}
}
return s, true
Expand All @@ -64,21 +63,22 @@ func replacePatternWithAttrValue(s, patternKey string, attrMap map[string]string
func replace(s, pattern string, value string, logger *zap.Logger) (string, bool) {
if value == "" {
logger.Debug("Empty resource attribute value found for pattern " + pattern)
return strings.Replace(s, pattern, "undefined", -1), false
return strings.ReplaceAll(s, pattern, "undefined"), false
}
return strings.Replace(s, pattern, value, -1), true
return strings.ReplaceAll(s, pattern, value), true
}

// getNamespace retrieves namespace for given set of metrics from user config.
func getNamespace(rm *pmetric.ResourceMetrics, namespace string) string {
if len(namespace) == 0 {
serviceName, svcNameOk := rm.Resource().Attributes().Get(conventions.AttributeServiceName)
serviceNamespace, svcNsOk := rm.Resource().Attributes().Get(conventions.AttributeServiceNamespace)
if svcNameOk && svcNsOk && serviceName.Type() == pcommon.ValueTypeString && serviceNamespace.Type() == pcommon.ValueTypeString {
switch {
case svcNameOk && svcNsOk && serviceName.Type() == pcommon.ValueTypeString && serviceNamespace.Type() == pcommon.ValueTypeString:
namespace = fmt.Sprintf("%s/%s", serviceNamespace.StringVal(), serviceName.StringVal())
} else if svcNameOk && serviceName.Type() == pcommon.ValueTypeString {
case svcNameOk && serviceName.Type() == pcommon.ValueTypeString:
namespace = serviceName.StringVal()
} else if svcNsOk && serviceNamespace.Type() == pcommon.ValueTypeString {
case svcNsOk && serviceNamespace.Type() == pcommon.ValueTypeString:
namespace = serviceNamespace.StringVal()
}
}
Expand Down Expand Up @@ -142,15 +142,16 @@ func dimensionRollup(dimensionRollupOption string, labels map[string]string) [][
}

if dimensionRollupOption == zeroAndSingleDimensionRollup {
//"Zero" dimension rollup
// "Zero" dimension rollup
if len(labels) > 0 {
rollupDimensionArray = append(rollupDimensionArray, dimensionZero)
}
}
if dimensionRollupOption == zeroAndSingleDimensionRollup || dimensionRollupOption == singleDimensionRollupOnly {
//"One" dimension rollup
// "One" dimension rollup
for labelName := range labels {
dimSet := append(dimensionZero, labelName)
dimSet := dimensionZero
dimSet = append(dimSet, labelName)
sort.Strings(dimSet)
rollupDimensionArray = append(rollupDimensionArray, dimSet)
}
Expand Down
3 changes: 1 addition & 2 deletions exporter/awsemfexporter/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package awsemfexporter

import (
Expand Down Expand Up @@ -326,7 +325,7 @@ func TestGetLogInfo(t *testing.T) {
"/aws/ecs/containerinsights/test-cluster-name/performance",
"test-task-id",
},
//test case for aws container insight usage
// test case for aws container insight usage
{
"empty namespace, config w/ pattern",
"",
Expand Down