Skip to content

[system + winlog] Fix mapping for time_created to date #5350

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

Merged
merged 20 commits into from
Feb 23, 2023
Merged

[system + winlog] Fix mapping for time_created to date #5350

merged 20 commits into from
Feb 23, 2023

Conversation

nicpenning
Copy link
Contributor

@nicpenning nicpenning commented Feb 21, 2023

  • Bug

What does this PR do?

This sets the winlog.time_created field (currently keyword) to a date type. Even though that I have no data that has this field any longer (in Winlogbeat or Elastic Agent System or Custom Windows event log integrations), I see that it exists in the sample json files provided in the pipelines directory for testing, so instead of removing it, I am updating to a date as it should be.

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • I have verified that Kibana version constraints are current according to guidelines.

@nicpenning nicpenning requested a review from a team as a code owner February 21, 2023 17:51
@elasticmachine
Copy link

elasticmachine commented Feb 21, 2023

💚 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 preview

Expand to view the summary

Build stats

  • Start Time: 2023-02-23T01:49:52.859+0000

  • Duration: 15 min 25 sec

Test stats 🧪

Test Results
Failed 0
Passed 196
Skipped 0
Total 196

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@nicpenning nicpenning requested a review from a team as a code owner February 21, 2023 17:58
@nicpenning nicpenning changed the title [system] Fix mapping for security datastream time_created to date [system + winlog] Fix mapping for time_created to date Feb 21, 2023
@elasticmachine
Copy link

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

Copy link
Contributor

@efd6 efd6 left a comment

Choose a reason for hiding this comment

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

I'm not sure we can do this safely; in system, if the date processor fails we have a field that may fail ingest and in winlog there is no pipeline, so we have no control of the format of the value in the field and so again risk an ingest failure. The system case could be made more safe, but winlog has no processor by design.

Also, what are the implications for existing installations with a mapping change?

@nicpenning
Copy link
Contributor Author

Today, it seems that this field doesn't exist anyways. In the System System, and Application mappings, this field does not exist so they are not in conflict with the properly mapped Winlogbeat mappings.

Do you have any modern examples with the Elastic Agent and of the System or Custom Windows logs that this field exists?

None the less, the other option is to remove this field mapping entirely.

Right now it is inconsistent between the System Integrations, Windows and Custom Windows integrations.

What would you recommend?

@efd6
Copy link
Contributor

efd6 commented Feb 21, 2023

Thanks, the mapping in winlogbeat supports this change.

I think I'd suggest leaving the winlog integration as you have it; the responsibility I guess lies on the user to provide an appropriate pipeline to handle the data stream. For the system/security it could be made safe by adding an on_failure option to the date processor (and modifying the pipeline on_failure option).

Something like

  - date:
      tag: "time_created_date"
      field: winlog.time_created
      formats:
        - ISO8601
      if: ctx.winlog?.time_created != null
      on_failure:
        - remove:
            field: winlog.time_created
            ignore_failure: true
        - append:
            field: error.message
            value: "fail-{{{ _ingest.on_failure_processor_tag }}}"
        - fail:
            message: "Processor {{ _ingest.on_failure_processor_type }} with tag {{ _ingest.on_failure_processor_tag }} in pipeline {{ _ingest.on_failure_pipeline }} failed with message: {{ _ingest.on_failure_message }}"
on_failure:
  - set:
      field: event.kind
      value: pipeline_error
  - append:
      field: error.message
      value: "{{ _ingest.on_failure_message }}"

Could also consider a rename instead of a remove in the case of a failure.

@nicpenning
Copy link
Contributor Author

I like the fail safe in the pipeline. I am good with adding that.

I am wondering if the sample document came from Splunk or a third party ingestion tool because of the 10k winlogbeat endpoints and many event channels, time_created doesn't appear to exist. We only have about 30 Elastic agents with the reapective integrations but no matches yet. I see the sample doc was from 2019 so there could have been a change in the last 3-4 years for this source.

@nicpenning
Copy link
Contributor Author

I went ahead and adapted your feedback for adjusting the pipeline.

@efd6
Copy link
Contributor

efd6 commented Feb 22, 2023

/test

@@ -61,8 +61,17 @@ processors:
field: winlog.time_created
Copy link
Contributor

Choose a reason for hiding this comment

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

We do need the tag here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I will add it in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

@elasticmachine
Copy link

elasticmachine commented Feb 22, 2023

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (3/3) 💚
Files 100.0% (4/4) 💚
Classes 100.0% (4/4) 💚
Methods 60.976% (50/82) 👍 35.976
Lines 99.535% (2780/2793) 👎 -0.465
Conditionals 100.0% (0/0) 💚

