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

Make cloud.id work for monitoring Elasticsearch reporter #15254

Merged
merged 17 commits into from
Jan 6, 2020

Conversation

ycombinator
Copy link
Contributor

@ycombinator ycombinator commented Dec 25, 2019

Resolves #14399.

This PR allows users to specify two new optional settings:

  • monitoring.cloud.id. If specified, it's value will be decoded and used to override monitoring.elasticsearch.hosts.
  • monitoring.cloud.auth. If specified, it's value will be decoded and used to override monitoring.elasticsearch.username and monitoring.elasticsearch.password.

Before this PR

The monitoring.elasticsearch.* settings were determined using the following precedence order:

  • Is monitoring.elasticsearch.* set?
    • Yes: monitoring.elasticsearch.* will be used.
    • No:
      • Is cloud.* set?
        • Yes: cloud.* will be decoded and used to set elasticsearch.* and monitoring.elasticsearch.*.
        • No:
          • Is elasticsearch.* set?
            • Yes: It will be used to set monitoring.elasticsearch.*.
            • No: No monitoring.elasticsearch.* will be set.

After this PR

The monitoring.elasticsearch.* settings will be determined using the following precedence order (new settings and related precedence rules are bolded):

  • Is monitoring.cloud.* set?
    • Yes: monitoring.cloud.* will be decoded and used to override monitoring.elasticsearch.*.
    • No:
      • Is monitoring.elasticsearch.* set?
        • Yes: monitoring.elasticsearch.* will be used.
        • No:
          • Is cloud.* set?
            • Yes: cloud.* will be decoded and used to set elasticsearch.* and monitoring.elasticsearch.*.
            • No:
              • Is elasticsearch.* set?
                • Yes: It will be used to set monitoring.elasticsearch.*.
                • No: No monitoring.elasticsearch.* will be set.

Important Note

The enhancement introduced by this PR has no impact on the deprecated xpack.monitoring.* settings. That is, even with this PR, users won't be able to set xpack.monitoring.cloud.* nor will setting monitoring.cloud.* cause xpack.monitoring.elasticsearch.* to be set or overridden.

Testing this PR

  1. Create a deployment on cloud.elastic.co.
  2. Grab the values for cloud.id and cloud.auth from your deployment.
  3. Build a Beat, say Filebeat, with this PR.
    cd $GOPATH/src/github.com/elastic/beats/filebeat
    mage build
    
  4. Configure your beat with the following monitoring settings:
    monitoring:
      enabled: true
      cloud:
        id: YOUR_CLOUD_ID
        auth: YOUR_CLOUD_AUTH
  5. Make any other necessary configuration for the Beat to ingest some data.
  6. Start the Beat.
  7. Verify in your Cloud deployment's ES cluster that there's .monitoring-beats-* indices and documents in those indices.

libbeat/monitoring/cloudid.go Show resolved Hide resolved
libbeat/monitoring/cloudid.go Outdated Show resolved Hide resolved
libbeat/monitoring/cloudid.go Outdated Show resolved Hide resolved
libbeat/monitoring/cloudid.go Outdated Show resolved Hide resolved
libbeat/monitoring/cloudid.go Outdated Show resolved Hide resolved
libbeat/monitoring/cloudid.go Outdated Show resolved Hide resolved
@elasticmachine
Copy link
Collaborator

Pinging @elastic/stack-monitoring (Stack monitoring)

// decodeCloudID decodes the cloud.id into elasticsearch-URL and kibana-URL
func decodeCloudID(cloudID string) (string, string, error) {
// DecodeCloudID decodes the cloud.id into elasticsearch-URL and kibana-URL
func DecodeCloudID(cloudID string) (string, string, error) {
Copy link

Choose a reason for hiding this comment

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

If we start to expose this function, we should also try to make it more clear what is returned. Either by introducing a new type or naming the return values. I'd prefer a struct like:

type CloudIDDetails struct {
  ElasticsearchURL string
  KibanaURL string
}

// decodeCloudAuth splits the cloud.auth into username and password.
func decodeCloudAuth(cloudAuth string) (string, string, error) {
// DecodeCloudAuth splits the cloud.auth into username and password.
func DecodeCloudAuth(cloudAuth string) (string, string, error) {
Copy link

@urso urso Dec 27, 2019

Choose a reason for hiding this comment

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

Hm... I guess these details are used for Elasticsearch and Kibana? We might want to add those to the struct as well?

alternatively one can hide the parsing behind a structure (lazy or eager parsing is possible)

type CloudID struct {
  id string
  username, password, esURL, kibURL string
}

func NewCloudID(id string) (*CloudID, error) {
  // parse id and fill structure
}

func (cid *CloudID) ID() string {
  return cid
}

func (cid *CloudID) Username() string {
  return cid.username
}

...

err := monitoring.OverrideWithCloudSettings(monitoringCfg)
if err != nil {
return nil, err
}
Copy link

Choose a reason for hiding this comment

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

If possible I'd prefer to not overwrite settings in a *common.Config. It's an anti-pattern we unfortunately use throughout Beats.

e.g. based on the CloudID structure one could introduce an interface type like:

type StackDetails interface {
  Username() string
  Password() string
  ElasticsearchURL() string
}

Then it's a matter of constructing the right object, instead of overwriting a shared configuration object that might already be applied partially.

I think for this PR it is ok as done, as monitoring settings are quite 'local'. But in general when dealing with configs we should prefer construction over modifications (treat *common.Config as readonly). It is a common issue that we sometimes did unpack a configuration before it has been modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++ to not overwriting settings, I was only doing it to be consistent with how we are handling the global cloud.id and cloud.auth settings.

@ycombinator
Copy link
Contributor Author

ycombinator commented Dec 27, 2019

@urso I like your suggestions to a) hide the cloud ID functionality behind a struct and methods and b) not mutate the shared*common.Config object directly. Much of the "bad" implementation comes from mirroring the existing implementation for parsing the global cloud.id and cloud.auth settings.

I'm going to cleanup the existing implementation in a separate refactoring-only PR first, and then use the cleaned up implementation in this PR.

@urso
Copy link

urso commented Dec 27, 2019

I'm going to cleanup the existing implementation in a separate refactoring-only PR first, and then use the cleaned up implementation in this PR.

I think we can progress here and cleanup both locations later at the same time. Amount of work shouldn't be much different, but no need to hold back this enhancement.

libbeat/cloudid/cloudid.go Show resolved Hide resolved
libbeat/cloudid/cloudid.go Show resolved Hide resolved
libbeat/cloudid/cloudid.go Show resolved Hide resolved
libbeat/cloudid/cloudid.go Show resolved Hide resolved
libbeat/cloudid/cloudid.go Show resolved Hide resolved
libbeat/cloudid/cloudid.go Show resolved Hide resolved
@ycombinator
Copy link
Contributor Author

@urso This PR is ready for your review again. I think any further cleanup (to prevent overwriting settings) will not be trivial so we should defer it to a future PR. WDYT?

libbeat/monitoring/cloudid.go Outdated Show resolved Hide resolved
@ycombinator
Copy link
Contributor Author

@urso I've addressed your latest round of feedback. This PR is ready for your review again. Thanks!

@ycombinator ycombinator requested a review from urso January 6, 2020 09:46
@ycombinator
Copy link
Contributor Author

jenkins, test this

@ycombinator ycombinator merged commit 721472f into elastic:master Jan 6, 2020
@ycombinator ycombinator deleted the lb-mon-cloud-id branch January 6, 2020 18:56
@ycombinator ycombinator removed the needs_backport PR is waiting to be backported to other branches. label Jan 6, 2020
ycombinator added a commit that referenced this pull request Jan 7, 2020
…5343)

* Refactoring: exporting functions needed from monitoring package

* Overriding monitoring.elasticsearch.* if monitoring.cloud.* settings are present

* Adding explanatory comment

* Adding unit tests skeleton

* Adding godocs for exported symbols

* Adding CHANGELOG entry

* Fixing type name in godoc

* More godoc fixes

* Fleshing out unit tests

* Adding docs

* Refactoring: make CloudID struct

* Adding godoc

* Wrap decoding errors

* Use getter methods instead of unexported fields

* Use single quotes for quoting strings in YAML

* Using errors.Wrap instead of custom error type

* Fixing formatting
@ycombinator ycombinator added the test-plan Add this PR to be manual test plan label Jan 9, 2020
@kvch kvch self-assigned this Jan 17, 2020
@kvch kvch added the test-plan-regression Manually testing this PR found a regression label Jan 17, 2020
@kvch
Copy link
Contributor

kvch commented Jan 17, 2020

Opened issue: #15638

@kvch kvch added test-plan-ok This PR passed manual testing and removed test-plan-regression Manually testing this PR found a regression labels Jan 30, 2020
@andresrc andresrc added the Team:Integrations Label for the Integrations team label Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature:Stack Monitoring libbeat Team:Integrations Label for the Integrations team test-plan Add this PR to be manual test plan test-plan-ok This PR passed manual testing v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make cloud.id work for monitoring Elasticsearch reporter
6 participants