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

Introduce a configurable default service environment #4861

Merged
merged 8 commits into from
Feb 26, 2021

Conversation

axw
Copy link
Member

@axw axw commented Feb 22, 2021

Motivation/summary

Introduce a configurable default service environment. This is recorded in events which have no service environment defined, and is used in agent central config when no environment is specified. There is no default default, so there is no change in behaviour unless the configuration is set.

Checklist

How to test these changes

  1. Run apm-server configured with apm-server.default_service_environment: abc123
  2. Send some transactions with environment set (to something else); the environment should be kept intact, and not overridden
  3. Send some transactions with environment unset; the default environment should be set
  4. Enable transaction aggregation, ensure all metrics have an environment associated
  5. Enable central config, ensure that an agent with no environment set picks up config for the environment "abc123"

Related issues

Closes #4664.

@axw axw changed the title Processor interface Introduce a configurable default service environment Feb 22, 2021
@apmmachine
Copy link
Contributor

apmmachine commented Feb 22, 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: Pull request #4861 updated

  • Start Time: 2021-02-26T00:20:36.059+0000

  • Duration: 58 min 23 sec

  • Commit: 19b5477

Test stats 🧪

Test Results
Failed 0
Passed 4738
Skipped 118
Total 4856

Trends 🧪

Image of Build Times

Image of Tests

@axw axw force-pushed the processor-interface branch from 7f8c1c6 to 7cb3eab Compare February 23, 2021 03:37
@codecov-io
Copy link

codecov-io commented Feb 23, 2021

Codecov Report

Merging #4861 (1f2445e) into master (24b6886) will decrease coverage by 0.05%.
The diff coverage is 62.85%.

@@            Coverage Diff             @@
##           master    #4861      +/-   ##
==========================================
- Coverage   76.77%   76.71%   -0.06%     
==========================================
  Files         166      167       +1     
  Lines       10230    10265      +35     
==========================================
+ Hits         7854     7875      +21     
- Misses       2376     2390      +14     
Impacted Files Coverage Δ
beater/config/config.go 68.85% <ø> (ø)
x-pack/apm-server/main.go 0.00% <ø> (ø)
beater/beater.go 67.93% <27.77%> (-2.66%) ⬇️
beater/api/config/agent/handler.go 95.04% <100.00%> (+0.08%) ⬆️
beater/api/mux.go 91.83% <100.00%> (ø)
model/modelprocessor/environment.go 100.00% <100.00%> (ø)

@axw axw force-pushed the processor-interface branch from 7cb3eab to 8a37add Compare February 23, 2021 05:08
@axw axw force-pushed the processor-interface branch from 8a37add to 5d10a73 Compare February 23, 2021 05:09
@axw axw marked this pull request as ready for review February 25, 2021 02:50
@axw axw requested a review from a team February 25, 2021 05:02
case *model.Error:
if t.Metadata.Service.Environment == "" {
t.Metadata.Service.Environment = s.DefaultServiceEnvironment
}
Copy link
Contributor

Choose a reason for hiding this comment

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

should be exhaustive here? i prefer prefer that something fails loudly if eg. we add a new event type

Copy link
Member Author

@axw axw Feb 25, 2021

Choose a reason for hiding this comment

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

Yeah, good point - it should be and it's not. I forgot to cover profiles.

I could make this panic if it sees a type it doesn't know about, but I'd rather not have this feature cause such a catastrophic failure in case test coverage isn't quite adequate (which evidently it's not).

I think ideally we wouldn't be dealing with a "Transformable" interface here at all, but instead pass around the concrete model.Batch struct type. Then the processor can just iterate over the bits it cares about. We could have tests for processors that check the Batch type hasn't changed, if necessary.

I'd like to defer that, and just add Profile in for now. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good, thanks (create an issue, maybe?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened #4877

@@ -62,6 +62,12 @@ policy_templates:
required: false
description: Enter as <Id>:<API Key>
show_user: true
- name: default_service_environment
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure about this, shouldn't we use the namespace instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd prefer to keep them separate for now, so users have the flexibility to have two dimensions:

  • a namespace is a collection of APM services, e.g. split by business applications, business unit, etc.
  • typical environments for those services: production, testing, development

Copy link
Contributor

Choose a reason for hiding this comment

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

ah ok, that was news to me 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Please also update the README accordingly, it refers to using namespace for environment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just to be clear, setting namespace to environment is still a reasonable choice. Perhaps we should just soften the language a little, to point it out as an option but not necessarily state that it is recommended.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, that's what I meant, the additional use case for namespace tha you explained above, should be added to the README.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -62,6 +62,12 @@ policy_templates:
required: false
description: Enter as <Id>:<API Key>
show_user: true
- name: default_service_environment
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also update the README accordingly, it refers to using namespace for environment.

@simitt
Copy link
Contributor

simitt commented Feb 25, 2021

Apologies - I just approved, but didn't see your ongoing conversation.

@jalvz
Copy link
Contributor

jalvz commented Feb 25, 2021

One more question, sorry for delay: this intended for 7.13, I suppose?

