Skip to content

Commit

Permalink
chore: Fix linter findings for revive:comment-spacings (part 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-pawel committed Sep 16, 2024
1 parent 8d282ab commit 9cd4cd1
Show file tree
Hide file tree
Showing 64 changed files with 306 additions and 313 deletions.
70 changes: 35 additions & 35 deletions plugins/inputs/aliyuncms/aliyuncms.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ type (
Metric struct {
ObjectsFilter string `toml:"objects_filter"`
MetricNames []string `toml:"names"`
Dimensions string `toml:"dimensions"` //String representation of JSON dimensions
Dimensions string `toml:"dimensions"` // String representation of JSON dimensions
TagsQueryPath []string `toml:"tag_query_path"`
AllowDataPointWODiscoveryData bool `toml:"allow_dps_without_discovery"` //Allow data points without discovery data (if no discovery data found)
AllowDataPointWODiscoveryData bool `toml:"allow_dps_without_discovery"` // Allow data points without discovery data (if no discovery data found)

dtLock sync.Mutex //Guard for discoveryTags & dimensions
discoveryTags map[string]map[string]string //Internal data structure that can enrich metrics with tags
dtLock sync.Mutex // Guard for discoveryTags & dimensions
discoveryTags map[string]map[string]string // Internal data structure that can enrich metrics with tags
dimensionsUdObj map[string]string
dimensionsUdArr []map[string]string //Parsed Dimesnsions JSON string (unmarshalled)
requestDimensions []map[string]string //this is the actual dimensions list that would be used in API request
requestDimensionsStr string //String representation of the above
dimensionsUdArr []map[string]string // Parsed Dimesnsions JSON string (unmarshalled)
requestDimensions []map[string]string // this is the actual dimensions list that would be used in API request
requestDimensionsStr string // String representation of the above

}

Expand Down Expand Up @@ -149,7 +149,7 @@ func (s *AliyunCMS) Init() error {
return fmt.Errorf("failed to create cms client: %w", err)
}

//check metrics dimensions consistency
// check metrics dimensions consistency
for i := range s.Metrics {
metric := s.Metrics[i]
if metric.Dimensions == "" {
Expand All @@ -172,15 +172,15 @@ func (s *AliyunCMS) Init() error {

s.measurement = formatMeasurement(s.Project)

//Check regions
// Check regions
if len(s.Regions) == 0 {
s.Regions = aliyunRegionList
s.Log.Infof("'regions' is not set. Metrics will be queried across %d regions:\n%s",
len(s.Regions), strings.Join(s.Regions, ","))
}

//Init discovery...
if s.dt == nil { //Support for tests
// Init discovery...
if s.dt == nil { // Support for tests
s.dt, err = newDiscoveryTool(s.Regions, s.Project, s.Log, credential, int(float32(s.RateLimit)*0.2), time.Duration(s.DiscoveryInterval))
if err != nil {
s.Log.Errorf("Discovery tool is not activated: %v", err)
Expand All @@ -198,7 +198,7 @@ func (s *AliyunCMS) Init() error {

s.Log.Infof("%d object(s) discovered...", len(s.discoveryData))

//Special setting for acs_oss project since the API differs
// Special setting for acs_oss project since the API differs
if s.Project == "acs_oss" {
s.dimensionKey = "BucketName"
}
Expand All @@ -208,7 +208,7 @@ func (s *AliyunCMS) Init() error {

// Start plugin discovery loop, metrics are gathered through Gather
func (s *AliyunCMS) Start(telegraf.Accumulator) error {
//Start periodic discovery process
// Start periodic discovery process
if s.dt != nil {
s.dt.start()
}
Expand All @@ -226,7 +226,7 @@ func (s *AliyunCMS) Gather(acc telegraf.Accumulator) error {

var wg sync.WaitGroup
for _, metric := range s.Metrics {
//Prepare internal structure with data from discovery
// Prepare internal structure with data from discovery
s.prepareTagsAndDimensions(metric)
wg.Add(len(metric.MetricNames))
for _, metricName := range metric.MetricNames {
Expand All @@ -250,10 +250,10 @@ func (s *AliyunCMS) Stop() {
}

func (s *AliyunCMS) updateWindow(relativeTo time.Time) {
//https://help.aliyun.com/document_detail/51936.html?spm=a2c4g.11186623.6.701.54025679zh6wiR
//The start and end times are executed in the mode of
//opening left and closing right, and startTime cannot be equal
//to or greater than endTime.
// https://help.aliyun.com/document_detail/51936.html?spm=a2c4g.11186623.6.701.54025679zh6wiR
// The start and end times are executed in the mode of
// opening left and closing right, and startTime cannot be equal
// to or greater than endTime.

windowEnd := relativeTo.Add(-time.Duration(s.Delay))

Expand Down Expand Up @@ -310,8 +310,8 @@ func (s *AliyunCMS) gatherMetric(acc telegraf.Accumulator, metricName string, me
switch key {
case "instanceId", "BucketName":
tags[key] = value.(string)
if metric.discoveryTags != nil { //discovery can be not activated
//Skipping data point if discovery data not exist
if metric.discoveryTags != nil { // discovery can be not activated
// Skipping data point if discovery data not exist
_, ok := metric.discoveryTags[value.(string)]
if !ok &&
!metric.AllowDataPointWODiscoveryData {
Expand Down Expand Up @@ -349,7 +349,7 @@ func parseTag(tagSpec string, data interface{}) (tagKey, tagValue string, err er
)
tagKey = tagSpec

//Split query path to tagKey and query path
// Split query path to tagKey and query path
if splitted := strings.Split(tagSpec, ":"); len(splitted) == 2 {
tagKey = splitted[0]
queryPath = splitted[1]
Expand All @@ -360,7 +360,7 @@ func parseTag(tagSpec string, data interface{}) (tagKey, tagValue string, err er
return "", "", fmt.Errorf("can't query data from discovery data using query path %q: %w", queryPath, err)
}

if tagRawValue == nil { //Nothing found
if tagRawValue == nil { // Nothing found
return "", "", nil
}

Expand All @@ -378,11 +378,11 @@ func (s *AliyunCMS) prepareTagsAndDimensions(metric *Metric) {
defaultTags = []string{"RegionId:RegionId"}
)

if s.dt == nil { //Discovery is not activated
if s.dt == nil { // Discovery is not activated
return
}

//Reading all data from buffered channel
// Reading all data from buffered channel
L:
for {
select {
Expand All @@ -394,7 +394,7 @@ L:
}
}

//new data arrives (so process it) or this is the first call
// new data arrives (so process it) or this is the first call
if newData || len(metric.discoveryTags) == 0 {
metric.dtLock.Lock()
defer metric.dtLock.Unlock()
Expand All @@ -403,13 +403,13 @@ L:
metric.discoveryTags = make(map[string]map[string]string, len(s.discoveryData))
}

metric.requestDimensions = nil //erasing
metric.requestDimensions = nil // erasing
metric.requestDimensions = make([]map[string]string, 0, len(s.discoveryData))

//Preparing tags & dims...
// Preparing tags & dims...
for instanceID, elem := range s.discoveryData {
//Start filing tags
//Remove old value if exist
// Start filing tags
// Remove old value if exist
delete(metric.discoveryTags, instanceID)
metric.discoveryTags[instanceID] = make(map[string]string, len(metric.TagsQueryPath)+len(defaultTags))

Expand All @@ -419,15 +419,15 @@ L:
s.Log.Errorf("%v", err)
continue
}
if err == nil && tagValue == "" { //Nothing found
if err == nil && tagValue == "" { // Nothing found
s.Log.Debugf("Data by query path %q: is not found, for instance %q", tagQueryPath, instanceID)
continue
}

metric.discoveryTags[instanceID][tagKey] = tagValue
}

//Adding default tags if not already there
// Adding default tags if not already there
for _, defaultTagQP := range defaultTags {
tagKey, tagValue, err := parseTag(defaultTagQP, elem)

Expand All @@ -436,7 +436,7 @@ L:
continue
}

if err == nil && tagValue == "" { //Nothing found
if err == nil && tagValue == "" { // Nothing found
s.Log.Debugf("Data by query path %q: is not found, for instance %q",
defaultTagQP, instanceID)
continue
Expand All @@ -445,23 +445,23 @@ L:
metric.discoveryTags[instanceID][tagKey] = tagValue
}

//if no dimension configured in config file, use discovery data
// if no dimension configured in config file, use discovery data
if len(metric.dimensionsUdArr) == 0 && len(metric.dimensionsUdObj) == 0 {
metric.requestDimensions = append(
metric.requestDimensions,
map[string]string{s.dimensionKey: instanceID})
}
}

//add dimensions filter from config file
// add dimensions filter from config file
if len(metric.dimensionsUdArr) != 0 {
metric.requestDimensions = append(metric.requestDimensions, metric.dimensionsUdArr...)
}
if len(metric.dimensionsUdObj) != 0 {
metric.requestDimensions = append(metric.requestDimensions, metric.dimensionsUdObj)
}

//Unmarshalling to string
// Unmarshalling to string
reqDim, err := json.Marshal(metric.requestDimensions)
if err != nil {
s.Log.Errorf("Can't marshal metric request dimensions %v :%v",
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/aliyuncms/aliyuncms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type mockGatherAliyunCMSClient struct{}
func (m *mockGatherAliyunCMSClient) DescribeMetricList(request *cms.DescribeMetricListRequest) (*cms.DescribeMetricListResponse, error) {
resp := new(cms.DescribeMetricListResponse)

//switch request.Metric {
// switch request.Metric {
switch request.MetricName {
case "InstanceActiveConnection":
resp.Code = "200"
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestPluginInitialize(t *testing.T) {
} else {
require.NoError(t, plugin.Init())
}
if len(tt.regions) == 0 { //Check if set to default
if len(tt.regions) == 0 { // Check if set to default
require.Equal(t, plugin.Regions, aliyunRegionList)
}
})
Expand Down Expand Up @@ -390,7 +390,7 @@ func TestGather(t *testing.T) {
Log: testutil.Logger{Name: inputTitle},
}

//test table:
// test table:
tests := []struct {
name string
hasMeasurement bool
Expand Down Expand Up @@ -444,7 +444,7 @@ func TestGather(t *testing.T) {
}

func TestGetDiscoveryDataAcrossRegions(t *testing.T) {
//test table:
// test table:
tests := []struct {
name string
project string
Expand Down
Loading

0 comments on commit 9cd4cd1

Please sign in to comment.