16 - Using Service Dependency Graph To Analyze and Test Microservices
16 - Using Service Dependency Graph To Analyze and Test Microservices
Shang-Pin Ma1, Chen-Yuan Fan1, Yen Chuang1, Wen-Tin Lee2, Shin-Jie Lee3, Nien-Lin Hsueh4
Department of Computer Science and Engineering, National Taiwan Ocean University, Keelung, Taiwan1
Department of Software Engineering and Management, National Kaohsiung Normal University, Kaohsiung, Taiwan 2
Department of Computer Science and Information Engineering, National Cheng Kung University, Tainan, Taiwan3
Department of Computer Science and Information Engineering, Feng Chia University, Taichung, Taiwan4
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
82
path part includes multiple objects which are comprising operations. A directed arrow indicates that a microservice
one or more HTTP operations like GET, POST, or invokes an endpoint of another microservice.
DELETE. In operation, it includes not only the
description, but also input parameters and responses,
which can refer to the external definitions by $ref tag.
OAS/Swagger is the most widely-used specification for
describing microservices [13].
III. GMAT (GRAPH-BASED MICROSERVICE
ANALYSIS AND TESTING)
In this section, we introduce the proposed approach,
GMAT (Graph-based Microservice Analysis and
Testing), in depth. In the beginning, we identified three Figure 2 Concept of service dependency graph (SDG)
research goals that GMAT should achieve, as follows.
1. Visualizing the dependency relationships between In this research, we also propose the concept of
microservices. Extracting the service calls (i.e., service invocation chain (SIC) to provide supplementary
service invocations) between microservices, information for SDG. The service invocation chain
building corresponding service dependency graph, indicates a sequence of service invocations between
and visualizing the graph is the first and most multiple microservices (See the heavy line of Figure 3).
important research goal of GMAT. GMAT is enabled to find all microservices involved in a
2. Detecting cyclic dependency references. The cyclic SIC and show the SIC in SDG when the user clicks any
dependency references between microservices is involved service node. Besides, when a service test case
very risky from the viewpoints of both fails, the SIC that involves the failed invocation will be
development and maintenance. Cyclic dependency highlighted to effectively help users to identify the error
references may cause failures at runtime and root.
increase the complexity of developing new versions In summary, by using GMAT, SDG could help
of microservices. Effectively detecting cyclic developers to manage the complex service interactions
dependency references is the second research goal. while SIC could effectively find error roots when failures
3. Improving the coverage of service tests. To ensure occur. The main tasks performed by GMAT include: 1)
the quality of a developed system, testing extracting service endpoint information and service call
microservice invocations is a necessity. A system information to construct service dependency relationships;
lacks of complete microservice testing is very 2) check the status of service tests and automatically
fragile and prone to be crash. Meanwhile, cross- generate the test code (using Pact) if some service test
service debugging is difficult when a runtime error cases were not written; 3) combining all information to
occurs. Thus, providing an assistant tool to improve produce a SDG document and displaying SDG in a
the test coverage is the third research goal. visualized way based on the SDG document.
A. Service Dependency Graph (SDG) and Service
Invocation Chain (SIC)
A microservice provides APIs to other microservices and
also consumes (or calls) other microservices in a system.
Service invocations cause dependency relationships
between microservices. When the number of
microservices is large, it is hard to manage the complex
dependency relationships between these microservices.
In this research, we propose the concept of service
dependency graph to address the above issue. The basic
idea is to collect all service invocation links, construct a
Figure 3 Concept of service invocation chain (SIC)
service dependency graph (SDG) to represent all links,
and show the SDG in a visualized way to let users easily B. Construction of SDG
browse all service dependency relationships and check How to extract required information for SDG is a key
anomalies or errors by using the graph. Accordingly, issue for generating SDG. In this research, we apply the
there are three required steps for the construction of Reflection mechanism to gather all necessary data, such
visualized SDG: 1) gathering all service invocation links as service endpoints and service calls. Many
from multiple microservice projects for a MSA-based programming languages, such as Java, Python, and C#,
system; 2) constructing the internal representation of support the Reflection mechanism. Its advantage is that
SDG; and 3) displaying the SDG using visualization we can obtain various program information without
techniques. program execution. Using the Reflection mechanism,
The concept of SDG is very simple, as shown in GMAT can retrieve the service endpoints and service call
Figure 2. The dark-blue circle represents a microservice information directly. If the implementation language does
while the light-gray circle represents the service endpoint. not support the feature of reflection, service dependency
A microservice owns one or more endpoints; i.e., a information could be directly provided by developers via
microservice component provides one or more service extended Swagger to allow GMAT obtain required data.
83
According to multiple sources [14, 15], Java-based a microservice project including multiple related
Spring Boot Framework is deemed as the most matured interfaces, implementation classes, and their interactions.
framework for developing microservices. Therefore, we A bigger rounded rectangle represent a class or an
decided to firstly support Spring Boot projects in GMAT. interface. Smaller, colored rounded rectangles inside an
In other words, developers could use the Spring Boot interface or a class is a method. In Figure 5, the rectangle
framework to build microservices and follow several in left-hand side is endpoints of the microservice. The
simple guidelines and practices to develop microservices rectangle in right-hand side is service call objects. The
so that GMAT can produce visualized SDG automatically. classes in the middle is core objects encapsulating
The microservice development guidelines in GMAT business logic for the microservice. The arrowed lines
include: represent function calls. In Figure 5, GMAT can extract
z Developers are strongly recommended to use Spring four links between service endpoints and service calls,
Boot Actuator to monitor microservices and gather including Service Endpoint 1 and Service Call 1, Service
metrics. GMAT relies on Spring Boot Actuator to Endpoint 2 and Service Call 1, Service Endpoint 2 and
obtain the endpoint information. Service Call 2, Service Endpoint 3 and Service Call 2. All
z Developers are also strongly recommended to use these links are stored in a graph database, Neo4J 1 , for
Spring Feign, a declarative HTTP client developed by further processing. By inspecting these links of all
Netflix, to invoke other microservices. Spring Feign microservice projects of the target application, GMAT
can work smoothly with Spring Eureka to enhance the can build all service invocation chains and construct an
flexibility by using the discovery service. GMAT overall service dependency graph. In other words, GMAT
relies on Spring Feign to retrieve the information of is able to generate visualized SDG based on the collected
service calls. An example code of Applying Spring information of services, service endpoints, and service
Feign is shown in Figure 4. The developer has to mark calls. In this research, we apply D3.js2, the widely-used
FeignClient in the interface and specify the name of web visualization framework, to render the SDG. An
the microservice. The specified name needs to be the example is shown in Figure 6. Developers could trace the
same as the one registered in Spring Eureka. The linkages between services during the development of both
FeignClient also needs to be annotated with current system version and new versions for the system.
RequestMapping information to specify the service
URL path and service method.
C. Retrieval of SIC
As mentioned, in addition to SDG, we also designed
a method to find the SIC (service invocation chains) to
detect anomalies, divided into the following three steps:
1. Retrieve all service invocation paths: By querying
the graph database (Neo4j), GMAT could find all
Figure 5 Concept of dependencies between microservices service invocation paths containing one or more
service calls.
For the project that follows the above guidelines, 2. Remove unnecessary paths: Some returned service
GMAT can obtain information of microservice endpoints invocation paths are not required to be kept since
and service calls via the Java Reflection mechanism, and these paths are included in a larger path. As shown
establish relationships between microservices based on in Figure 7, the graph in the left-hand side shows
these information. When applying the Reflection, in order interactions between endpoints in the database.
to successfully find the service endpoints and service calls, Invocation paths in the right-hand side are the query
it needs to deal with the Java interfaces and corresponding
implementation classes. Figure 5 is a diagram that shows
1 2
https://neo4j.com/ https://d3js.org/
84
results. GMAT eliminates several paths (ones in red After determining whether microservices satisfy the
color) since these paths are merely sub-paths. specified test cases, GMAT calculates the coverage of the
3. Group paths by the same starting service endpoint: service tests based on all the test results in the MSA-based
We defined that an invocation chain is a graph system. Service test coverage is calculated by using
comprising service calls for a leading service formula 1.
endpoint. As shown in Figure 7, each boxed group (
)
( ) = (1)
is defined as an SIC. (
)
z : the MSA-based system is being developed.
z ( ): service test coverage for the system
z ( ): the number of service calls that have been
passed in the test for the system .
z ( ) : the number of all service calls for the
system .
3
https://APIs.guru/openapi-directory/
85
z Neo4j Driver: Bolt interactions and effectively find error roots when failures
z Neo4j Memory Pagecache Size: 4G occur. Experiments show that GMAT is able to work well
z Neo4j Memory Heap Max Size: 8G for both small-scale and large MSA-based systems.
The next stage of development will add requriement
Table 1. Test data for simulation scenarios to SDG for further improving the capability of
change management for the target MSA-based system.
ACKNOWLEDGMENT
This research was sponsored by Ministry of Science
and Technology in Taiwan under the grants MOST 105-
2221-E-019-054-MY3 and MOST 106-2221-E-035 -014
-MY2.
REFERENCES
[1] C. Y. Fan and S. P. Ma, "Migrating Monolithic Mobile
Application to Microservice Architecture: An Experiment
Report," in 2017 IEEE International Conference on AI &
Mobile Services (AIMS), 2017, pp. 109-112.
[2] B. Familiar, "What Is a Microservice?," in Microservices, IoT,
and Azure, ed: Springer, 2015, pp. 9-19.
The experiment was conducted 5 times to obtain [3] S. Newman, Building Microservices: " O'Reilly Media, Inc.",
average results. Figure 10 presents the data related to the 2015.
creation times of SDGs for the prepared MSA-based [4] J. Lewis and M. Fowler, "Microservices," ed: Recuperado de:
http://martinfowler.com/articles/microservices.html, 2014.
applications with various number of microservices. [5] C. Richardson, "Microservices: Decomposing applications for
When the number of microservices is less than 200, the deployability and scalability," ed: InfoQ, 2014.
SDG creation time is less than seven seconds. Even when [6] J. Lewis and M. Fowler. (2014). Microservices - a definition of
the number of microservices is one thousand, the this new architectural term. Available:
https://martinfowler.com/articles/microservices.html
creation time is less than 1.5 minutes. Our results
[7] F. Montesi and J. Weber, "Circuit Breakers, Discovery, and
indicate that GMAT yields acceptable performance for API Gateways in Microservices," arXiv preprint
the creation of service dependency graph. It also arXiv:1609.05830, 2016.
demonstrate that GMAT is feasible to be applied in both [8] M. Soni, "End to End Automation on Cloud with Build
Pipeline: The Case for DevOps in Insurance Industry,
small-scale and large-scale MSA-based applications.
Continuous Integration, Continuous Testing, and Continuous
Delivery," in 2015 IEEE International Conference on Cloud
Computing in Emerging Markets (CCEM), 2015, pp. 85-89.
Service Dependency Graph Creation Time [9] M. Fowler and M. Foemmel, "Continuous integration,"
Thought-Works) http://www. thoughtworks. com/Continuous
100
87.23 Integration. pdf, p. 122, 2006.
90
[10] H. Kang, M. Le, and S. Tao, "Container and Microservice
80 Driven Design for Cloud Infrastructure DevOps," in 2016 IEEE
International Conference on Cloud Engineering (IC2E), 2016,
creation time (second)
70
60 pp. 202-211.
50 [11] What is Docker. Available: https://www.docker.com/what-
40 docker-old
30
27.22 [12] OpenAPI Specification. Available:
21.19
13.17
https://github.com/OAI/OpenAPI-
20
6.9 Specification/blob/master/versions/2.0.md
10 1.22 2.67
0.5 0.8 0.85 1.09 [13] H. Vural, M. Koyuncu, and S. Guney, "A Systematic Literature
0
10 20 30 40 50 100 200 300 400 500 1,000
Review on Microservices," Cham, 2017, pp. 203-217.
Service number
[14] O. Shelajev. (2016). Why Spring is Winning the Microservices
Game. Available: https://zeroturnaround.com/rebellabs/why-
spring-is-winning-the-microservices-game/
Figure 10 SDG creation time [15] H. Schlosser. (2017). Microservices trends 2017: Strategies,
tools and frameworks. Available:
https://jaxenter.com/microservices-trends-2017-survey-
V. CONCLUSIONS 133265.html
In this paper, we propose an approach for assisting the [16] R. Tarjan, "Depth-First Search and Linear Graph Algorithms,"
SIAM Journal on Computing, vol. 1, pp. 146-160, 1972.
development of MSA-based systems, referred to as [17] T. Mauro. (2015). Adopting Microservices at Netflix: Lessons
GMAT (Graph-based Microservice Analysis and for Architectural Design. Available:
Testing). GMAT can automatically generate "Service https://www.nginx.com/blog/microservices-at-netflix-
Dependency Graph (SDG)" to analyze and visualize the architectural-best-practices/
dependency relationships between microservices. GMAT [18] B. Wong. (2014). The Case for Chaos. Available:
https://www.slideshare.net/BruceWong3/the-case-for-chaos
could help developers to manage the complex service
86