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

Add new webhooks plugin that superseed github and rollbar plugins. #1289

Closed
wants to merge 14 commits into from

Conversation

francois2metz
Copy link
Contributor

@francois2metz francois2metz commented May 27, 2016

Information

This is a WIP of a new plugin webhooks that allow multiple sub-webhooks as discused on #1287 and #1248

The config looks like

[[inputs.webhooks]]
  service_address = ":1925"

  [[inputs.webhooks.webhook]]
    name = "rollbar"
    path = "/rollbar"

  [[inputs.webhooks.webhook]]
    name = "github"
    path = "/github"

There is still work to do. We are waiting for feedbacks before :)

  • update config

Required for all PRs:

  • CHANGELOG.md updated
  • Sign CLA (if not already signed)
  • README.md updated (if adding a new plugin)

Signed-off-by: François de Metz [email protected]
Signed-off-by: Cyril Duez [email protected]

@francois2metz
Copy link
Contributor Author

Is this approach ok for you? cc @sparrc

Webhook []WebhookConfig
}

type WebhookConfig struct {
Copy link
Contributor

@sparrc sparrc May 31, 2016

Choose a reason for hiding this comment

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

This could be problematic as future webhooks could likely have very different necessary configuration parameters.

I would prefer if we could directly define different types of webhooks here. This would introduce the limitation that only one type of webhook would be allowed per-port, but I think this is OK.

ie, config would look like this:

[[inputs.webhook]]
  service_address = ":1619"
  [inputs.webhooks.github]
    path = "/github"
  [inputs.webhooks.rollbar]
    path = "/rollbar"

Copy link
Contributor

@cduez cduez Jun 1, 2016

Choose a reason for hiding this comment

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

We change the suggested configuration because we couldn't find a nice and effective way to easily detect configured webhooks plugins with it.

Correct me if i am wrong, but with this configuration i would have a struct like this :

type WebhookConfig struct {
    ServiceAddress string

    RollbarConfig RollbarConfig
    GithubConfig  GithubConfig
}

type RollbarConfig struct {
     path string
}

type GithubConfig struct {
     path string
}

Even with this configuration:

[[inputs.webhook]]
  service_address = ":1619"
  [inputs.webhooks.github]
    path = "/github"

The problems are:

  1. The RollbarConfig get initialized so we don't know if we should start it or not.
  2. Furthermore, this probably mean that we can't iterate over a list of webhooks plugins and we have to manually iterate like this:
plugins := [wb.GithubConfig, wb.RollbarConfig]
for plugin := range plugins {
    plugin.Register...
}

Do you have any ideas of how we could solve this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Number 2 is true, you would need to maintain a list of the available webhook plugins.

Not sure I understand what you mean by Number 1, you should just be able to check if Github is not nil, and start it if so.

Copy link
Contributor

Choose a reason for hiding this comment

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

For the Number 1, we observed that all fields of the plugin struct are initialized.

This means that even if the rollbar configuration is missing, like the configuration above, we still get an initialized struct RollbarConfig (in WebhookConfig) with an empty field path. So the nil check doesn't work to know if the plugin is configured or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh nevermind, we just find that is how Go works. We just have to use a pointer instead it seems to work then.

@cduez cduez force-pushed the plugin/webhooks branch 3 times, most recently from 57eecb5 to f1c247d Compare June 2, 2016 08:16
Signed-off-by: François de Metz <[email protected]>
Signed-off-by: Cyril Duez <[email protected]>
Signed-off-by: François de Metz <[email protected]>
Signed-off-by: Cyril Duez <[email protected]>
@francois2metz francois2metz changed the title WIP: Add new webhooks plugin that superseed github and rollbar plugins. Add new webhooks plugin that superseed github and rollbar plugins. Jun 2, 2016
@francois2metz
Copy link
Contributor Author

Updated with the new config:

[[inputs.webhook]]
  service_address = ":1619"
  [inputs.webhooks.github]
    path = "/github"

This PR is ready for a full review.

s := reflect.ValueOf(wb).Elem()
for i := 0; i < s.NumField(); i++ {
f := s.Field(i)

Copy link
Contributor

Choose a reason for hiding this comment

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

there's a risk of panic here on line 77, you should add in:

if !f.CanInterface() {
  continue
}

before calling Interface()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Fixed.

@sparrc
Copy link
Contributor

sparrc commented Jun 2, 2016

Cursory review and I think it looks great, I am swamped with some other work right now but will try to do a full review of this over the weekend.

thanks @cduez & @francois2metz, is this done & ready from your perspective?

f := s.Field(i)

if wbPlugin, ok := f.Interface().(Webhook); ok {
webhooks = append(webhooks, wbPlugin)
Copy link
Contributor

@sparrc sparrc Jun 2, 2016

Choose a reason for hiding this comment

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

in here I believe you should also check if wbPlugin == nil ? (and don't append if it is nil)

Copy link
Contributor

Choose a reason for hiding this comment

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

getting hairy but I think you actually need reflect.ValueOf(wbPlugin).IsNil()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, with some tests.

@francois2metz
Copy link
Contributor Author

It's done on our side. I'll check your comments.

@francois2metz
Copy link
Contributor Author

Updated with your comments.

@francois2metz
Copy link
Contributor Author

All done @sparrc

sparrc pushed a commit that referenced this pull request Jun 22, 2016
closes #1289

Signed-off-by: François de Metz <[email protected]>
Signed-off-by: Cyril Duez <[email protected]>

Rename internals struct.

Signed-off-by: François de Metz <[email protected]>
Signed-off-by: Cyril Duez <[email protected]>

Update changelog.

Signed-off-by: François de Metz <[email protected]>
Signed-off-by: Cyril Duez <[email protected]>

Update READMEs and CHANGELOG.

Signed-off-by: François de Metz <[email protected]>
Signed-off-by: Cyril Duez <[email protected]>

Update SampleConfig.

Update the config format.

Update telegraf config.

Update the webhooks README.

Update changelog.

Update the changelog with an upgrade path.

Update default ports.

Fix indent.

Check for nil value on AvailableWebhooks.

Check for CanInterface.
sparrc pushed a commit that referenced this pull request Jun 22, 2016
closes #1289

Signed-off-by: François de Metz <[email protected]>
Signed-off-by: Cyril Duez <[email protected]>

Rename internals struct.

Signed-off-by: François de Metz <[email protected]>
Signed-off-by: Cyril Duez <[email protected]>

Update changelog.

Signed-off-by: François de Metz <[email protected]>
Signed-off-by: Cyril Duez <[email protected]>

Update READMEs and CHANGELOG.

Signed-off-by: François de Metz <[email protected]>
Signed-off-by: Cyril Duez <[email protected]>

Update SampleConfig.

Update the config format.

Update telegraf config.

Update the webhooks README.

Update changelog.

Update the changelog with an upgrade path.

Update default ports.

Fix indent.

Check for nil value on AvailableWebhooks.

Check for CanInterface.
@sparrc sparrc closed this in #1401 Jun 22, 2016
chebrolus pushed a commit to chebrolus/telegraf that referenced this pull request Jun 24, 2016
closes influxdata#1289

Signed-off-by: François de Metz <[email protected]>
Signed-off-by: Cyril Duez <[email protected]>

Rename internals struct.

Signed-off-by: François de Metz <[email protected]>
Signed-off-by: Cyril Duez <[email protected]>

Update changelog.

Signed-off-by: François de Metz <[email protected]>
Signed-off-by: Cyril Duez <[email protected]>

Update READMEs and CHANGELOG.

Signed-off-by: François de Metz <[email protected]>
Signed-off-by: Cyril Duez <[email protected]>

Update SampleConfig.

Update the config format.

Update telegraf config.

Update the webhooks README.

Update changelog.

Update the changelog with an upgrade path.

Update default ports.

Fix indent.

Check for nil value on AvailableWebhooks.

Check for CanInterface.
@francois2metz francois2metz deleted the plugin/webhooks branch June 29, 2016 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants