- Design an application in which there will be an API server which provides CRUD operations for an incident also they can acknowledge, resolve, comment to an incident.
- Also,
- there will be an Event Handler service which will emit appropriate events based on the action taken with the incident.
- there can many worker entities (like JIRA, Slack, Zendesk, etc) which can subscribe to those events.
- If a worker has subscribed to any event (say incident_created), when an incident is created, the Event Handler should receive the event from the API server(producer) and it should emit/sent to all the workers who subscribed to those events.
Service for handling and reporting incidents
This has been tested to work in the specified environments.
- Ubuntu and MacOS
- Docker Community Edition
- git
- Run
go build -o main
. - Make sure a dockerised instance of
mysql
with relevant environment variables is running. Database environment variables can be matched against that inapplication.yaml
file in the project. - Run
./main db:migrate:up
- Make sure
rabbitmq
is running as well. - Open 5 terminals.
- Run these commands in each of them:
a.
./main start:eventhandler
b../main start:webserver
c../main start:worker slack
d../main start:worker zendesk
e../main start:worker jira
- Make sure
docker-machine
is installed. - Go to
scripts
folder. - Run
./deploy.sh
in the terminal.
- Run
eval $(docker-machine env node-1)
- Run
docker service ls
to view all the services in the virtual machine.
- Run
docker service logs -f <service-id>
to view logs for a service.
- Run
docker-machine stop node-1
to stop the virtual machine instance.
Each incident is uniquely identified by the id given to the incident. An incident consists of a message, a status, an acknowledgement and comments associated with it.
Internal Server Error is returned in case of database failures or some other app related errors for all the APIs. An example is shown in the POST section.
Creates a new incident and inserts it into the db.
URL: /incident/
Method: POST
Headers:
Content-Type: application/json
Body: {
message: "issue with service",
}
Content-Type: application/json
Body: {
status: "INCIDENT CREATED",
ID: "1"
}
Content-Type: application/json
Body: {
status: "Bad Request",
error: <error-description>
}
Content-Type: application/json
Body: {
status: "Internal Server Error",
error: "incident creation failed"
}
Gets the incident for the given id.
URL: /incident/1
Method: GET
If exists:
Content-Type: application/json
Body: {
status: "unresolved",
acknowledged: "no",
message: "issues with data creation",
"comments: [
"working towards resolution"
]
}
Not Found Response (404 Not Found):
Content-Type: application/json
Body: {
status: "Not Found",
error: "incident not found"
}
Content-Type: application/json
Body: {
status: "Bad Request",
error: <error-description>
}
Update the prefilled metadata of the incident.
URL: /incident/1
Method: PUT
Body: {
acknowledged: "yes",
status: "resolved",
comments: "this issue was resolved by customer"
}
Content-Type: application/json
Body: {
status: "INCIDENT UPDATED",
}
Content-Type: application/json
Body: {
status: "Bad Request",
error: <error-description>
}
Delete an incident.
URL: /incident/1
Method: DELETE
Content-Type: application/json
Body: {
status: "INCIDENT DELETED",
}
Content-Type: application/json
Body: {
status: "Bad Request",
error: <error-description>
}
All the code related to the application resides in internal
directory with the exception of the executable file which resides outside.
- this directory contains all the handlers for the
incident
web APIs.
config
has provides data structures and helpers to store app related configurations.
eventhandler
hosts thegrpc client
- which is used by theincident web service
to notify theeventhandler
of an event and thegrpc server
which is used used to notify theworkers
of an event.
- this directory hosts the necessary infrastructure for the project like
database
andqueue
and also provides the essential interfaces to be used by the dependent services.
migrations
contains the database migration script to initialize the database schema and functions to migrate the schema to a database.
model
contains application-specific domain objects for view and entities for persistence.
serializer
is used by the service and apis to model the information coming from the apis and going out of the apis for the view.
service
interacts with the repository for getting data and updating data before and after processing.
repository
provides an interface to the service communicate with the database.
webserver
hosts the path to the apis and functionalities to start the web server.
workers
provides functionalities to create and run different types of workers.
- Docker images for the internal services have been pushed to Docker Hub with their appropriate configuration.
- Dependencies like RabbitMQ can be directly pulled from Docker hub while running the services in Docker Swarm.
- There's some issue in DNS resolution in the case of MySQL because of which connection is refused by it thereby causing the dependent services to start up.
- Tests have not been added because of time constraints.