LinkitAir is a demo PoC of an online flights search application.
It consists on a REST API (Spring Boot) and a UI (Angular).
$ mkdir -p ~/.mongodb/data
$ docker run -d --name mongo -p 27017:27017 -v "${HOME}/.mongodb/data:/data/db" mongo
$ git clone https://github.com/lubumbax/linkitair.git
$ cd linkitair/flights-service
$ mvn clean spring-boot:run
$ git clone https://github.com/lubumbax/linkitair.git
$ cd linkitair/linkitair-web
$ npm install
$ ng serve
- Access LinkitAir at http://localhost:4200 and start searching flights.
- Access Swagger UI at http://localhost:8080/swagger-ui.html
$ cd linkitair
$ docker run -d --name prometheus -p 9090:9090 -v "$(pwd)/prometheus.yaml:/etc/prometheus/prometheus.yml" prom/prometheus
$ docker run -d --name grafana -p 3000:3000 grafana/grafana
- Access Grafana at http://localhost:3000 (username
admin
and paswordadmmin
). - Once in, follow "
Configuration
(left menu) >Datasources
>[Add data source]
>Prometheus
: {URL = http://host.docker.internal:9090
} >Save and Test
". - Once the data source has been created, follow "
Create
(+ on the left menu) >Import
> (paste the contents ofdashboard.json
) >[Load]
>Prometheus
: (select the Prometheus data source) >[Import]
".
LikitAir consists on a backend Spring Boot REST API serving data to a frontend Angular 8 UI.
These run each in its own process (and port/service).
It is possible to have the UI served by the Spring Boot process.
You can check that checking out to the feature/ui-in-boot
branch in this repository (see doc for that there).
The API is a Spring Boot application that serves flight information through a Spring MVC REST Controller.
The data is retrieved from MongoDB. This allows us to add data any time during the execution of the demo.
Here are the entities involved:
- Airport: identified uniquely by an airport
code
(eg "AMS
") and contains information asname
,city
,altitude
, ... - Flight: identified uniquely by a flight number (eg "
LK0003
") and contains afrom
andto
- Flight.AirportData: contain the
code
of an airport and adescription
attribute made with thecode
,name
andcity
of the actual Airport.
The Flight.AirportData.description
attribute is what the API will use in order to search flights by a given airport token.
The token could be just part of the name of a city, the name of the airport itself of just the airport code.
The UI is a basic Angular application that pulls flights information from the Spring Boot application.
It consists of a flights search page in which we can search available flights for a given "From" and "To" airports.
The page displays two flight search boxes that will dynamically be populated with the airports matching the characters entered.
Once an airport is selected, the search box "locks-in" with a light blue colour indicating that it is "ready" to search.
The Angular application is to be run from the command line with ng serve
.
It is possible to build it and embed it in the Spring Boot application.
See the ui-in-boot
branch to see how to do that.
- MongoDB
- Java 17
The easiest way to run MongoDB is probably launching it in a Docker container:
$ mkdir -p ~/.mongodb/data
$ docker run -d --name mongo -p 27017:27017 -v "${HOME}/.mongodb/data:/data/db" mongo
You may prefer running MongoDB locally as described in the following section.
$ brew install mongodb
To launch MongoDB manually:
$ mongod --config /usr/local/etc/mongod.conf
You may prefer to have launchd
auto-starting mongodb at login:
$ brew services start mongodb
The OOTB config looks something like this:
systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /usr/local/var/mongodb
net:
bindIp: 127.0.0.1
You can easily install MongoDB in Linux with one of the major distribution package systems (apt, rmp, ...). Eg.:
apt install mongodb
$ git clone <url of this repository>
$ cd linkitair/flights-service
$ mvn clean spring-boot:run
To return a list of flights from Amsterdam/Schiphol:
$ curl -v -G "http://localhost:8080/flights/from/AMS"
To return a list of flights from Amsterdam/Schiphol to Frankfurt/Frankfurt am Main:
$ curl -v -G "http://localhost:8080/flights/from/AMS/to/FRA"
Documentation about the endpoints and models is exposed by Swagger at http://localhost:8080/swagger-ui.html
Try to add a couple more flights:
$ mongo
> use linkitair;
> db.flights.insert({
"_id" : "XX666",
"from" : { "code" : "AMS", "description" : "AMS - Schiphol (Amsterdam)" },
"to" : { "code" : "MAD", "description" : "MAD - Bajaras (Madrid)" },
"time" : "23:59",
"price" : "1.0",
"_class" : "com.lubumbax.linkitair.flights.model.Flight"
});
> db.flights.insert({
"_id" : "XX000",
"from" : { "code" : "MAD", "description" : "MAD - Bajaras (Madrid)" },
"to" : { "code" : "AMS", "description" : "AMS - Schiphol (Amsterdam)" },
"time" : "00:00",
"price" : "1.0",
"_class" : "com.lubumbax.linkitair.flights.model.Flight"
});
$ git clone <url of this repository>
$ cd linkitair/linkitair-web
$ npm install
$ ng serve
Browse to http://localhost:4200
Try entering just "am" in the "From" search box. Both "AMS" and "FRA" will be found. Select "AMS".
Try entering just "fra" in the "To" search box. "FRA" will be found. Select "FRA".
Search the available flights.
On the Spring Boot API, Micrometer gathers metrics that are made available by Actuator under http://localhost:8080/actuator/metrics
Adding the dependency micrometer-registry-prometheus
is enough for Spring Boot to add a Prometheus metrics registry to MeterRegistry
.
Prometheus then can be configured to pull (scrape) the values of actuator metrics periodically and store them as time series values.
Then we can visualize data from Prometheus in a dashboard with Grafana.
The following steps assume that you have Docker running on your machine.
$ cd linkitair
$ docker run -d --name prometheus -p 9090:9090 -v "$(pwd)/prometheus.yaml:/etc/prometheus/prometheus.yml" prom/prometheus
Note: for some versions of Docker (or the driver used) the volume binding (-v
) feature doesn't work.
As a workaround, we can create our own prometheus image:
docker build -t lubumbax/prometheus -f - . << __EOF
FROM prom/prometheus
COPY prometheus.yaml /etc/prometheus/prometheus.yml
__EOF
docker run -d --name prometheus -p 9090:9090 lubumbax/prometheus
Once it is running, go to http://localhost:9090/targets and check that Prometheus lists the label linkitair_micrometer
.
That confirms that Prometheus is now pulling data from our Spring Boot application.
The following steps assume that you have Docker running on your machine.
$ docker run -d -p 3000:3000 grafana/grafana
- Access Grafana at http://localhost:3000 (username
admin
and paswordadmmin
). - Once in, follow "
Configuration
(left menu) >Datasources
>[Add data source]
>Prometheus
: {URL = http://host.docker.internal:9090
} >Save and Test
". - Once the data source has been created, follow "
Create
(+ on the left menu) >Import
> (paste the contents ofdashboard.json
) >[Load]
>Prometheus
: (select the Prometheus data source) >[Import]
".