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

Logging code cleanup related to Nomad auto-discovery #26498

Merged
merged 6 commits into from
Jun 29, 2021

Conversation

andrewkroh
Copy link
Member

What does this PR do?

This does some minor clean up of the logging code and docs related to Nomad. I removed some statements that were providing duplicate information and switched a few over to using the structured logger to improve log readability.

A log message about enabled not being parsed was always being logged despite no actual error.

The doc examples were trying to start a Filebeat input with type: nomad.

Fixed some typos in code comments.

Why is it important?

This make debugging a little more enjoyable 😆 .

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

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jun 25, 2021
@elasticmachine
Copy link
Collaborator

elasticmachine commented Jun 25, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: andrewkroh commented: run tests

  • Start Time: 2021-06-28T20:14:20.169+0000

  • Duration: 97 min 40 sec

  • Commit: 7352205

Test stats 🧪

Test Results
Failed 0
Passed 29481
Skipped 3839
Total 33320

Trends 🧪

Image of Build Times

Image of Tests

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 29481
Skipped 3839
Total 33320

@andrewkroh
Copy link
Member Author

run tests

enabled: false
type: log
paths:
- /opt/nomad/alloc/${data.nomad.allocation.id}/alloc/logs/${data.nomad.task.name}.*
Copy link

Choose a reason for hiding this comment

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

I have a semi-related note about this path template (sorry if slightly off-topic)- when testing out this feature I noticed that the task.name data was only being published on the meta.nomad field of the event, not the nomad field used in this example. Here's the relevant code:

event := bus.Event{
"provider": p.uuid,
"id": fmt.Sprintf("%s-%s", obj.ID, task["name"]),
flag: true,
"host": nodeName,
"nomad": allocMeta,
"meta": common.MapStr{
"nomad": common.MapStrUnion(allocMeta, common.MapStr{
"task": task,
}),
},
}
p.publish(event)

In my tests, ${data.nomad.task.name} gave an invalid template reference error, but ${data.meta.nomad.task.name} resolved properly. Does this sound correct and if so, should all the documentation examples be updated to reflect this working usage? Or does a separate PR to fix the existing examples make more sense?

Copy link
Member Author

@andrewkroh andrewkroh Jun 28, 2021

Choose a reason for hiding this comment

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

When testing I noted that there was a lot of duplicate information in the autodiscover events that get published by that code. But I wasn't sure what the expected behavior was. And now that you bring it up, I see that there are docs for what should be in the events at https://www.elastic.co/guide/en/beats/filebeat/current/configuration-autodiscover.html#_nomad. So based on those docs I think I could change this and fix the missing nomad.task fields. Can you open a separate issue please?

Here's a sample document taken from the updated debug logs I added.

{
  "autodiscover.event": {
    "provider": "d4bc811c-9039-44a5-be01-fd60b08c1a6a",
    "meta": {
      "nomad": {
        "namespace": "default",
        "allocation": {
          "name": "hello-world.servers[0]",
          "id": "64782844-aedc-4acb-b72d-30dfe7f7939d",
          "status": "running"
        },
        "datacenter": [
          "va"
        ],
        "task": {
          "name": "hello-world"
        },
        "region": "global",
        "job": {
          "name": "hello-world",
          "type": "service"
        }
      }
    },
    "host": "compute01",
    "start": true,
    "id": "64782844-aedc-4acb-b72d-30dfe7f7939d-hello-world",
    "nomad": {
      "namespace": "default",
      "allocation": {
        "name": "hello-world.servers[0]",
        "id": "64782844-aedc-4acb-b72d-30dfe7f7939d",
        "status": "running"
      },
      "datacenter": [
        "va"
      ],
      "region": "global",
      "job": {
        "name": "hello-world",
        "type": "service"
      }
    },
    "config": []
  }
}

Copy link

Choose a reason for hiding this comment

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

Can you open a separate issue please?

Opened #26538.

But I wasn't sure what the expected behavior was.

It turns out there was some discussion around the need for this duplicate information in the original PR- see #14954 (comment).

Copy link
Member Author

Choose a reason for hiding this comment

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

Great find. So based on that comment it sounds like we need to keep both meta and nomad. But we can make sure all the documented keys are present under the nomad.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

I think only the nomad fields need to be available for config templates. The meta fields are used for enrichment, but shouldn't be necessarily available for templates. We probably messed something up in the original PR, I remember going back and forth on this 😬

We also have to double-check that hints based configs have the same fields available.

@andrewkroh
Copy link
Member Author

andrewkroh commented Jun 28, 2021

Note to self, two other things to fix:

  • Docs show secretID as config value but it's secret_id.

  • Docs are missing info about ACL requirements. Seems like filebeat needs an ACL token with these capabilities.

namespace "*" {
  policy = "read"
}
node {
  policy = "read"
}
agent {
  policy = "read"
}

