Real time change detection in ChatOps by using gRPC Stream
This is an article on the 25th CyberAgent Advent Calendar 2017.
Today let me introduce our lovely bot called neokiriko. She is our second generation bot, and older first generation is kiriko. They are powerful buddy for our ChatOps, and inspired by the most famous Japanese fashion monster!
Architecture Overview
neokiriko architecture is as follows.
neokiriko is written as a private slack app. She is important as bot application but her role is limited and is not monolithic. We have microservices specialized in web operation. It manipulates public cloud resources like AWS, continuous integration service like CircleCI, and GitHub. By doing so, web operations can be used from other microservices and command line tools.
Real time change detection sequence
Let me explain one of effective techniques in this architecture.
We often use server push technology with gRPC Stream. gRPC Stream is very useful and can reduce the number of HTTP requests. This can be applied to advanced web operations.
For example, we build make version tag to latest docker image in CircleCI build container. In this case, you need to look at Web UI to check current build status. However, I believe that build progress should be notified to Slack. Therefore, we developed the following mechanism.
When tag command is sent, gRPC stream is established between neokiriko and ops service. The role of this gRPC stream is to push build status from ops service to neokiriko. When neokiriko receives current status, it posts updated payload to target responseURL. When is build completed, disconnect gRPC stream.
This example is using CircleCI, but it can be applied in various cases. Ops service can manipulate Kubernetes Cluster by using gRPC stream, and there seems to be many effective use cases.