-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the Elastic product origin header when talking to Elasticsearch o…
…r Kibana. (#29966) Set the beats product origin header by default when communicating with Elasticsearch or Kibana. (cherry picked from commit 5f3dd3e) # Conflicts: # metricbeat/module/kibana/settings/settings.go # metricbeat/module/kibana/stats/stats.go # metricbeat/module/kibana/status/status.go
- Loading branch information
Showing
7 changed files
with
167 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
// Package productorigin defines the Elastic product origin header. | ||
package productorigin | ||
|
||
const ( | ||
// Identifies a request as originating from an Elastic product. Has the side effect of | ||
// suppressing Elasticsearch API deprecation warnings in Kibana when set. | ||
Header = "X-Elastic-Product-Origin" | ||
|
||
// Applicable values from https://github.com/elastic/kibana/blob/main/x-pack/plugins/upgrade_assistant/common/constants.ts#L50 | ||
Observability = "observability" | ||
Beats = "beats" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package settings | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/elastic/beats/v7/libbeat/common/productorigin" | ||
"github.com/elastic/beats/v7/metricbeat/helper" | ||
"github.com/elastic/beats/v7/metricbeat/mb" | ||
"github.com/elastic/beats/v7/metricbeat/mb/parse" | ||
"github.com/elastic/beats/v7/metricbeat/module/kibana" | ||
) | ||
|
||
// init registers the MetricSet with the central registry. | ||
// The New method will be called after the setup of the module and before starting to fetch data | ||
func init() { | ||
mb.Registry.MustAddMetricSet(kibana.ModuleName, "settings", New, | ||
mb.WithHostParser(hostParser), | ||
) | ||
} | ||
|
||
var ( | ||
hostParser = parse.URLHostParserBuilder{ | ||
DefaultScheme: "http", | ||
DefaultPath: kibana.SettingsPath, | ||
QueryParams: "extended=true", // make Kibana fetch the cluster_uuid | ||
}.Build() | ||
) | ||
|
||
// MetricSet type defines all fields of the MetricSet | ||
type MetricSet struct { | ||
mb.BaseMetricSet | ||
settingsHTTP *helper.HTTP | ||
} | ||
|
||
// New create a new instance of the MetricSet | ||
func New(base mb.BaseMetricSet) (mb.MetricSet, error) { | ||
return &MetricSet{ | ||
BaseMetricSet: base, | ||
}, nil | ||
} | ||
|
||
// Fetch methods implements the data gathering and data conversion to the right format | ||
// It returns the event which is then forward to the output. In case of an error, a | ||
// descriptive error must be returned. | ||
func (m *MetricSet) Fetch(r mb.ReporterV2) (err error) { | ||
if err = m.init(); err != nil { | ||
return | ||
} | ||
|
||
content, err := m.settingsHTTP.FetchContent() | ||
if err != nil { | ||
return | ||
} | ||
|
||
return eventMapping(r, content) | ||
} | ||
|
||
func (m *MetricSet) init() (err error) { | ||
httpHelper, err := helper.NewHTTP(m.BaseMetricSet) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
httpHelper.SetHeaderDefault(productorigin.Header, productorigin.Beats) | ||
|
||
kibanaVersion, err := kibana.GetVersion(httpHelper, kibana.SettingsPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
isSettingsAPIAvailable := kibana.IsSettingsAPIAvailable(kibanaVersion) | ||
if !isSettingsAPIAvailable { | ||
const errorMsg = "the %v metricset is only supported with Kibana >= %v. You are currently running Kibana %v" | ||
return fmt.Errorf(errorMsg, m.FullyQualifiedName(), kibana.SettingsAPIAvailableVersion, kibanaVersion) | ||
} | ||
|
||
m.settingsHTTP, err = helper.NewHTTP(m.BaseMetricSet) | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters