-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Conversation
Is this approach ok for you? cc @sparrc |
Webhook []WebhookConfig | ||
} | ||
|
||
type WebhookConfig struct { |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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:
- The
RollbarConfig
get initialized so we don't know if we should start it or not. - 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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
57eecb5
to
f1c247d
Compare
Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me>
Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me>
Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me>
cc403c1
to
47f3a70
Compare
d328100
to
fa60db9
Compare
Updated with the new config:
This PR is ready for a full review. |
Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me>
fa60db9
to
f2e03bb
Compare
s := reflect.ValueOf(wb).Elem() | ||
for i := 0; i < s.NumField(); i++ { | ||
f := s.Field(i) | ||
|
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Fixed.
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) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, with some tests.
It's done on our side. I'll check your comments. |
Updated with your comments. |
All done @sparrc |
closes #1289 Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> Rename internals struct. Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> Update changelog. Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> Update READMEs and CHANGELOG. Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> 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.
closes #1289 Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> Rename internals struct. Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> Update changelog. Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> Update READMEs and CHANGELOG. Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> 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.
closes influxdata#1289 Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> Rename internals struct. Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> Update changelog. Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> Update READMEs and CHANGELOG. Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> 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.
Information
This is a WIP of a new plugin
webhooks
that allow multiple sub-webhooks as discused on #1287 and #1248The config looks like
There is still work to do. We are waiting for feedbacks before :)
Required for all PRs:
Signed-off-by: François de Metz francois@stormz.me
Signed-off-by: Cyril Duez cyril@stormz.me