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

[MetricBeat] [AWS] if the number of resources is a multiple of 50, there is no tags field in the event #26385

Closed
kwinstonix opened this issue Jun 21, 2021 · 3 comments · Fixed by #26443
Assignees
Labels
Team:Integrations Label for the Integrations team

Comments

@kwinstonix
Copy link
Contributor

kwinstonix commented Jun 21, 2021

the problem

I found a strange problem of AWS cloudwatch module, there are some EC2 instances cross some regions, but sometimes metricbeat event of some region has no tags. I can query tags with aws CLI aws resourcegroupstaggingapi, then I think there is some bug in the logic of querying tags.

  • Version: 7.13

  • Operating System: linux

  • Steps to Reproduce:

    • Some AWS resource's amount is a multiple of 50(e.g. 100 EC2 instances)
    • Use aws CloudWatch Module

metricbeat config:

  - module: aws
    access_key_id: 'your access key'
    secret_access_key: 'your secret key'
    period: 300s
    regions:
      - ap-northeast-1
    metricsets:
      - cloudwatch
    metrics:
      - namespace: AWS/EC2
        name: CPUUtilization
        statistic: ["Average"]
        resource_type: "ec2:instance"

the reason

  • aws resourcegroupstaggingapi has strange behavior, with the default pagination size of 50 and 100 EC2 instances, we need send three times request and there is zero result in the last request
  • line 191 is not safe and correct, we should break the for loop if output.ResourceTagMappingList is an empty result, then the function can return resourceTagMap to the caller.

func GetResourcesTags(svc resourcegroupstaggingapiiface.ClientAPI, resourceTypeFilters []string) (map[string][]resourcegroupstaggingapi.Tag, error) {
if resourceTypeFilters == nil {
return map[string][]resourcegroupstaggingapi.Tag{}, nil
}
resourceTagMap := make(map[string][]resourcegroupstaggingapi.Tag)
getResourcesInput := &resourcegroupstaggingapi.GetResourcesInput{
PaginationToken: nil,
ResourceTypeFilters: resourceTypeFilters,
}
init := true
for init || *getResourcesInput.PaginationToken != "" {
init = false
getResourcesRequest := svc.GetResourcesRequest(getResourcesInput)
output, err := getResourcesRequest.Send(context.TODO())
if err != nil {
err = errors.Wrap(err, "error GetResources")
return nil, err
}
getResourcesInput.PaginationToken = output.PaginationToken
if resourceTypeFilters == nil || len(output.ResourceTagMappingList) == 0 {
return nil, nil
}
for _, resourceTag := range output.ResourceTagMappingList {

I modify the if statemen, then metricebeat event has tags field.

if len(output.ResourceTagMappingList) == 0 {  	
    break
} 
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jun 21, 2021
@kwinstonix kwinstonix changed the title [MetricBeat] [AWS] if The number of resources is a multiple of 50 [MetricBeat] [AWS] if the number of resources is a multiple of 50, there is not tags in the event Jun 21, 2021
@kwinstonix kwinstonix changed the title [MetricBeat] [AWS] if the number of resources is a multiple of 50, there is not tags in the event [MetricBeat] [AWS] if the number of resources is a multiple of 50, there is no tags field in the event Jun 21, 2021
@kaiyan-sheng kaiyan-sheng self-assigned this Jun 21, 2021
@kaiyan-sheng kaiyan-sheng added the Team:Integrations Label for the Integrations team label Jun 21, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@kwinstonix
Copy link
Contributor Author

@kaiyan-sheng , I opened a PR to fix this. Could you help me review it ?

@kaiyan-sheng
Copy link
Contributor

Yes!! Thank you so much for the PR! Will review it shortly!!

kwinstonix added a commit to kwinstonix/beats that referenced this issue Jun 30, 2021
kaiyan-sheng added a commit that referenced this issue Jun 30, 2021
kaiyan-sheng added a commit that referenced this issue Jun 30, 2021
mdelapenya added a commit to mdelapenya/beats that referenced this issue Jul 1, 2021
* master:
  [MetricBeat] [AWS] Fix aws metric tags with resourcegroupstaggingapi paginator (elastic#26385) (elastic#26443)
  Move openmetrics module to oss (elastic#26561)
  Skip flaky test TestFilestreamMetadataUpdatedOnRename (elastic#26609)
  [filebeat][fortinet] Use default add_locale for fortinet.firewall (elastic#26524)
  Enroll proxy settings (elastic#26514)
v1v added a commit to v1v/beats that referenced this issue Jul 5, 2021
…stage-failed-within-same-build

* upstream/master: (36 commits)
  Revert "[CI] fight the flakiness with some retry option in the CI only for the Pull Requests (elastic#26617)" (elastic#26704)
  Packaging: linux/armv7 is not supported (elastic#26706)
  Cyberarkpas: Link to official docs on how to setup TLS (elastic#26614)
  Make network_direction, registered_domain and convert processors compatible with ES older than 7.13.0 (elastic#26676)
  Disable armv7 packaging (elastic#26679)
  [Heartbeat] use --params flag for synthetics (elastic#26674)
  Update dependent package to avoid downloading a suspicious file (elastic#26406)
  [mergify] set title and allow bp in any direction (elastic#26648)
  Fix memory leak in SQL helper when database is not available (elastic#26607)
  [CI] fight the flakiness with some retry option in the CI only for the Pull Requests (elastic#26617)
  [mergify] automate PRs that change the backport rules (elastic#26641)
  [Metricbeat] Add Airflow module in xpack (elastic#26220)
  chore: add-backport-next (elastic#26620)
  [metricbeat] Add state_job metricset (elastic#26479)
  CI: jenkins labels are less time consuming now (elastic#26613)
  [MetricBeat] [AWS] Fix aws metric tags with resourcegroupstaggingapi paginator (elastic#26385) (elastic#26443)
  Move openmetrics module to oss (elastic#26561)
  Skip flaky test TestFilestreamMetadataUpdatedOnRename (elastic#26609)
  [filebeat][fortinet] Use default add_locale for fortinet.firewall (elastic#26524)
  Enroll proxy settings (elastic#26514)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Integrations Label for the Integrations team
Projects
None yet
3 participants