Graylog2 / graylog-plugin-integrations

A collection of open source Graylog integrations that will be released together.
Other
14 stars 14 forks source link

AddNotificationType causes guice error #576

Closed lingpri closed 4 years ago

lingpri commented 4 years ago

GuiceError while adding a notification type.

addNotificationType(SlackEventNotificationConfig.TYPE_NAME, SlackEventNotificationConfig.class, SlackEventNotification.class, SlackEventNotification.Factory.class);


1) No implementation for org.graylog.integrations.notifications.types.SlackEventNotificationConfig was bound.
  Did you mean?
    org.graylog.integrations.notifications.types.SlackEventNotification annotated with @com.google.inject.internal.UniqueAnnotations$Internal(value=1) bound  at org.graylog.integrations.notifications.types.SlackEventNotification$Factory.create(SlackEventNotification.java:52)

  while locating org.graylog.integrations.notifications.types.SlackEventNotificationConfig
    for the 1st parameter of org.graylog.integrations.notifications.types.SlackClient.<init>(SlackClient.java:51)
  while locating org.graylog.integrations.notifications.types.SlackClient
    for the 2nd parameter of org.graylog.integrations.notifications.types.SlackEventNotification.<init>(SlackEventNotification.java:74)
  at org.graylog.integrations.notifications.types.SlackEventNotification$Factory.create(SlackEventNotification.java:52)
  at com.google.inject.assistedinject.FactoryProvider2.initialize(FactoryProvider2.java:716)
  at org.graylog2.plugin.PluginModule.addNotificationType(PluginModule.java:296) (via modules: org.graylog2.shared.bindings.PluginBindings -> org.graylog.integrations.IntegrationsModule -> com.google.inject.assistedinject.FactoryModuleBuilder$1)

1 error
    at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:543)
    at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:178)
    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109)
    at com.google.inject.Guice.createInjector(Guice.java:87)
    at org.graylog2.shared.bindings.GuiceInjectorHolder.createInjector(GuiceInjectorHolder.java:34)
    at org.graylog2.bootstrap.CmdLineTool.setupInjector(CmdLineTool.java:381)
    at org.graylog2.bootstrap.CmdLineTool.run(CmdLineTool.java:196)
    at org.graylog2.bootstrap.Main.main(Main.java:50)

Process finished with exit code 1```
bernd commented 4 years ago

@lingpri The problem is that you are trying to inject a SlackClient instance in the SlackEventNotification constructor: https://github.com/Graylog2/graylog-plugin-integrations/pull/575/files#diff-b505e0eebc5d106c7d5e05bbf9ac78eaR69

In line 51 in SlackClient you try to inject the SlackEventNotificationConfig. That doesn't work because there is no binding for it. (and there cannot be one)

In line 90 of SlackEventNotification you already create a new SlackClient instance, passing in the SlackEventNotificationConfig you got from theEventNotificationContext. So to fix the binding error, you can just remove the injection of the SlackClient in line 69 in SlackEventNotification.

lingpri commented 4 years ago

@lingpri The problem is that you are trying to inject a SlackClient instance in the SlackEventNotification constructor: https://github.com/Graylog2/graylog-plugin-integrations/pull/575/files#diff-b505e0eebc5d106c7d5e05bbf9ac78eaR69

In line 51 in SlackClient you try to inject the SlackEventNotificationConfig. That doesn't work because there is no binding for it. (and there cannot be one)

In line 90 of SlackEventNotification you already create a new SlackClient instance, passing in the SlackEventNotificationConfig you got from theEventNotificationContext. So to fix the binding error, you can just remove the injection of the SlackClient in line 69 in SlackEventNotification.

when I follow your advice , I'm able to start the graylog server. In SlackEventNotification.java I didn't want to write the line, SlackClient slackClient = new SlackClient(config); defeats the purpose of dependency injection. I will try refactoring the code.