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

Adding version check to Logstash metricsets when xpack.enabled: true is set #12705

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions metricbeat/module/logstash/logstash.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/helper"
"github.com/elastic/beats/metricbeat/helper/elastic"
"github.com/elastic/beats/metricbeat/mb"
)

Expand Down Expand Up @@ -74,6 +75,10 @@ func validateXPackMetricsets(base mb.BaseModule) error {
// ModuleName is the name of this module.
const ModuleName = "logstash"

// PipelineGraphAPIsAvailableVersion is the version of Logstash since when its APIs
// can return pipeline graphs
var PipelineGraphAPIsAvailableVersion = common.MustNewVersion("7.3.0")

// MetricSet can be used to build other metricsets within the Logstash module.
type MetricSet struct {
mb.BaseMetricSet
Expand Down Expand Up @@ -135,6 +140,32 @@ func GetPipelines(http *helper.HTTP, resetURI string) ([]PipelineState, error) {
return pipelines, nil
}

// GetVersion returns the version of the Logstash node
func GetVersion(http *helper.HTTP, currentPath string) (*common.Version, error) {
const rootPath = "/"
content, err := fetchPath(http, currentPath, rootPath, "")
if err != nil {
return nil, err
}

var response struct {
Version *common.Version `json:"version"`
}

err = json.Unmarshal(content, &response)
if err != nil {
return nil, err
}

return response.Version, nil
}

// ArePipelineGraphAPIsAvailable returns whether Logstash APIs that returns pipeline graphs
// are available in the given version of Logstash
func ArePipelineGraphAPIsAvailable(currentLogstashVersion *common.Version) bool {
return elastic.IsFeatureAvailable(currentLogstashVersion, PipelineGraphAPIsAvailableVersion)
}

func fetchPath(http *helper.HTTP, resetURI, path string, query string) ([]byte, error) {
defer http.SetURI(resetURI)

Expand Down
19 changes: 19 additions & 0 deletions metricbeat/module/logstash/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package node

import (
"fmt"

"github.com/elastic/beats/metricbeat/helper"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/mb/parse"
Expand Down Expand Up @@ -63,6 +65,23 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
return nil, err
}

if ms.XPack {
logstashVersion, err := logstash.GetVersion(http, ms.HostData().SanitizedURI+nodePath)
if err != nil {
return nil, err
}

arePipelineGraphAPIsAvailable := logstash.ArePipelineGraphAPIsAvailable(logstashVersion)
if err != nil {
return nil, err
}

if !arePipelineGraphAPIsAvailable {
const errorMsg = "The %v metricset with X-Pack enabled is only supported with Logstash >= %v. You are currently running Logstash %v"
return nil, fmt.Errorf(errorMsg, ms.FullyQualifiedName(), logstash.PipelineGraphAPIsAvailableVersion, logstashVersion)
}
}

return &MetricSet{
ms,
http,
Expand Down
17 changes: 17 additions & 0 deletions metricbeat/module/logstash/node_stats/node_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package node_stats

import (
"fmt"

"github.com/elastic/beats/metricbeat/helper"

"github.com/elastic/beats/metricbeat/mb"
Expand Down Expand Up @@ -66,6 +68,21 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
}

if ms.XPack {
logstashVersion, err := logstash.GetVersion(http, ms.HostData().SanitizedURI+nodeStatsPath)
if err != nil {
return nil, err
}

arePipelineGraphAPIsAvailable := logstash.ArePipelineGraphAPIsAvailable(logstashVersion)
if err != nil {
return nil, err
}

if !arePipelineGraphAPIsAvailable {
const errorMsg = "The %v metricset with X-Pack enabled is only supported with Logstash >= %v. You are currently running Logstash %v"
return nil, fmt.Errorf(errorMsg, ms.FullyQualifiedName(), logstash.PipelineGraphAPIsAvailableVersion, logstashVersion)
}

http.SetURI(http.GetURI() + "?vertices=true")
}

Expand Down