@nicpenning
Copy link
Contributor Author

Corrected, please test.

@nicpenning
Copy link
Contributor Author

/test

field: error.message
value: "fail-{{{ _ingest.on_failure_processor_tag }}}"
- fail:
message: "Processor {{ _ingest.on_failure_processor_type }} with tag {{ _ingest.on_failure_processor_tag }} in pipeline {{ _ingest.on_failure_pipeline }} failed with message: {{ _ingest.on_failure_message }}"
on_failure:
- set:
Copy link
Contributor

@efd6 efd6 Feb 22, 2023

Choose a reason for hiding this comment

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

I just noticed this. Please make this an append, otherwise the fail tag will be lost. Also set the event.kind as shown above.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer that these were set in the global on_failure. This way if we add others in the future, they are already handled.

@nicpenning
Copy link
Contributor Author

How is that?

field: error.message
value: "fail-{{{ _ingest.on_failure_processor_tag }}}"
- fail:
message: "Processor {{ _ingest.on_failure_processor_type }} with tag {{ _ingest.on_failure_processor_tag }} in pipeline {{ _ingest.on_failure_pipeline }} failed with message: {{ _ingest.on_failure_message }}"
on_failure:
- set:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer that these were set in the global on_failure. This way if we add others in the future, they are already handled.

Comment on lines 73 to 76
- set:
field: event.kind
value: pipeline_error
- append:
Copy link
Contributor

@efd6 efd6 Feb 22, 2023

Choose a reason for hiding this comment

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

Please revert eab6083.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't find a way to revert here on github.com so I applied changes to align to what it was before this commit.

Comment on lines 78 to 80
on_failure:
- set:
field: error.message
Copy link
Contributor

Choose a reason for hiding this comment

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

The global on_failure should be

on_failure:
  - set:
      field: event.kind
      value: pipeline_error
  - append:
      field: error.message
      value: "{{ _ingest.on_failure_message }}"

This way local formatting of the failure message is preserved in conjunction with any failure tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do I remove this then?

 - set:
      field: error.message
      value: |-
        Processor "{{ _ingest.on_failure_processor_type }}" with tag "{{ _ingest.on_failure_processor_tag }}" in pipeline "{{ _ingest.on_failure_pipeline }}" failed with message "{{ _ingest.on_failure_message }}"

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep. If you take the suggestion I started with and replace all of the text in the file from the date processor on with that, then you have what we need.

@nicpenning
Copy link
Contributor Author

I think I am getting closer. Sorry this one has been a rough go :D

@nicpenning nicpenning requested review from efd6 and removed request for belimawr and leehinman February 22, 2023 04:12
@nicpenning
Copy link
Contributor Author

Sorry pushing the wrong buttons on my phone. Ready to test?

@efd6
Copy link
Contributor

efd6 commented Feb 22, 2023

Can you amend the global on_failure option to set event.kind and use an append in place of a set for error.message?

@nicpenning
Copy link
Contributor Author

Sorry I forgot to put those back in as intended.

Please give that a go.

Comment on lines 81 to 82
value: |-
Processor "{{ _ingest.on_failure_processor_type }}" with tag "{{ _ingest.on_failure_processor_tag }}" in pipeline "{{ _ingest.on_failure_pipeline }}" failed with message "{{ _ingest.on_failure_message }}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
value: |-
Processor "{{ _ingest.on_failure_processor_type }}" with tag "{{ _ingest.on_failure_processor_tag }}" in pipeline "{{ _ingest.on_failure_pipeline }}" failed with message "{{ _ingest.on_failure_message }}"
value: "{{ _ingest.on_failure_message }}"

The errors are already formatted in the fail processor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood. Updated.

@efd6
Copy link
Contributor

efd6 commented Feb 23, 2023

/test

Copy link
Contributor

@efd6 efd6 left a comment

Choose a reason for hiding this comment

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

Thanks

@nicpenning
Copy link
Contributor Author

You are welcome! Thanks for the help!

@efd6 efd6 merged commit 9c89a60 into elastic:main Feb 23, 2023
@elasticmachine
Copy link

Package system - 1.24.3 containing this change is available at https://epr.elastic.co/search?package=system

@elasticmachine
Copy link

Package winlog - 1.12.2 containing this change is available at https://epr.elastic.co/search?package=winlog

@nicpenning nicpenning deleted the patch-5 branch February 23, 2023 13:03
agithomas pushed a commit to agithomas/integrations that referenced this pull request Mar 20, 2023
agithomas pushed a commit to agithomas/integrations that referenced this pull request Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants