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

[ACM] Agent remote configuration management - Main functionality #2095

Closed
wants to merge 15 commits into from

Conversation

jalvz
Copy link
Contributor

@jalvz jalvz commented Apr 11, 2019

  • needs changelog
  • needs tests
  • needs feature docs
  • new Kibana config to add in yml file and docs
  • needs sync

Notes

  • Service environment is optional, and treated like any other value (i.e. a service is unequivocally identified by its name). This is the lowest common denominator, as an agent can always send an extra request for a default:
if GET config?service.name=X&service.environment=Z == 404
then GET config?service.name=X

ofc we can introduce an option to save the extra round trip.

Steps to test

  1. Checkout [APM] Central configuration management kibana#36031, and start Elasticsearch and Kibana.

  2. Create the CM index with defined mapping:

PUT .apm-cm
{
  "mappings": {
    "properties": {
      "service": {
        "properties": {
          "environment": {
            "type": "keyword",
            "ignore_above": 1024
          },
          "name": {
            "type": "keyword",
            "ignore_above": 1024
          }
        }
      },
      "settings": {
        "properties": {
          "sample_rate": {
            "type": "float"
          }
        }
      },
      "timestamp": {
        "properties": {
          "us": {
            "type": "long"
          }
        }
      }
    }
  }
}
  1. Index some config docs

PUT .apm-cm/_doc/1
{
    "service": { 
      "name": "opbeans-lisp",
      "environment": "lambda"
    },
    "@timestamp" : "2019-03-01T12:12:12",
    "settings": {
      "sampling_rate": 0.1
    }
}

PUT .apm-cm/_doc/2
{
    "service": { 
      "name": "opbeans-fortran",
      "environment": "rocket-launchpad"
    },
    "@timestamp" : "2019-04-01T12:12:12",
    "settings": {
      "sampling_rate": 0.4
    }
}

PUT .apm-cm/_doc/3
{
    "service": { 
      "name": "opbeans-fortran",
      "environment": "rocket-launchpad"
    },
    "@timestamp" : "2019-07-01T12:12:12",
    "settings": {
      "sampling_rate": 0.7
    }
}

PUT .apm-cm/_doc/4
{
    "service": { 
      "name": "opbeans-fortran",
      "environment": "testbed"
    },
    "@timestamp" : "2019-10-01T12:12:12",
    "settings": {
      "sampling_rate": 1.0
    }
}

PUT .apm-cm/_doc/5
{
    "service": { 
      "name": "opbeans-fortran"
    },
    "@timestamp" : "2019-12-01T12:12:12",
    "settings": {
      "sampling_rate": 0.12
    }
}

Alternatively, create a config directly in the UI by visiting /app/apm#/settings/new.
You should have created some transactions first.

  1. Start APM Server with -E apm-server.kibana.enabled -E apm-server.kibana.path properties set and send requests to the config endpoint:
    curl http://localhost:8200/config?service.name=apm-agent-js
{
  "sampling_rate": "0.4"
}

@jalvz
Copy link
Contributor Author

jalvz commented Apr 11, 2019

make check-full fails with "struct field tag json:settings not compatible with reflect.StructTag.Get: bad syntax for struct tag value", which I have no clue what is about.

branch compiles and runs fine otherwise

@jalvz
Copy link
Contributor Author

jalvz commented Apr 11, 2019

@simitt @graphaelli it would be great if you can have a look

@graphaelli
Copy link
Member

Took a look and the api and response make sense to me

@jalvz jalvz force-pushed the cm-poc branch 3 times, most recently from ba0cd64 to 3900229 Compare May 24, 2019 11:37
@jalvz jalvz changed the title Proof of concept for agent remote configuration Agent remote configuration main functionality May 24, 2019
@jalvz jalvz changed the title Agent remote configuration main functionality [ACM] Agent remote configuration management - Main functionality May 24, 2019
@jalvz jalvz added the feature label May 24, 2019
@jalvz jalvz added this to the 7.3 milestone May 24, 2019
@jalvz jalvz force-pushed the cm-poc branch 5 times, most recently from aa792c2 to fb27508 Compare June 4, 2019 14:48
@jalvz
Copy link
Contributor Author

jalvz commented Jun 4, 2019

@graphaelli is there something missing/wrong here preventing merge, other than golint errors?

@graphaelli
Copy link
Member

I expected we were going to settle on the storage format before merging

@jalvz
Copy link
Contributor Author

jalvz commented Jun 6, 2019

Worst case I would just have to remove this function: https://github.com/elastic/apm-server/pull/2095/files#diff-b6b7a562b4bbb8af1d07c8eaf1fda8b0R41, which is trivial (revert 5d3a467). Or am I missing something else?

I'd really avoid PRs open for more than 1 month if possible

Copy link
Contributor

@simitt simitt left a comment

Choose a reason for hiding this comment

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

Great work @jalvz ! I left a couple of comments, most of them are nits.

_meta/beat.yml Outdated Show resolved Hide resolved
_meta/beat.yml Outdated Show resolved Hide resolved
_meta/beat.yml Outdated Show resolved Hide resolved
agentcfg/fetch.go Outdated Show resolved Hide resolved
agentcfg/fetch.go Outdated Show resolved Hide resolved
agentcfg/fetch.go Outdated Show resolved Hide resolved
beater/agent_config_handler.go Show resolved Hide resolved
beater/beater.go Show resolved Hide resolved
beater/route_config.go Outdated Show resolved Hide resolved
beater/agent_config_handler.go Outdated Show resolved Hide resolved
)

var (
endpoint = "/api/apm/settings/cm/search"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this could be a const

agentcfg/model.go Show resolved Hide resolved
agentcfg/model.go Show resolved Hide resolved
beater/config.go Outdated
@@ -258,6 +259,7 @@ func defaultConfig(beatVersion string) *Config {
filepath.Join("ingest", "pipeline", "definition.json")),
}},
},
Mode: ModeProduction,
Mode: ModeProduction,
Kibana: nil,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you setting a nil default?

Copy link
Contributor Author

@jalvz jalvz Jun 14, 2019

Choose a reason for hiding this comment

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

Because a default of common.Config() would imply enabled=true.
That means that after upgrading, users would be welcome with a new requirement (Kibana) or an error in the logs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. I'd be more explicit about it by either setting common.NewConfigFrom(`enabled: false`) or adding a dedicated test to the config_test.go checking that Kibana.Enabled() == false. Otherwise it could easily happen that this gets removed in the future without anything failing.

@@ -183,6 +183,56 @@ apm-server:
#ilm:
#enabled: false

#kibana:
Copy link
Contributor

Choose a reason for hiding this comment

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

has there been a discussion around using the existing kibana settings instead of introducing a new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it has been discussed.

This is the same setting, just in a different namespace.

The beats setting is under setup which is not correct in our case; this is not for a setup command.

Also, should we use that, the server would refuse to start if Kibana is not reachable, which is not what we want, and not coherent eg. with Elasticsearch output.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha 👍

beater/config.go Outdated
@@ -258,6 +259,7 @@ func defaultConfig(beatVersion string) *Config {
filepath.Join("ingest", "pipeline", "definition.json")),
}},
},
Mode: ModeProduction,
Mode: ModeProduction,
Kibana: nil,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. I'd be more explicit about it by either setting common.NewConfigFrom(`enabled: false`) or adding a dedicated test to the config_test.go checking that Kibana.Enabled() == false. Otherwise it could easily happen that this gets removed in the future without anything failing.

@@ -176,15 +176,14 @@ func (conn *Connection) Request(method, extraPath string,
return resp.StatusCode, result, retError
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file before merging.

jalvz added a commit to jalvz/apm-server that referenced this pull request Jun 17, 2019
This introduces a new requirement (Kibana) and setting for it, in the apm-server namespace (disabled by default).
It also adds an endpoint /v1/agent/configs for agents to poll configuration, requiring them to be authenticated (except RUM).

Supersedes elastic#2095

More info in elastic/apm#4
@jalvz
Copy link
Contributor Author

jalvz commented Jun 17, 2019

Superseded by #2289

@jalvz jalvz closed this Jun 17, 2019
jalvz added a commit that referenced this pull request Jun 17, 2019
This introduces a new requirement (Kibana) and setting for it, in the apm-server namespace (disabled by default).
It also adds an endpoint /v1/agent/configs for agents to poll configuration, requiring them to be authenticated (except RUM).

Supersedes #2095

More info in elastic/apm#4
jalvz added a commit to jalvz/apm-server that referenced this pull request Jun 28, 2019
This introduces a new requirement (Kibana) and setting for it, in the apm-server namespace (disabled by default).
It also adds an endpoint /v1/agent/configs for agents to poll configuration, requiring them to be authenticated (except RUM).

Supersedes elastic#2095

More info in elastic/apm#4
jalvz added a commit that referenced this pull request Jun 28, 2019
This introduces a new requirement (Kibana) and setting for it, in the apm-server namespace (disabled by default).
It also adds an endpoint /v1/agent/configs for agents to poll configuration, requiring them to be authenticated (except RUM).

Supersedes #2095

More info in elastic/apm#4
@watson watson mentioned this pull request Jul 4, 2019
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants