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

[Docker] Stop returning errors when there are no metric values #39807

Merged
merged 4 commits into from
Jun 7, 2024

Conversation

zmoog
Copy link
Contributor

@zmoog zmoog commented Jun 5, 2024

Proposed commit message

Stop returning errors when there are no metric values for the Docker memory metricset.

The docker metricset returns an error when there are no memory metric values available. This condition can happen when there are no running containers on Docker.

When no containers are running, the metricset returns an error at every collection, creating noise.

Notes for reviewers

  • Is there a use case when we should return an error instead?
  • Should I add a logger to log a debug message saying "no memory stats data available"?

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Related issues

The docker metricset returns an error when there are no memory metric
values available.

This condition can happen when there are no running containers on
Docker.

When no containers are running, the metricset returns an error
at every collection, creating noise.
@zmoog zmoog self-assigned this Jun 5, 2024
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jun 5, 2024
Copy link
Contributor

mergify bot commented Jun 5, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @zmoog? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v8./d.0 is the label to automatically backport to the 8./d branch. /d is the digit

@zmoog zmoog changed the title [Docker] Return nil instead or an error if no metrics [Docker] [Metrics] Stop returning errors when there are no metric values Jun 5, 2024
@zmoog zmoog changed the title [Docker] [Metrics] Stop returning errors when there are no metric values [Docker] Stop returning errors when there are no metric values Jun 5, 2024
@zmoog zmoog marked this pull request as ready for review June 5, 2024 11:31
@zmoog zmoog requested a review from a team as a code owner June 5, 2024 11:32
@zmoog zmoog requested review from faec and leehinman June 5, 2024 11:32
@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Jun 5, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jun 5, 2024
@zmoog
Copy link
Contributor Author

zmoog commented Jun 5, 2024

@fearful-symmetry, do you see any issue in replacing the error with a debug log message? I see you added the error years ago.

@zmoog
Copy link
Contributor Author

zmoog commented Jun 5, 2024

Here is an example of log message:

{
    "log.level": "debug",
    "@timestamp": "2024-06-05T22:48:55.082+0200",
    "log.logger": "memory",
    "log.origin": {
        "function": "github.com/elastic/beats/v7/metricbeat/module/docker/memory.(*MetricSet).Fetch",
        "file.name": "memory/memory.go",
        "file.line": 84
    },
    "message": "No memory stats data available",
    "service.name": "metricbeat",
    "ecs.version": "1.6.0"
}

It looks good, but the log.logger value "memory" is not great; it requires checking the log.origin.function value to learn it's part of the docker module.

What's the expected format in Baats?

Copy link
Contributor

@faec faec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit about the logger name, otherwise looks good

metricbeat/module/docker/memory/memory.go Outdated Show resolved Hide resolved
Remove the const for the metricset name. Managing module and metricset
name as const would require a larger change, which is out of scope.

I prefer to keep things as simple as possible for this quick fix, and
leave other decisions to code owners.
@zmoog zmoog added the backport-v8.14.0 Automated backport with mergify label Jun 7, 2024
@zmoog zmoog enabled auto-merge (squash) June 7, 2024 14:03
@zmoog zmoog merged commit 4c1d3f2 into elastic:main Jun 7, 2024
19 checks passed
mergify bot pushed a commit that referenced this pull request Jun 7, 2024
* Return nil instead or an error if no metrics

The docker metricset returns an error when there are no memory metric
values available.

This condition can happen when there are no running containers on
Docker.

When no containers are running, the metricset returns an error
at every collection, creating noise.

* Add a "docker.memory" logger to write a debug message on no-metrics

(cherry picked from commit 4c1d3f2)
@zmoog zmoog deleted the zmoog/docker-no-container-running branch June 7, 2024 14:36
zmoog added a commit that referenced this pull request Jun 10, 2024
… (#39829)

* Return nil instead or an error if no metrics

The docker metricset returns an error when there are no memory metric
values available.

This condition can happen when there are no running containers on
Docker.

When no containers are running, the metricset returns an error
at every collection, creating noise.

* Add a "docker.memory" logger to write a debug message on no-metrics

(cherry picked from commit 4c1d3f2)

Co-authored-by: Maurizio Branca <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.14.0 Automated backport with mergify Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants