-
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.
Metricbeat: Add configuration for RabbitMQ management prefix path (#7074
) Refactor RabbitMQ metricsets to reuse host parser and metricset builder so management prefix path can be configured as an only module setting. Check in tests the paths metricbeat is trying to access to collect the metrics. Previously it required to configure each metricset in its own module block with the path in the host.
- Loading branch information
Showing
17 changed files
with
228 additions
and
130 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
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
The RabbitMQ module uses http://www.rabbitmq.com/management.html[HTTP API] created by the management plugin to collect metrics. | ||
|
||
The default metricsets are `connection`, `node` and `queue`. | ||
The default metricsets are `connection`, `node`, `queue` and `exchange`. | ||
|
||
If `management.path_prefix` is set in RabbitMQ configuration, `management_path_prefix` has to be set to the same value in this module configuration. |
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
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 @@ | ||
package rabbitmq | ||
|
||
import ( | ||
"github.com/elastic/beats/metricbeat/helper" | ||
"github.com/elastic/beats/metricbeat/mb" | ||
) | ||
|
||
// MetricSet can be used to build other metric sets that query RabbitMQ | ||
// management plugin | ||
type MetricSet struct { | ||
mb.BaseMetricSet | ||
*helper.HTTP | ||
} | ||
|
||
// NewMetricSet creates an metric set that can be used to build other metric | ||
// sets that query RabbitMQ management plugin | ||
func NewMetricSet(base mb.BaseMetricSet, subPath string) (*MetricSet, error) { | ||
http, err := helper.NewHTTP(base) | ||
if err != nil { | ||
return nil, err | ||
} | ||
http.SetURI(http.GetURI() + subPath) | ||
http.SetHeader("Accept", "application/json") | ||
|
||
return &MetricSet{ | ||
base, | ||
http, | ||
}, nil | ||
} |
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,63 @@ | ||
package rabbitmq | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/metricbeat/mb" | ||
mbtest "github.com/elastic/beats/metricbeat/mb/testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func init() { | ||
mb.Registry.MustAddMetricSet("rabbitmq", "test", newTestMetricSet, | ||
mb.WithHostParser(HostParser), | ||
) | ||
} | ||
|
||
type testMetricSet struct { | ||
*MetricSet | ||
} | ||
|
||
func newTestMetricSet(base mb.BaseMetricSet) (mb.MetricSet, error) { | ||
ms, err := NewMetricSet(base, "/api/test") | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &testMetricSet{ms}, nil | ||
} | ||
|
||
// Fetch makes an HTTP request to fetch connections metrics from the connections endpoint. | ||
func (m *testMetricSet) Fetch() ([]common.MapStr, error) { | ||
_, err := m.HTTP.FetchContent() | ||
return nil, err | ||
} | ||
|
||
func TestManagementPathPrefix(t *testing.T) { | ||
visited := false | ||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
switch r.URL.Path { | ||
case "/management_prefix/api/test": | ||
w.WriteHeader(200) | ||
w.Header().Set("Content-Type", "application/json;") | ||
visited = true | ||
default: | ||
w.WriteHeader(404) | ||
} | ||
})) | ||
defer server.Close() | ||
|
||
config := map[string]interface{}{ | ||
"module": "rabbitmq", | ||
"metricsets": []string{"test"}, | ||
"hosts": []string{server.URL}, | ||
pathConfigKey: "/management_prefix", | ||
} | ||
|
||
f := mbtest.NewEventsFetcher(t, config) | ||
f.Fetch() | ||
assert.True(t, visited) | ||
} |
Oops, something went wrong.