Giter Site home page Giter Site logo

fabric8-notification's Introduction

Fabric8 Notification service

1. Contributes

1.1. Project Structure

This project is build around Notification Type in center.

To register new notification type and to see list of exisitng notification type check in main.go

1.1.1. Introducing New / Ehnancing Existing - Notification Type

For each kind of Notification, there is one Notification Type is defined. This section will give details on what are the components of Notification Type which helps to introduce new Notification Type or Enhance existing one.

Register

New Notification Type can be registered as below,

resolvers.Register("analytics.notify.cve", collector.ConfiguredVars(config, collector.NewCVEResolver(authClient, witClient)), nil)
  • First arg, Notification Type name (string), here it is "analytics.notify.cve". You need to come up with unique Notification Type name depending on what kind of New Notificatoin you want to support. Later value of this will be used to get registered Resolver and Validator in NotifyController.Send()

  • Second arg, ReceiverResolver, it is used to find out list of users to which email should be sent when Notificatin arrives for given Notification Type, more on this later.

  • Third arg, ParamValidator, it is used to validate parameter received in Notification payload.

Resolver

ReceiverResolver is responsible to return list of email to which notification sent for given Notification Type. Resolver will get ID attribute as input.

The value of ID attibute should be decided such that the related emails can be fetched. For ex, to find notification email list for workitem.create workitem.go type, one would like to get Workitem.ID for newly created workitem.

You can also decide to set ID with value of codebase_url for analytics.notify.cve cve.go type as with url one can find users who have registred for CVE notification on given Codebase URL.

Resolver will generally get initialized with 'WIT Client' and 'Auth Client' which will be used to query data based on ID to get notification email list.

Template

This is about email template which include email body, subject, headers etc. All email templates are maintained in template folder. For each Notification Type there is one folder with its name.

  • body.html - mandatory file which should have email body. It uses golang template link.

  • subject.txt - mandatory file which should have subject like for email. It uses golang template link.

1.2. Notification API

Here is sequence diagram of "/api/notify" API. Client will call this API to send Notification Emails.

NotifyAPI

1.3. Build Project

This project use the dep dependency management system.

1.3.1. Prerequisites

One should have go (version 1.10 or later), git and make installed on the system.

1.3.2. make commands for local development
make all - build everything

Run make all to build the whole project. After this one can find executable created at ./bin/fabric8-notification and run the same to run the Notification service locally.

While running locally, you need to set mandrill.apikey configuration param. This param used in sending notification email. While doing local devl and testing, you can skip send_email part and thus comment in main.go which validate this param.

make preview - test email generation against template

Run make preview to run preview/main.go. This will execute all template generation defined in main.go file. This is useful when you want to check the output of your template. The output email will be stored at ./tmp/ folder with file name having Notification Type name as prefix.

make test-unit-no-coverage - execute unit tests

Run make test-unit-no-coverage to run unit tests without coverage.

make clean

Run make clean clean all artificates generated during build. This is not removing ./tmp/ folder.

1.3.3. Updating WIT/Auth API dependency

This project uses WIT/Auth Client API. Time to time WIT/Auth project dependency should be changed in glide files to get latest WIT/Auth API.

fabric8-notification's People

Contributors

alexeykazakov avatar aslakknutsen avatar fche avatar geetikabatra avatar invinciblejai avatar jarifibrahim avatar jmelis avatar kwk avatar matousjobanek avatar mindreeper2420 avatar nurali-techie avatar sbose78 avatar sbryzak avatar surajssd avatar vpavlin avatar xcoulon avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fabric8-notification's Issues

Scale Profile images correctly

When user has an imageURL from gravatar we can easily append "?s=22" to the URL and we're good, but some have imageURL from github which contain another URL parameter "?v=n" appending "?s=22" to that has no effect.

The image size function need to take the additional parameter into account

return an error if the payload is invalid

in

