Skip to content

Commit

Permalink
Add the Elasticsearch License in the log (elastic#15834)
Browse files Browse the repository at this point in the history
* Add the ve Elasticsearch License in the log.

When the license callback is executed the license will be show in
the log at info level
  • Loading branch information
ph authored Jan 27, 2020
1 parent e3588da commit 8683c72
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ https://github.com/elastic/beats/compare/v7.5.0...v7.5.1[View commits]

- Fix `proxy_url` option in Elasticsearch output. {pull}14950[14950]
- Fix bug with potential concurrent reads and writes from event.Meta map by Kafka output. {issue}14542[14542] {pull}14568[14568]
- Fix license detection, when a beats successfully connect to Elasticsearch the detected license will be show in the log at info level. {pull}15834[15834]

*Filebeat*

Expand Down
2 changes: 1 addition & 1 deletion x-pack/functionbeat/function/beater/functionbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (bt *Functionbeat) Run(b *beat.Beat) error {
}

if outputName == "elasticsearch" {
licenser.Enforce(logp.NewLogger("license"), b.Info.Name, licenser.BasicAndAboveOrTrial)
licenser.Enforce(b.Info.Name, licenser.BasicAndAboveOrTrial)
}

bt.log.Info("Functionbeat is running")
Expand Down
5 changes: 1 addition & 4 deletions x-pack/libbeat/cmd/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package cmd

import (
"github.com/elastic/beats/libbeat/cmd"
"github.com/elastic/beats/libbeat/logp"

// register central management
"github.com/elastic/beats/x-pack/libbeat/licenser"
Expand All @@ -16,10 +15,8 @@ import (
_ "github.com/elastic/beats/x-pack/libbeat/autodiscover/providers/aws/elb"
)

const licenseDebugK = "license"

// AddXPack extends the given root folder with XPack features
func AddXPack(root *cmd.BeatsRootCmd, name string) {
licenser.Enforce(logp.NewLogger(licenseDebugK), name, licenser.BasicAndAboveOrTrial)
licenser.Enforce(name, licenser.BasicAndAboveOrTrial)
root.AddCommand(genEnrollCmd(name, ""))
}
9 changes: 8 additions & 1 deletion x-pack/libbeat/licenser/es_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ import (
"github.com/elastic/beats/libbeat/outputs/elasticsearch"
)

const licenseDebugK = "license"

// Enforce setups the corresponding callbacks in libbeat to verify the license on the
// remote elasticsearch cluster.
func Enforce(log *logp.Logger, name string, checks ...CheckFunc) {
func Enforce(name string, checks ...CheckFunc) {
name = strings.Title(name)

cb := func(client *elasticsearch.Client) error {
// Logger created earlier than this place are at risk of discarding any log statement.
log := logp.NewLogger(licenseDebugK)

fetcher := NewElasticFetcher(client)
license, err := fetcher.Fetch()

Expand All @@ -42,6 +47,8 @@ func Enforce(log *logp.Logger, name string, checks ...CheckFunc) {
)
}

log.Infof("Elasticsearch license: %s", license.Get())

return nil
}

Expand Down

0 comments on commit 8683c72

Please sign in to comment.