@andrewkroh andrewkroh marked this pull request as ready for review June 28, 2021 15:24
@andrewkroh andrewkroh requested a review from a team as a code owner June 28, 2021 15:24
@andrewkroh andrewkroh added the Team:Integrations Label for the Integrations team label Jun 28, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jun 28, 2021
@andrewkroh andrewkroh requested a review from jsoriano June 28, 2021 15:28
@andrewkroh
Copy link
Member Author

run tests

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Thanks! Glad to see some activity around nomad 🙂

@jsoriano jsoriano added the backport-v7.14.0 Automated backport with mergify label Jun 29, 2021
@andrewkroh andrewkroh merged commit b061836 into elastic:master Jun 29, 2021
mergify bot pushed a commit that referenced this pull request Jun 29, 2021
* Logging and code cleanup related to Nomad auto-discover
* Fix a few doc nits
* Update heartbeat log line assertion
* Add complete example with discovery and add_nomad_metadata
* Fix secret_id and document minimal ACL policy

Closes #26456

(cherry picked from commit b061836)
andrewkroh added a commit that referenced this pull request Jun 29, 2021
* Logging and code cleanup related to Nomad auto-discover
* Fix a few doc nits
* Update heartbeat log line assertion
* Add complete example with discovery and add_nomad_metadata
* Fix secret_id and document minimal ACL policy

Closes #26456

(cherry picked from commit b061836)

Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>
v1v added a commit to v1v/beats that referenced this pull request Jun 29, 2021
…arwin-arm64

* upstream/master: (295 commits)
  Update urllib to 1.26.5. (elastic#26380)
  Update golang.org/x/crypto (elastic#26448)
  [Filebeat] Update Fortinet Ingest Pipeline (elastic#24816)
  Move parsers outside of filestream input so others can use them as well (elastic#26541)
  [Filebeat] Fix `threatintel.indicator.url.full` field not populating (elastic#26508)
  [Filebeat] Add network direction processor to Zeek and Suricata modules (elastic#24620)
  Logging code cleanup related to Nomad auto-discovery (elastic#26498)
  [Metricbeat] Add Couchbase's Sync Gateway module (elastic#25599)
  Refactor add_cloud_metadata to handle ECS fields easier (elastic#26438)
  [Elastic Agent] Improper casting of int64 (elastic#26520)
  [Elastic Agent] Enable configuring monitoring namespace (elastic#26439)
  [Heartbeat] configure permissions for synthetics config (elastic#26393)
  Osquerybeat: set the raw index name to supress the timestamp suffix (elastic#26545)
  [Heartbeat] add screenshots config to synthetics (elastic#26455)
  [Elastic Agent] Use http2 to connect to Fleet Server. (elastic#26474)
  Remove all docs about  Beats central management (elastic#26399)
  update data.json for gcp billing (elastic#26506)
  Skip x-pack metricbeat tests (elastic#26537)
  [Elastic Agent] Fix issue with FLEET_CA not being used with Fleet Server in container (elastic#26529)
  Add changelog entry for  elastic#26224 (elastic#26531)
  ...
mdelapenya added a commit to mdelapenya/beats that referenced this pull request Jun 30, 2021
* master: (25 commits)
  fix: Force PLATFORMS environment variable when we build Elastic Agent dependencies on arm64 (elastic#26415)
  macos for metricbeat to run in the extended meta-stage (elastic#26573)
  Packaging: add arm7 platform in the main pipeline (elastic#26575)
  [Heartbeat] Skip flakey timer queue test (elastic#26592)
  Update to "read_pipeline" permission (elastic#26465) (elastic#26580)
  API keys do not reflect the need for read_pipeline (elastic#26466) (elastic#26582)
  Add Fleet agent.id to Agent monitoring data (elastic#26548)
  Add kinesis metricset (elastic#25989)
  Refactor of system/memory metricset (elastic#26334)
  Introduce httpcommon package in libbeat (add support for Proxy) (elastic#25219)
  [Filebeat] change multiline configuration in awss3 input to parsers (elastic#25873)
  docs: Hint for the error "Error extracting container id" (elastic#25824)
  [Docs] Fixed metricbeat redis exported field CPU descriptions (elastic#25846) (elastic#26496)
  Update urllib to 1.26.5. (elastic#26380)
  Update golang.org/x/crypto (elastic#26448)
  [Filebeat] Update Fortinet Ingest Pipeline (elastic#24816)
  Move parsers outside of filestream input so others can use them as well (elastic#26541)
  [Filebeat] Fix `threatintel.indicator.url.full` field not populating (elastic#26508)
  [Filebeat] Add network direction processor to Zeek and Suricata modules (elastic#24620)
  Logging code cleanup related to Nomad auto-discovery (elastic#26498)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autodiscovery backport-v7.14.0 Automated backport with mergify Filebeat Filebeat libbeat :Processors Team:Integrations Label for the Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nomad auto-discover uses Debugf incorrectly
4 participants