📢 3 Tools to Improve Your Code Quality: GitHub Codespaces, Kubernetes, and Skyramp 🚀

📢 3 Tools to Improve Your Code Quality: GitHub Codespaces, Kubernetes, and Skyramp 🚀

Dec 4, 2023

3 Tools to Improve Your Code Quality: GitHub Codespaces, Kubernetes, and Skyramp

#github #kubernetes #testing #vscode

In the world of developing distributed applications with microservices, code quality is paramount. It can make the difference between a well-functioning application, and one that's prone to bugs and vulnerabilities. To help you maintain and improve your code quality, we'll explore three powerful tools in this blog: GitHub Codespaces, Kubernetes, and Skyramp. You’ll be able to try this combo for yourself with an instant dev environment.

Putting the Pieces Together

In previous blog posts, we covered using GitHub Codespaces for debugging, generating tests in a Kubernetes cluster, and running Skyramp's built-in dashboard to manage test results. In this blog, we’ll bring the pieces together to show how you can use all these tools to construct and run test scenarios for your system-under-test.

A Word about Component Testing

Within the space beyond unit testing and prior to end-to-end testing, there is a critical stage known as component testing. This infodeck on Martin Fowler's website covering testing strategies for microservices describes component testing this way:

"In a microservice architecture, the components are the services themselves. By writing tests at this granularity, the contract of the API is driven through tests from the perspective of a consumer."

When you're developing a distributed application with microservices, it's essential to ensure that each component functions correctly, both in isolation as well as when integrated with other components. Component testing is the key to ensuring this, and Skyramp is here to assist you in this endeavor.

Instant Dev Environment

GitHub Codespaces can be used to provide a cloud-based, integrated development environment that makes it easier to set up and run your tests with Skyramp. You can clone your repository, create a dedicated Codespace for your microservices, and then execute tests. A straightforward testing workflow is crucial to identify and fix issues early in the development process, saving you time and reducing headaches in the long run.

Here are some benefits of using GitHub Codespaces for component testing:

  • On-Demand Environments: Easily spin up a development environment for your microservices project, reducing setup time and eliminating conflicts between dependencies.

  • Consistency: Ensure that all developers work in identical environments, reducing the "it works on my machine" problem.

  • Collaboration: Multiple developers can collaborate on the same project without worrying about where to setup and run environments.

  • Easy Test and Debug: Run tests and debug seamlessly within the Codespace environment using a familiar VSCode interface.

We've prepared a GitHub Codespace from a branch of the Skyramp sample-microservices repo on GitHub. This branch is based on the Online Boutique demo project from Google Cloud. The project is a web-based e-commerce store that consists of an 11-tier microservices application. Skyramp added support for REST, which we will use for the example in this blog.

The GitHub Codespace can be launched from the link below and then clicking "Create Codespace".

That will setup a VSCode environment within the browser that looks like this:

Kubernetes Clusters in GitHub Codespaces

For microservices to function as a cohesive system, you need a way to test their interaction in a realistic environment. This is where Kubernetes comes into play. Kubernetes allows you to manage containerized applications in clusters, making it a perfect fit for deploying and testing microservices.

We will be using the Online Boutique application mentioned earlier for our example, which is built around Kubernetes. Skyramp can then be utilized to easily deploy and test the distributed app consisting of various microservices. We have created tests in the repo for testing 4 primary components of the application - Product Catalog, Cart, Payment, and Checkout.

Let's get started by changing the directory in the terminal of the Codespace to skyramp/rest-demo:

cd skyramp/rest-demo

Then, we'll create a new Kubernetes cluster with the Skyramp CLI:

skyramp cluster create -l

Expected output:

