Skip to content

feat: ecs event spec - #346

Merged
olegsu merged 2 commits into
elastic:mainfrom
olegsu:ecs-event-spec
Aug 30, 2022
Merged

feat: ecs event spec#346
olegsu merged 2 commits into
elastic:mainfrom
olegsu:ecs-event-spec

Conversation

@olegsu

@olegsu olegsu commented Aug 17, 2022

Copy link
Copy Markdown
Collaborator
@olegsu
olegsu requested a review from a team as a code owner August 17, 2022 10:32
@cla-checker-service

cla-checker-service Bot commented Aug 17, 2022

Copy link
Copy Markdown

💚 CLA has been signed

@mergify

mergify Bot commented Aug 17, 2022

Copy link
Copy Markdown
Contributor

This pull request does not have a backport label. Could you fix it @olegsu? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit
    NOTE: backport-skip has been added to this pull request.
@mergify mergify Bot assigned olegsu Aug 17, 2022
@mergify mergify Bot mentioned this pull request Aug 17, 2022
@olegsu
olegsu force-pushed the ecs-event-spec branch 4 times, most recently from 054ced0 to 96ef744 Compare August 17, 2022 11:49

@eyalkraft eyalkraft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good job!
small changes required

Comment thread resources/ecs/event.go Outdated

// Event According to https://www.elastic.co/guide/en/ecs/current/ecs-event.html
// event.ingested property is not part of this struct as the fleet server setting it
type Event struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!
Please make sure we use beat's implementation if possible

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Great, I was looking this one

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@eyalkraft the ecs.Event like other ECS types is using only ecs custom struct type.
So the final document looks like this (with uppercase keys)
If you are familiar with the decoder of those ecs tags it would be great.
Otherwise, I suggest keeping the previous, custom sturct and to handle this later.
image

Comment thread resources/fetchersManager/data.go Outdated
@@ -84,7 +85,7 @@ func (d *Data) fetchIteration(ctx context.Context) {
start := time.Now()

cycleId, _ := uuid.NewV4()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are some cycleId leftovers

Comment thread transformer/events_creator.go Outdated
ID: id.String(),
Kind: ecs.KindState,
Sequence: seq,
Outcome: ecs.OutcomeSuccess,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I now wonder If we should also send the failed evaluations as failed events...
I'll comment in the issue

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sounds as a good KPI

Comment thread evaluator/opa_test.go
"github.com/stretchr/testify/assert"
)

func TestOpaEvaluator_decode(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

Comment thread evaluator/opa.go
}

err = decoder.Decode(result)
opaResult.Metadata.CreatedAt = now()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since it's only used once that could maybe be

Suggested change
opaResult.Metadata.CreatedAt = now()
opaResult.Metadata.CreatedAt = time.Now().UTC()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The reason for this was to have the ability to overwrite the value to a predictable one in the test

@eyalkraft eyalkraft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

@olegsu

olegsu commented Aug 18, 2022

Copy link
Copy Markdown
Collaborator Author

A quick update following #346 (comment)

To support the ecs struct tags properly, we need to add to all the structs that we use ecs tag. Later, implement the decoder that knows how to convert the struct into mapstr.M as required in the beat.Event (https://github.com/elastic/beats/blob/main/libbeat/beat/event.go#L44)
Similar to what is been done by packetbeat

The migration to ecs tags can be done just after this will be merged as it mostly a refactor without any changes in terms of the structure of the outgoing event.

To close, the Event struct that was removed will be part of this PR

@eyalkraft @uri-weisman

Slack

@olegsu
olegsu force-pushed the ecs-event-spec branch 3 times, most recently from 080b0f3 to 2a2dddc Compare August 22, 2022 04:51
@eyalkraft

Copy link
Copy Markdown
Contributor

Thanks @olegsu! This PR looks great.
Can you please open a follow-up ticket regarding using the ecs tag and implementing the decoder, including the information from your last comment and including what is the motivation for us to do so? (pros vs cons)
Thanks!

@olegsu
olegsu force-pushed the ecs-event-spec branch 3 times, most recently from cf6480f to 77c6934 Compare August 28, 2022 07:13
@olegsu
olegsu requested a review from a team as a code owner August 28, 2022 07:13
@olegsu
olegsu requested a review from gurevichdmitry August 28, 2022 07:13

@gurevichdmitry gurevichdmitry left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@olegsu, utils.py file approved. LGTM

@mergify

mergify Bot commented Aug 29, 2022

Copy link
Copy Markdown
Contributor

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b ecs-event-spec upstream/ecs-event-spec
git merge upstream/main
git push upstream ecs-event-spec
olegsu added 2 commits August 30, 2022 10:37
https://www.elastic.co/guide/en/ecs/current/ecs-event.html
Signed-off-by: Oleg Sucharevich <oleg.sucharevich@elastic.co>
Signed-off-by: Oleg Sucharevich <oleg.sucharevich@elastic.co>
@github-actions

Copy link
Copy Markdown
@olegsu
olegsu merged commit 6af24a7 into elastic:main Aug 30, 2022
@olegsu

olegsu commented Sep 11, 2022

Copy link
Copy Markdown
Collaborator Author

Thanks @olegsu! This PR looks great. Can you please open a follow-up ticket regarding using the ecs tag and implementing the decoder, including the information from your last comment and including what is the motivation for us to do so? (pros vs cons) Thanks!

Done @eyalkraft
https://github.com/orgs/elastic/projects/705/views/47?filterQuery=iteration%3A%22sprint+15%22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants