0% found this document useful (0 votes)
312 views6 pages

16 - Using Service Dependency Graph To Analyze and Test Microservices

Documento

Uploaded by

Lidiane Souza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
312 views6 pages

16 - Using Service Dependency Graph To Analyze and Test Microservices

Documento

Uploaded by

Lidiane Souza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

2018 42nd IEEE International Conference on Computer Software & Applications

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]

Abstract—Microservice architecture (MSA) is an Microservice Analysis and Testing). GMAT can


emerging software architectural style, which differs automatically generate "Service Dependency Graph
fundamentally from the monolithic, layered architecture. (SDG)" to analyze and visualize the dependency
MSA is based on microservices to provide several relationships between microservices. Using GMAT,
advantages, such as autonomy, composability, scalability, people are able to detect anomalies by analyzing risky
and fault-tolerance. However, how to manage complex service invocation chains in early stage of development,
“call” relationships between microservices is still a big and trace the linkages between services when developing
issue that needs to be addressed. In this paper, we propose a new version of a target system. The system overview of
an approach for assisting the development of MSA-based GMAT is shown in Figure 1.
systems, referred to as GMAT (Graph-based
Microservice Analysis and Testing). GMAT can
automatically generate "Service Dependency Graph
(SDG)" to analyze and visualize the dependency
relationships between microservices. Using GMAT,
people are able to detect anomalies by analyzing risky
service invocation chains in early stage of development,
and trace the linkages between services when developing
a new version of a target system. Experiments show that Figure 1 Overview of GMAT approach
GMAT is able to work well for both small-scale and
large-scale MSA-based systems. The remainder of this paper is organized as follows:
Keywords- microservice testing, microservice analysis, Section 2 outlines background knowledge and related
service dependency graph, service engineering work. In Section 3, we describe the proposed GMAT
approach in depth. Section 4 presents the quantitative
experiments. Section 5 draws a number of conclusions.
I. INTRODUCTION
The rapid development of the internet has greatly II. BACKGROUND AND RELATED WORK
increased the number of requests for services on demand.
Traditional software applications, referred to as A. Characteristcis of Microservices
monolithic ones, are divided into the front-end UI (user An in-depth survey of the literature led to the
interface), service-side logic components, and database. identification of five characteristics of microservices [2-
Monolithic architecture needs to struggle with handling 6]:
cases in which the number of users exceeds the capacity 1. Autonomous: microservices are responsible for the
of the server. Furthermore, monolithic architectures are execution of their own underlying processes, which
hard to manage and maintain due to a lack of mechanisms can be initiated, operated, and shut down
aimed at modularization [1]. Microservice architecture independently. They can be also developed and
(MSA) [2-6] is an emerging cloud-based software deployed separately within their own development
architecture, which differ fundamentally from monolithic lifecycle.
systems. MSA provides intermediate building blocks, 2. Scalability: microservices are small, stateless
referred to as microservices, to handle specific functions. components, which makes them easy to scale up.
Microservices provide a lot of advantages, such as 3. Technology heterogeneity: microservices use
autonomy, composability, scalability, and fault-tolerance. unified platform-independent, communication
Several enterprises, such as Netflix, Amazon, and Spotify, protocols for the exchange of information, which
have adopted the microservice architecture to build means that they can be constructed using a variety
scalable, easily maintainable software systems. However, of programming languages on various platforms
microservices has two characteristics, Microservice using many types of database.
choreography and evolutionary design, that cause several 4. Specialized: each service handles specific domain
pending issues. The first issue is how to manage complex logic and communicates with other services using
call relationships between microservices while the second well-designed interfaces.
one is how to efficiently assure the quality of 5. Fault Tolerance: the fact that each microservice has
continuously changing microservices. its own lifecycle means that it is able to tolerate
To address the above issues, in this paper, we propose failures by applying a failover mechanism or
an approach for assisting the development of MSA-based skipping the invocation, whenever a service fails.
systems, referred to as GMAT (Graph-based

0730-3157/18/$31.00 ©2018 IEEE 81


DOI 10.1109/COMPSAC.2018.10207
For the sake of scalability, an MSA should be which includes a Firefox plugin allowing automated
equipped with Service Discovery, API Gateway, and script writing in various programming languages. Video
Circuit Breaker. Service discovery provides a mechanism and screenshots can also be captured during testing.
for the registration of microservices. This makes the Selenium allows the use of Selenium Grid for the
services addressable, such that they are able to concurrent execution of multiple cases to speed up
communicate with each other using an IP and port [7]. validation. Nightmare is a high-level browser automation
API Gateway is an interface between the client and tool that can be implemented without the need for an
microservice system, which allows users to invoke the actual browser. It uses Electron, a web technology used
services they require without the need for any knowledge in the development of desktop applications, providing
pertaining to the structure of the system. Circuit Breaker simpler syntax and a wider choice of API.
is an error handling mechanism to increase the resiliency Behavior-driven development (BDD) is a common
of the system. approach to agile development, allowing analysts,
Various automation tools are required for the developers, and testers to work together in the
application of MSA. A pipeline [8] breaks down the development of scenarios. The final step in testing a
software delivery process into stages, including build microservice system is to confirm that the system works
automation, continuous integration [9], test automation, well in all anticipated situations. Gherkin is a business-
and deployment automation. The use of containers [10] in readable, domain-specific language commonly used in
the pipeline facilitates deployment and portability to behavior-driven testing. It can be used to describe the
accelerate the delivery of software systems to users. A behavior of software without the need to describe the
container provides an environment in which to run an method of implementation. It also can be used as a
application program, and may be regarded as a document of the software. Cucumber and Serenity BDD
lightweight virtual machine not running under Hypervisor. are BDD frameworks that support Gherkin as well as a
The use of the Docker [11] container is widely variety of programming language, including Java. It can
recommended to run microservices. In large-scale also be used with JUnit, Selenium, and other test tools. As
microservice systems, centralized logs, metrics, and long as a Gherkin description file is written and tests
feedback systems can be used to facilitate management implemented, Cucumber can be used to perform tests
and on-going development. (based on the descriptor) to produce Pretty, HTML, JSON
and other test reports.
B. Testing Mechanisms for Microservices
Testing is a key step in software development. Within C. Discovery Service
a microservice architecture, the testing process plays an Within a microservice system, services are able to
important role in the integration of services in a pipeline. communicate with each other. However, enabling
In this phase, we introduce four testing methods including, services to find each other and communicate remains an
unit test, service test, end-to-end test, and behavior-driven on-going problem. Introducing a service discovery
test. It is generally preferable to minimize the number of mechanism makes it possible for a service to obtain real-
test cases to ensure the fastest possible pipeline time information about the IP and Port of other services
processing. simply by implementing service discovery. Thus, the
To ensure the functionality of a microservice, it must service need not be aware of the IP or Port of other
pass unit testing during development. It is common to services. Besides, since Service Discovery tools enable
employ JUnit as a unit testing tool. Mockito is a Mock the mapping from one name to multiple services, it can
framework used to verify the behavior of mock objects, also provide the functionality of load balancing with
such as the time of a function call, and verify the simple service selection methods, such as Round Robin
correctness of input parameters and return values. or Random selection.
Service testing must take into account the consumer- A number of Service Discovery systems are available,
driven contract between a service provider and its service including Etcd, Consul, and Eureka. Etcd is based on
consumer to ensure successful service invocation. During key/value store. Consul provides built-in auto load
consumer-driven contract testing, the unit test is balancing in cases where services are registered under the
implemented on the consumer side to verify the body and same name. Eureka was developed by Netflix running on
header of the request and define an expectation of the JVM with a built-in load balancer. All of the above-
header and body. When a unit test is passed, a DSL mentioned tools have RESTful interface, which is very
(Domain Specific Language) file is auto-generated, The useful in the development and implementation of
DSL file contains verification information to the API microservices.
provider. For service testing in the provider side, it is easy
to simply use the DSL generated from the service D. OpenAPI (Swagger)
consumer to verify the service provider. Pact is an open- The OpenAPI Specification (OAS, originally called
source contract-driven testing tool, which can be used to Swagger) [12] is a document specification for describing,
implement the above-mentioned approach. Pact supports generating, and consuming RESTful Web services. A
most popular programming languages. Besides, the DSL variety of tools can generate code, documentation and test
generated from Pact can be managed by Pact Broker. cases based on OAS. OAS released by Wordnik in 2011,
The End-to-End Test is used to test whether the supports lightweight formats like JSON and YAML.
system acts as the expected use cases. It is also an Many Web API developers have already supplied their
important part of the testing of microservice systems. OAS documents to their clients. The content of OAS can
Selenium is an automated tool for testing web pages, be divided into two parts: info and path. The info part
includes API title, version, and contact information. The

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.

Figure 4 Example of Spring Feign

z Developer are recommended to additionally apply


springfox-swagger2 to automatically generate
Swagger based on annotations. GMAT generates
reports based on Swagger.

Figure 6 Visualized SDG using D3.js

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  .

Figure 7 Concepts of SIC extraction

After performing the previous method of finding SIC,


GMAT can detect the cyclic dependency problem using
Tarjan’s Strongly Connected Component algorithm [16].
Cycle dependency is potential design error, which may Figure 9 Highlighted failed service test in SDG
lead to resource dependency and competition and even The developer could browse the SDG with test
cause unlimited service calls to make the system function results to visually check the failed service calls. He/she
improperly or even crash. Figure 8 shows an example of could fix the bug by examining the service invocation
cyclic dependency. Sa, Sb, and Sc invoke one another to chain and identifying the error root.
construct a cycle. GMAT will highlight this kind of
problem in SDG. IV. EXPERIMENTAL EVALUATIONS
The scale of a MSA system could range from less
than ten microservices to hundreds of microservices (e.g.,
Netflix includes more than five hundreds microservices
[17, 18]). Therefore, we need to test the performance of
the GMAT system applied in various sized MSA-based
systems. Currently, we cannot obtain the source code and
configurations of real-world MSA-based systems, so that
we decide to generate a set of test data (See Table 1) to
perform simulation. The setup of the experiment was as
follows:
1. Generate 11 simulated MSA-based applications
Figure 8 The concept of cyclic dependency with various number of microservices: 10, 20, 30,
40, 50, 100, 200, 300, 400, 500, and 1000.
D. Calculation of Service Test Coverage 2. Generate service endpoints randomly according to
GMAT expects that developers test microservices the distribution of numbers of service endpoints for
based on Pact by using the PactProviderRule API and the services published in APIs.guru 3 , the most
applying annotations of PactVerification and Pact. popular public service repository.
PactProviderRule is Pact's mock service which is used to 3. Allocate service calls between microservices
verify the service call. PactVerification is executed by randomly according to the distribution of numbers
Pact and is expected to interact with the contract defined of service calls in the Netflix system.
in Pact. The Pact annotation is an interactive contract that
4. Create visualized SDG for each project and record
describes microservice capabilities expected. By using
the time spent.
the Reflection mechanism, GMAT can inspect the test
directory code of all microservice projects for a system, 5. Hardware and software configurations:
and determine whether all service calls have been tested z OS: Arch Linux
using Pact in the above way. After examination, the failed z CPU: Intel Core i7-4790
service calls will be highlighted (in yellow) in SDG (See z RAM: 16GB
Figure 9). z Software Version: Java 1.8, Spring Boot
1.5.2, and Neo4j 3.1.1

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

You might also like