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

Wire agent config #4486

Merged
merged 7 commits into from
Dec 4, 2020
Merged

Wire agent config #4486

merged 7 commits into from
Dec 4, 2020

Conversation

jalvz
Copy link
Contributor

@jalvz jalvz commented Dec 2, 2020

Motivation/summary

Read configuration from Elastic Agent and use the namespace for the indices

Checklist

I have considered changes for:

How to test these changes

Related issues

@apmmachine
Copy link
Contributor

apmmachine commented Dec 2, 2020

💚 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 #4486 updated

  • Start Time: 2020-12-04T09:55:30.352+0000

  • Duration: 36 min 1 sec

Test stats 🧪

Test Results
Failed 0
Passed 4621
Skipped 139
Total 4760

Steps errors 3

Expand to view the steps failures

Compress

  • Took 0 min 0 sec . View more details on here
  • Description: tar --exclude=coverage-files.tgz -czf coverage-files.tgz coverage

Compress

  • Took 0 min 0 sec . View more details on here
  • Description: tar --exclude=system-tests-linux-files.tgz -czf system-tests-linux-files.tgz system-tests

Test Sync

  • Took 3 min 8 sec . View more details on here
  • Description: ./.ci/scripts/sync.sh

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.

Looks good functionally, just a few minor things I'd like to see tidied up


import "github.com/elastic/beats/v7/libbeat/common"

func NewIntegrationConfig() *IntegrationConfig {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func NewIntegrationConfig() *IntegrationConfig {
func NewIntegrationConfig(rootConfig *common.Config) *IntegrationConfig {

And then do the unpack here, like we do in config.New?

beater/beater.go Outdated
Comment on lines 141 to 146
if integrationConfig.DataStream != nil {
bt.namespace = integrationConfig.DataStream.Namespace
}
if bt.namespace == "" {
bt.namespace = "default"
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we encapsulate this in NewIntegrationConfig (passing in the root config), so there's always a namespace defined when NewIntegrationConfig returns? Then if other code ends up using that function, the logic is in one place.

publish/pub.go Outdated
@@ -81,7 +81,7 @@ var (
// newPublisher creates a new publisher instance.
//MaxCPU new go-routines are started for forwarding events to libbeat.
//Stop must be called to close the beat.Client and free resources.
func NewPublisher(pipeline beat.Pipeline, tracer *apm.Tracer, cfg *PublisherConfig) (*Publisher, error) {
func NewPublisher(pipeline beat.Pipeline, namespace string, tracer *apm.Tracer, cfg *PublisherConfig) (*Publisher, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Add namespace as a field of PublisherConfig?

}

Copy link
Member

Choose a reason for hiding this comment

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

If you add the following (untested), you can remove the TODO above. This addresses the issue I mentioned on Slack, where the data streams config will be defined for the initial static config, but not for the dynamic input coming from Agent:

apmServerCommonConfig.Merge(common.MustNewConfigFrom(`{"apm-server.data_streams.enabled": 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.

Not sure I follow, when agent starts the server it does it with -E apm-server.data_streams.enabled=true, right?

@codecov-io
Copy link

Codecov Report

Merging #4486 (38f43fc) into master (945e483) will decrease coverage by 0.09%.
The diff coverage is 10.00%.

@@            Coverage Diff             @@
##           master    #4486      +/-   ##
==========================================
- Coverage   76.06%   75.96%   -0.10%     
==========================================
  Files         160      161       +1     
  Lines        9775     9790      +15     
==========================================
+ Hits         7435     7437       +2     
- Misses       2340     2353      +13     
Impacted Files Coverage Δ
beater/config/integration.go 0.00% <0.00%> (ø)
publish/pub.go 73.80% <0.00%> (ø)
beater/beater.go 55.92% <14.28%> (-2.29%) ⬇️
processor/otel/consumer.go 93.51% <0.00%> (-0.45%) ⬇️
kibana/connecting_client.go 70.17% <0.00%> (+5.26%) ⬆️

@jalvz jalvz merged commit 6062235 into elastic:master Dec 4, 2020
@jalvz jalvz mentioned this pull request Dec 8, 2020
15 tasks
jalvz added a commit to jalvz/apm-server that referenced this pull request Dec 15, 2020
Read configuration from Elastic Agent and use the namespace for the indices
jalvz added a commit that referenced this pull request Dec 15, 2020
Read configuration from Elastic Agent and use the namespace for the indices
@axw axw self-assigned this Dec 22, 2020
@axw
Copy link
Member

axw commented Dec 22, 2020

Following on from #4228 (comment), I sent a transaction to APM Server and checked that a new "traces" data stream was created with the namespace "default":

GET /_data_stream/traces-*
{
  "data_streams" : [
    {
      "name" : "traces-apm-default",
      "timestamp_field" : {
        "name" : "@timestamp"
      },
      "indices" : [
        {
          "index_name" : ".ds-traces-apm-default-2020.12.22-000001",
          "index_uuid" : "3AuDXYecSVOUbw_JwGDdQw"
        }
      ],
      "generation" : 1,
      "_meta" : {
        "managed_by" : "ingest-manager",
        "managed" : true,
        "package" : {
          "name" : "apm"
        }
      },
      "status" : "YELLOW",
      "template" : "traces-apm",
      "ilm_policy" : "traces",
      "hidden" : false
    }
  ]
}

I then edited the integration to set the namespace to "nondefault", restarted elastic-agent, and send another transaction. A new data stream was created:

GET /_data_stream/traces-*
{
  "data_streams" : [
    {
      "name" : "traces-apm-default",
      "timestamp_field" : {
        "name" : "@timestamp"
      },
      "indices" : [
        {
          "index_name" : ".ds-traces-apm-default-2020.12.22-000001",
          "index_uuid" : "3AuDXYecSVOUbw_JwGDdQw"
        }
      ],
      "generation" : 1,
      "_meta" : {
        "managed_by" : "ingest-manager",
        "managed" : true,
        "package" : {
          "name" : "apm"
        }
      },
      "status" : "YELLOW",
      "template" : "traces-apm",
      "ilm_policy" : "traces",
      "hidden" : false
    },
    {
      "name" : "traces-apm-nondefault",
      "timestamp_field" : {
        "name" : "@timestamp"
      },
      "indices" : [
        {
          "index_name" : ".ds-traces-apm-nondefault-2020.12.22-000001",
          "index_uuid" : "G9c-yRmBT3KR9-MLsu9vuQ"
        }
      ],
      "generation" : 1,
      "_meta" : {
        "managed_by" : "ingest-manager",
        "managed" : true,
        "package" : {
          "name" : "apm"
        }
      },
      "status" : "YELLOW",
      "template" : "traces-apm",
      "ilm_policy" : "traces",
      "hidden" : false
    }
  ]
}

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