@axw
Copy link
Member Author

axw commented Feb 26, 2021

@jalvz yes, now labelled accordingly

@axw axw merged commit 992699d into elastic:master Feb 26, 2021
@axw axw deleted the processor-interface branch February 26, 2021 01:20
@jalvz
Copy link
Contributor

jalvz commented Feb 26, 2021

@jalvz yes, now labelled accordingly

I was going to say that in that case better hold onto merging to allow for package changes for 7.12 😬

@axw
Copy link
Member Author

axw commented Feb 27, 2021

@jalvz I suppose if that's needed we should be working off the 7.12 branch instead. We'll eventually version the package with the stack right? So bump the version on master/7.x to 0.2.0 and have 0.1.0 on 7.12?

@axw axw removed the test-plan label Mar 8, 2021
axw added a commit to axw/apm-server that referenced this pull request Mar 25, 2021
* Add transform.Processor interface

* beater: add default service environment

* model/modelprocessor: update PprofProfile too

* apmpackage: update README about namespace
# Conflicts:
#	apmpackage/apm/0.1.0/_dev/docs/README.template.md
#	apmpackage/apm/0.1.0/docs/README.md
#	apmpackage/apm/0.1.0/manifest.yml
#	changelogs/head.asciidoc
axw added a commit that referenced this pull request Mar 25, 2021
* Add transform.Processor interface

* beater: add default service environment

* model/modelprocessor: update PprofProfile too

* apmpackage: update README about namespace
# Conflicts:
#	apmpackage/apm/0.1.0/_dev/docs/README.template.md
#	apmpackage/apm/0.1.0/docs/README.md
#	apmpackage/apm/0.1.0/manifest.yml
#	changelogs/head.asciidoc
mergify bot pushed a commit that referenced this pull request Apr 27, 2021
* Add transform.Processor interface

* beater: add default service environment

* model/modelprocessor: update PprofProfile too

* apmpackage: update README about namespace

(cherry picked from commit 992699d)

# Conflicts:
#	apmpackage/apm/0.1.0/manifest.yml
#	apmpackage/apm/0.2.0/README.template.md
#	apmpackage/apm/0.2.0/docs/README.md
#	beater/api/config/agent/handler_test.go
#	beater/beater.go
#	beater/config/config.go
#	changelogs/head.asciidoc
#	model/modelprocessor/environment.go
#	model/modelprocessor/environment_test.go
#	transform/transform.go
#	x-pack/apm-server/main.go
@sorenlouv
Copy link
Member

@axw Are there any plans to enable the default service environment by default? In APM UI we are planning to remove the "all" option as well as the "no environment" option. If we do that and users have data without environment it won't show up anymore.

@axw
Copy link
Member Author

axw commented Feb 11, 2022

@sqren no plans at the moment. I recall we discussed this (taking away "all" and "none") in the past, and decided that it wasn't doable at the time. I think maybe because of backwards compatibility? What are we going to do for existing data?

@sorenlouv
Copy link
Member

I recall we discussed this (taking away "all" and "none") in the past, and decided that it wasn't doable at the time. I think maybe because of backwards compatibility? What are we going to do for existing data?

Yes, removing them now can be seen as a breaking change. Which is why I'd like to add a default environment asap so we can do it in ~18 months time (or whatever our data guarantees for APM data is).

We could add a migration script that updates documents to ensure they have an environment. But it requires a re-index of all data so I'm not sure how feasible it is.

@simitt
Copy link
Contributor

simitt commented Feb 11, 2022

@sqren can you create an issue for this so we can continue the discussion, including what the default env should be set to? I am not certain setting a default on the server would be more meaningful than having a none or all in the UI.

@sorenlouv
Copy link
Member

Should I re-open https://github.com/elastic/observability-dev/issues/1118 since it already contains all the background?

@axw
Copy link
Member Author

axw commented Feb 14, 2022

@sqren I think reopen #4468, with anything that's changed since it was closed.

@codecov-commenter
Copy link

codecov-commenter commented Oct 11, 2024

Codecov Report

Attention: Patch coverage is 65.78947% with 13 lines in your changes missing coverage. Please review.

Project coverage is 76.53%. Comparing base (acc9d81) to head (19b5477).

Files with missing lines Patch % Lines
beater/beater.go 27.77% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4861      +/-   ##
==========================================
- Coverage   76.58%   76.53%   -0.06%     
==========================================
  Files         166      167       +1     
  Lines       10118    10156      +38     
==========================================
+ Hits         7749     7773      +24     
- Misses       2369     2383      +14     
Files with missing lines Coverage Δ
beater/api/config/agent/handler.go 95.04% <100.00%> (+0.08%) ⬆️
beater/api/mux.go 91.83% <100.00%> (ø)
beater/config/config.go 68.85% <ø> (ø)
model/modelprocessor/environment.go 100.00% <100.00%> (ø)
x-pack/apm-server/main.go 0.00% <ø> (ø)
beater/beater.go 67.93% <27.77%> (-2.66%) ⬇️

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.

Define a default environment to record on agent data
7 participants