Creating local cluster     [##############################################################] 100 %
Successfully created local cluster.
Starting/restarting Resolver     [##############################################################] 100 %
Resolver manages DNS changes needed to access the cluster and needs sudo access.
[sudo] updating file /etc/resolv.conf

Next, let's bring up the system using Skyramp Deployer:

skyramp deployer up rest-app

Expected output:

email-service-745ddcd9c4-6zf8s                 ready
frontend-6f8fc574f7-w6hgb                      ready
product-catalog-service-5467566c8f-5n86m       ready
skyramp-worker-6c8bfdf587-bpf9m                ready
cart-service-56cd75c447-kshpg                  ready
currency-service-5b966cbfb8-tffff              ready
ad-service-7cb787976d-ldjm7                    ready
payment-service-5f9b47cfd4-26r9d               ready
redis-6fc54f68c4-fwg75                         ready
recommendation-service-6f8cd558b8-6cppj        ready
checkout-service-c5546db56-vdxld               ready
shipping-service-599947db74-flqhq              ready
All pods are ready

The system-under-test is now up and running. We have prepared several test scenarios which will be easy to run and then review the results with Skyramp.

A Complement of Tests

Quality assurance is not limited to early unit tests and final end-to-end tests. You need a comprehensive suite of tests, which include functional integration and performance tests, as well as the component tests highlighted earlier. This is where Skyramp completes the picture. Skyramp is an automated testing platform that can help you create and manage a wide range of tests for this stage of development.

Skyramp takes a modular approach to testing, as illustrated below with examples taken from the testing scenario we used for this blog.

  • Endpoints: Skyramp will use endpoint definitions for networking details of services used in tests as shown in this endpoint YAML file:

version: v1
services:
    - name: product-catalog-service
      port: 60000
      alias: product-catalog-service
      protocol: rest
endpoints:
  - name: product-catalog-service-get-products
    path: "/get-products"
    serviceName: product-catalog-service
    methods:
      - type: 'GET'
        name: get-products
  • Scenarios: Skyramp uses scenario definitions for request behavior of service methods or chains of requests, and specific asserts within test scenarios:

version: v1
scenarios:
  - name: scenario_123
    steps:
      - requestName: listProductsRequest
      - asserts: requests.listProductsRequest.res[0].id == "OLJCESPC7Z"
      - requestName: addCartRequest
      - asserts: requests.addCartRequest.res.success == "200 OK"
      - requestName: getCartRequest
      - asserts: requests.getCartRequest.res.user_id == "abcde"
      - requestName: chargeRequest
      - asserts: requests.chargeRequest.res.transaction_id != null
      - requestName: checkoutRequest
      - asserts: requests.checkoutRequest.res.items[0].item.product_id == "OLJCESPC7Z"
  • Tests: Skyramp uses test definitions as a starting point to execute the proper behavior of tests:

version: v1
test:
  name: "[REST] Checkout system load test testcase"
  target: rest-app
  testPattern:
    - startAt: 1s
      atOnce: 2
      scenarioName: scenario1
      duration: 10s

Running the Test, Checking the Results

We’ve found it incredibly valuable to have a central dashboard that aggregates and visualizes the results of your tests so you can get the most out of these tools, and ensure that your code quality is continually improving. Skyramp provides just that, and it can be run in GitHub Codespaces! Let's fire up the Skyramp Dashboard and run our test scenario against the services in the cluster.

Back to the Codespaces terminal, run this command:

skyramp dashboard up

Click "Open in Browser" from the dialog box popup regarding port forwarding and you will see the Skyramp Dashboard interface in a new browser tab. Click on "Tests". There will be no tests yet to display, but we can change that. Back to the Codespace tab, run Skyramp Tester in the terminal to execute our full-system test:

skyramp tester start full-system -n test-rest-demo

Now back to the Skyramp Dashboard tab in the browser and you will see the results of the test run there:

Looks like a passing grade! Notice the cells in the table can be expanded to view details of the test results.

You can explore further and even tweak the tests by checking out the YAML files in the endpoints, scenarios, and tests folders under skyramp/rest-demo. Also, visit the Skyramp Docs to learn more about all the functionality available for testing with Skyramp.

The Power of 3

By combining GitHub Codespaces, Kubernetes, and Skyramp, especially with a robust testing dashboard, you can ensure that your code quality remains high throughout the development lifecycle. As a result, your applications will be more reliable, ultimately leading to greater user satisfaction and a stronger competitive edge in the landscape of microservices-based distributed apps. As always, happy testing!

For more info, visit: Skyramp.dev & Join the Skyramp Community Discord

© 2024 Skyramp, Inc. All rights reserved.

© 2024 Skyramp, Inc. All rights reserved.

© 2024 Skyramp, Inc. All rights reserved.