func (a *AsyncWorkerNotifier) do(cn contextualNotification) {
ctx, notification := cn.context, cn.notification
receivers, vars, err := notification.Resolver(ctx, notification.ID)
if err != nil {
log.Error(ctx, map[string]interface{}{
"type": notification.Type,
"id": notification.ID,
"err": err,
}, "failed to resolve receivers")
return
}
if receivers == nil || len(receivers) == 0 {
log.Info(ctx, map[string]interface{}{
"type": notification.Type,
"id": notification.ID,
}, "skipping send email as no receivers resolved")
return
}
if vars == nil {
vars = map[string]interface{}{}
}
vars["custom"] = notification.CustomAttributes
subject, body, headers, err := notification.Template.Render(vars)
if err != nil {
log.Error(ctx, map[string]interface{}{
"type": notification.Type,
"id": notification.ID,
"err": err,
}, "failed to render template")
return
}
a.Sender.Send(ctx, subject, body, headers, receivers)
, if there is no receiver, no email is sent, but there's also no error returned to the caller, which can result in opening issues such as openshiftio/openshift.io#4605

Fail to parse template on missing system.description

{
	"err": "template: workitem.create:75:49: executing \"workitem.create\" at <\"system.description....>: invalid value; expected string",
	"file": "/tmp/go/src/github.com/fabric8-services/fabric8-notification/email/notifier.go",
	"func": "github.com/fabric8-services/fabric8-notification/email.(*AsyncWorkerNotifier).do",
	"id": "workitem.create",
	"identity_id": "46e9afce-5e0d-44fd-aa2b-2040357a4efb",
	"level": "error",
	"line": 89,
	"msg": "failed to render template",
	"pid": 1,
	"pkg": "github.com/fabric8-services/fabric8-notification/email",
	"req_headers": {
		"Accept-Encoding": [
			"gzip"
		],
		"Authorization": "*****",
		"Content-Length": [
			"162"
		],
		"Content-Type": [
			"application/json"
		],
		"User-Agent": [
			"Go-http-client/1.1"
		]
	},
	"req_id": "MwdOyF7UZn-73647",
	"req_payload": "{\"data\":{\"attributes\":{\"id\":\"d3e78d1f-bf18-4a21-9fca-968675d7a91f\",\"type\":\"workitem.create\"},\"id\":\"af2ccbfc-cb07-4376-a150-36afce7143fd\",\"type\":\"notifications\"}}",
	"time": "2017-08-01 08:53:06",
	"type": "d3e78d1f-bf18-4a21-9fca-968675d7a91f"
}

Unknown value work-item.name

The workitem templates refer to a [work-item.name] value. Not sure which value this is intended to be. Using woritem-type.name for now (e.g. bug, scenario etc)

support cico test coverage job

Issue:
For PR #99, we have observed that the ci.centos.org PR build (coverage) check is failing with following error.

/bin/bash: cico_run_coverage.sh: No such file or directory

Link: https://ci.centos.org/job/devtools-fabric8-notification-coverage/1/console

Fix:
Check whether we can run_tests_with_coverage and get meaningful metrics out of it. If yes, plz add support for run_tests_with_coverage. If we find that the run_tests_with_coverage take similar (almost same) build time as compared to run_tests_without_coverage then we can only have run_tests_with_coverage.

Add direct link to comment on comment.create|update

"Open this" links to the WorkItem details. It would be handy if this linked directly to the comment.

Require some additional UI / Backend changes:

  • Support anchor in HTML to scroll to the comment
  • Backend might need some support to 'fetch all up until this point' or similar. As the requested comment might not be part of the '5 last' comments.

Add graceful shutdown

Avoid the process being killed during rolling update before emails for currently received requests are scheduled.

Create initial Notification service

Support receiving events from WIT

  • Create Workitem
  • Update WorkItem
  • Create Comment
  • Update Comment

Should email Collaborators, WorkItem Assignees, WorkItem Creator and Commenters

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.