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

model: Align labels field with ECS #6633

Conversation

marclop
Copy link
Contributor

@marclop marclop commented Nov 16, 2021

Motivation/summary

Updates all data streams to use the ecs defined labels for values that
are string or bool, and adds a new field for numeric_labels which
stores all numeric labels as scaled_float, using the scaling_factor
we were using for indexes.

There's a single exception for the metrics-apm.internal data stream,
due to the fact that dynamic is set to strict, which disables the
externally defined ecs labels dynamic ability. For that data stream, the
field is defined as a standard field.

Checklist

How to test these changes

  1. Install the integration.
  2. Ingest some data with both numeric, string and bool labels.
  3. Verify that the string and bool labels are under the labels field
  4. Verify that numeric (floats and ints) are stored under numeric_labels.

Related issues

Closes #3873

@marclop marclop added enhancement v8.0.0 backport-8.0 Automated backport with mergify labels Nov 16, 2021
@marclop marclop changed the title model: Align labels with ECS model: Align labels field with ECS Nov 16, 2021
@apmmachine
Copy link
Contributor

apmmachine commented Nov 16, 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 preview

Expand to view the summary

Build stats

  • Start Time: 2021-11-18T03:07:12.441+0000

  • Duration: 49 min 22 sec

  • Commit: 453007c

Test stats 🧪

Test Results
Failed 0
Passed 5638
Skipped 19
Total 5657

🤖 GitHub comments

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

  • /test : Re-trigger the build.

  • /hey-apm : Run the hey-apm benchmark.

  • /package : Generate and publish the docker images.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

Updates all data streams to use the ecs defined `labels` for values that
are `string` or `bool`, and adds a new field for `numeric_labels` which
stores all numeric labels as `scaled_float`, using the `scaling_factor`
we were using for indexes.

There's a single exception for the `metrics-apm.internal` data stream,
due to the fact that `dynamic` is set to `strict`, which disables the
externally defined ecs labels dynamic ability. For that data stream, the
field is defined as a standard field.

Signed-off-by: Marc Lopez Rubio <[email protected]>
Signed-off-by: Marc Lopez Rubio <[email protected]>
Signed-off-by: Marc Lopez Rubio <[email protected]>
@marclop marclop force-pushed the f/labels-split-into-string-and-numeric-ecs-compatible branch from ec3cbd7 to 8117968 Compare November 16, 2021 12:29
@marclop marclop requested a review from a team November 16, 2021 13:51
@marclop marclop marked this pull request as ready for review November 16, 2021 13:51
@mergify
Copy link
Contributor

mergify bot commented Nov 16, 2021

This pull request is now in conflicts. Could you fix it @marclop? 🙏
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 f/labels-split-into-string-and-numeric-ecs-compatible upstream/f/labels-split-into-string-and-numeric-ecs-compatible
git merge upstream/master
git push upstream f/labels-split-into-string-and-numeric-ecs-compatible

Comment on lines 79 to 80
- external: ecs
name: labels
Copy link
Member

Choose a reason for hiding this comment

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

I think we have to define the field everywhere, and not use references. This data stream doesn't use strict mapping, but it does set dynamic: false at the top level meaning labels won't be indexed.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it's worth opening an issue on package-spec to allow specifying the dynamic property for external fields? Seems to me it should be reasonable to specify this:

- external: ecs
  name: labels
  dynamic: true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right, I missed that they won't be indexed if we just reference the ecs fields like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

model/apmevent.go Outdated Show resolved Hide resolved
model/labels.go Outdated Show resolved Hide resolved
Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

Just a few minor things, othewise LGTM.

I'd like to follow up on this by changing the Labels and NumericLabels fields to be more type-safe. Either

type APMEvent struct {
    Labels map[string][]string
    NumericLabels map[string][]float64
}

Or

// Labels/NumericLabels values are either always stored as arrays,
// or store as an array iff len > 1
type APMEvent struct {
    Labels map[string]LabelValue
    NumericLabels map[string]NumericLabelValue
}

type LabelValue struct {
    Value string
    Values []string // If non-nil, use this; otherwise use Value
}

type NumericLabelValue struct {
    Value float64
    Values []float64 // If non-nil, use this; otherwise use Value
}

But to be clear, let's do that in a followup.

model/modeldecoder/modeldecoderutil/labels.go Outdated Show resolved Hide resolved
processor/otel/metadata.go Show resolved Hide resolved
processor/otel/metadata.go Outdated Show resolved Hide resolved
Signed-off-by: Marc Lopez Rubio <[email protected]>
Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

@marclop marclop enabled auto-merge (squash) November 18, 2021 03:11
@marclop marclop merged commit 8be9227 into elastic:master Nov 18, 2021
@marclop marclop deleted the f/labels-split-into-string-and-numeric-ecs-compatible branch November 18, 2021 03:56
mergify bot pushed a commit that referenced this pull request Nov 18, 2021
Updates all data streams to use the ecs defined `labels` for values that
are `string` or `bool`, and adds a new field for `numeric_labels` which
stores all numeric labels as `scaled_float`, using the `scaling_factor`
we were using for indexes.

Signed-off-by: Marc Lopez Rubio <[email protected]>
(cherry picked from commit 8be9227)
marclop pushed a commit that referenced this pull request Nov 18, 2021
Updates all data streams to use the ecs defined `labels` for values that
are `string` or `bool`, and adds a new field for `numeric_labels` which
stores all numeric labels as `scaled_float`, using the `scaling_factor`
we were using for indexes.

Signed-off-by: Marc Lopez Rubio <[email protected]>
(cherry picked from commit 8be9227)
@stuartnelson3
Copy link
Contributor

confirmed with 50edba1

package main

import (
	"fmt"
	"os"

	"go.elastic.co/apm"
)

func main() {
	version := "undefined"
	if len(os.Args) > 1 {
		version = os.Args[1]
	}
	name := fmt.Sprintf("apm-server-%s", version)
	tx := apm.DefaultTracer.StartTransaction(name, "type")
	tx.Context.SetLabel("enabled", true)
	tx.Context.SetLabel("string", "string")
	tx.Context.SetLabel("numbers", 1234.56)
	tx.End()
	apm.DefaultTracer.Flush(nil)
	fmt.Printf("%s: %+v\n", name, apm.DefaultTracer.Stats())
}

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.

model: align labels with ECS
4 participants