-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Conversation
Pinging @elastic/stack-monitoring (Stack monitoring) |
libbeat/cloudid/cloudid.go
Outdated
// 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) { |
There was a problem hiding this comment.
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
}
libbeat/cloudid/cloudid.go
Outdated
// 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) { |
There was a problem hiding this comment.
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 | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@urso I like your suggestions to a) hide the cloud ID functionality behind a struct and methods and b) not mutate the shared 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. |
@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/docs/monitoring/monitoring-internal-collection.asciidoc
Outdated
Show resolved
Hide resolved
c619fec
to
8a4c878
Compare
8a4c878
to
f94d498
Compare
@urso I've addressed your latest round of feedback. This PR is ready for your review again. Thanks! |
jenkins, test this |
…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
Opened issue: #15638 |
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 overridemonitoring.elasticsearch.hosts
.monitoring.cloud.auth
. If specified, it's value will be decoded and used to overridemonitoring.elasticsearch.username
andmonitoring.elasticsearch.password
.Before this PR
The
monitoring.elasticsearch.*
settings were determined using the following precedence order:monitoring.elasticsearch.*
set?monitoring.elasticsearch.*
will be used.cloud.*
set?cloud.*
will be decoded and used to setelasticsearch.*
andmonitoring.elasticsearch.*
.elasticsearch.*
set?monitoring.elasticsearch.*
.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):monitoring.cloud.*
set?monitoring.cloud.*
will be decoded and used to overridemonitoring.elasticsearch.*
.monitoring.elasticsearch.*
set?monitoring.elasticsearch.*
will be used.cloud.*
set?cloud.*
will be decoded and used to setelasticsearch.*
andmonitoring.elasticsearch.*
.elasticsearch.*
set?monitoring.elasticsearch.*
.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 setxpack.monitoring.cloud.*
nor will settingmonitoring.cloud.*
causexpack.monitoring.elasticsearch.*
to be set or overridden.Testing this PR
cloud.id
andcloud.auth
from your deployment..monitoring-beats-*
indices and documents in those indices.