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

Metricbeat: Add configuration for RabbitMQ management prefix path #7074

Merged
merged 1 commit into from
May 11, 2018

Conversation

jsoriano
Copy link
Member

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, as described in #6875.

@jsoriano jsoriano added in progress Pull request is currently in progress. module Metricbeat Metricbeat labels May 11, 2018
)

var (
HostParser = parse.URLHostParserBuilder{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported var HostParser should have comment or be unexported

defaultScheme = "http"
pathConfigKey = "management_path_prefix"

ConnectionsPath = "/api/connections"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported const ConnectionsPath should have comment (or a comment on this block) or be unexported

*helper.HTTP
}

func NewMetricSet(base mb.BaseMetricSet, subPath string) (*MetricSet, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported function NewMetricSet should have comment or be unexported

"github.com/elastic/beats/metricbeat/mb"
)

type MetricSet struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported type MetricSet should have comment or be unexported

@@ -103,6 +103,10 @@ func (h *HTTP) SetMethod(method string) {
h.method = method
}

func (h *HTTP) GetURI() string {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported method HTTP.GetURI should have comment or be unexported


// Subpaths to management plugin endpoints
ConnectionsPath = "/api/connections"
ExchangesPath = "/api/exchanges"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported const ExchangesPath should have comment (or a comment on this block) or be unexported

defaultScheme = "http"
pathConfigKey = "management_path_prefix"

// Subpaths to management plugin endpoints

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment on exported const ConnectionsPath should be of the form "ConnectionsPath ..."

@jsoriano jsoriano force-pushed the rabbitmq-preffix-path branch 3 times, most recently from e04c9c9 to 1c66840 Compare May 11, 2018 08:14
@jsoriano jsoriano added review and removed in progress Pull request is currently in progress. labels May 11, 2018
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.
Copy link
Member

@ruflin ruflin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a huge step forward in how we can simplify adding new modules. This will reduce the code in quite a few modules with multiple metricsets and will adding new ones much easier.

I was wondering if we should split out the code refactoring part from the management change? Not necessarily because of the management change but because I think the refactor deserves it's own commit to point people to to have a look.

@@ -14,13 +14,21 @@ import (
)

func TestFetchEventContents(t *testing.T) {
absPath, err := filepath.Abs("../_meta/testdata/")
absPath, _ := filepath.Abs("../_meta/testdata/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a assert.NoError( for these erors. This will make debugging test much easier.

w.Header().Set("Content-Type", "application/json;")
w.Write([]byte(response))
default:
w.WriteHeader(404)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I should steal this for my elasticsearch http tests.

func init() {
if err := mb.Registry.AddMetricSet("rabbitmq", "exchange", New, hostParser); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we miss that in our PR bonanza or this came in later?


// Subpaths to management plugin endpoints
const (
ConnectionsPath = "/api/connections"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going forth an back if this should be in the module or in the metricset. Is there a benefit that the module knows about these paths?


var (
// HostParser parses host urls for RabbitMQ management plugin
HostParser = parse.URLHostParserBuilder{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it could become an issue that all Metricsets will now share one host parser as a global object?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be an issue.

@ruflin ruflin merged commit 2f3068a into elastic:master May 11, 2018
@ruflin
Copy link
Member

ruflin commented May 11, 2018

Merged it already to move forward with this. I really hope we get similar simplifications for other modules.

ruflin added a commit to ruflin/beats that referenced this pull request May 15, 2018
This is inspired by elastic#7074. More work is needed.
stevea78 pushed a commit to stevea78/beats that referenced this pull request May 20, 2018
…astic#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.
stevea78 pushed a commit to stevea78/beats that referenced this pull request May 20, 2018
…astic#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.
@jsoriano jsoriano deleted the rabbitmq-preffix-path branch November 7, 2018 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants