Reader small image

You're reading from  Go Programming - From Beginner to Professional - Second Edition

Product typeBook
Published inMar 2024
Reading LevelBeginner
PublisherPackt
ISBN-139781803243054
Edition2nd Edition
Languages
Right arrow
Author (1)
Samantha Coyle
Samantha Coyle
author image
Samantha Coyle

Samantha Coyle, a Software Engineer at Diagrid, specializes in Go for cloud-native developer tooling, abstracting application development challenges. Committed to Open Source, she contributes to projects like Dapr and Testcontainers. She boasts a rich history in retail computer vision solutions and successfully stabilized industrial edge use cases with testing and diverse deployments for biopharma data pipelines. Her expertise extends to being CKAD certified and reviewing Go textbooks. She is passionate about empowering early-career, diverse professionals. Samantha is in a family of gophers, and enjoys GopherCon with her brother and identical twin sister. She's a seasoned speaker, having presented at various conferences, including GopherCon.
Read more about Samantha Coyle

Right arrow

Go in the Cloud

Overview

This chapter will show you how to take your Go application to the next level of readiness for deployment. It will cover the considerations you have to make your Go application run reliably once deployed to your server or cloud infrastructure by demonstrating how to add monitoring capabilities to the system through an open source monitoring and alerting toolkit known as Prometheus. The chapter will also discuss how to run your application using an orchestrator and all of the benefits you get out of the box. Lastly, the chapter will cover insights that OpenTelemetry allows, as well as best practices for containerizing your Go application code.

By the end of this chapter, you will be empowered to deploy your Go application reliably, and with valuable insights into the system to ensure its success.

Technical requirements

For this chapter, you'll require Go version 1.21 or higher. The code for this chapter can be found at https://github.com/PacktPublishing/Go-Programming-From-Beginner-to-Professional-Second-Edition-/tree/main/Chapter21.

Introduction

In the previous chapter, you learned about the various Go tools that enable developers to write better code and be more productive. We covered the Go tools to compile and run your Go code using the go build and go run commands. We then looked at how to format Go code using gofmt. We also saw the power of working with the Go ecosystem through its dependencies with the goimports and go get command-line tools. After having functional dependencies in our code, we can see issues that might be present using the Go vet tool and the Go race detector. Lastly, with any good code comes a well-rounded project through proper documentation using the Go doc tool. The previous chapter empowered you with the tools right at your fingertips in the Go ecosystem.

In this chapter, we focus on the fact that at some point in a project, your application development journey will lead you to the final frontier: deploying the application. But, before you hit the deploy button or run the final...

Making your app monitorable by systems such as Prometheus

Monitoring is a critical aspect of maintaining the health and performance of any application, no matter the language. Monitoring is especially important in a cloud-native environment where resources are dynamic and distributed. There are certain nuances as to the differences between monitoring and observability in software engineering.

The monitoring aspects abide more by collecting data through predefined metrics and thresholds to detect and alert upon issues to define the overall health of the system, whereas observability is much more investigative and goes into a more comprehensive understanding of system behavior and performance to enable effective debugging and troubleshooting in complex environments. To focus on enabling monitoring capabilities and insights into the health of our application, we will focus on monitoring instead of observability in this book chapter.

Prometheus is a powerful tool when it comes to...

Enabling deep insights through OpenTelemetry

In today’s complex distributed systems landscape, understanding how our applications behave and perform is crucial for maintaining reliability and performance. We will now take a look at another useful monitoring tool readily available. OpenTelemetry is a pivotal tool for gaining profound insights into the functionality and performance of distributed systems. OpenTelemetry, often referred to as OTel, provides a standardized approach to collect and correlate data across various components of the system.

By incorporating OpenTelemetry into your Go applications, you can seamlessly capture telemetry data, including traces, metrics, and logs, to gain a holistic understanding of your system’s operation. Let’s take a look at the three main pillars OpenTelemetry encompasses:

  • Tracing allows us to track the flow of requests as they travel through different services and components, providing invaluable insights into...

Best practices for putting your Go application in a container

In recent years, containerization has revolutionized the way software engineers deploy and manage software applications. By encapsulating an application along with its dependencies into a lightweight, portable container, containerization provides numerous benefits, including consistency, scalability, and portability for our applications. This approach has gained widespread adoption across industries and is considered a standard practice for modern software development and deployment workflows.

Containerization is essential to software nowadays as it ensures consistency by packaging the application and its dependencies into a single unit, eliminating the infamous and dreaded “it works on my machine” problem This consistency extends to different environments, including production, reducing the risk of configuration drift. It also allows scalability on demand, as it is efficient to add or remove instances of...

Making your app ready to work with orchestrators such as Kubernetes

Kubernetes, often abbreviated as K8s, has emerged as the de facto standard for container orchestration and management. It provides the capabilities to automate the deployment, scaling, and management of containerized applications. At its core, Kubernetes abstracts away the complexities of managing individual containers and offers a unified API and control plane for orchestrating containerized workloads across a cluster of machines. Orchestrators such as Kubernetes are what you turn to when you want to streamline the deployment and management of modern, cloud-native applications.

In today’s dynamic and rapidly evolving software landscape, where microservices architectures and containerization have become mainstream, Kubernetes offers a scalable and resilient platform for deploying and operating these distributed applications. However, it is not without its complexities and learning curve.

There are a few...

Summary

This chapter was an exciting one that expanded our understanding of where we are running the Go applications that we write. We learned how to run our Go code in the cloud, all packaged up nicely and providing us with the monitoring insights that we need to ensure success for our services.

We started with understanding why and how to make our Go application code instrumented with monitoring using Prometheus. That was a nice segue into gaining even richer insights into our application using OpenTelemetry. We then demonstrated how to containerize our application using Docker, and then looked at how to run that containerized application in an orchestrated environment, such as in Kubernetes. We’ve covered a lot of ground in this chapter and in this book in its entirety.

Over the course of the book, we have covered the basics of Go with variables and various type declarations. We moved into control flow and data rules with Go, to include some of the newest features of...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Go Programming - From Beginner to Professional - Second Edition
Published in: Mar 2024Publisher: PacktISBN-13: 9781803243054
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Samantha Coyle

Samantha Coyle, a Software Engineer at Diagrid, specializes in Go for cloud-native developer tooling, abstracting application development challenges. Committed to Open Source, she contributes to projects like Dapr and Testcontainers. She boasts a rich history in retail computer vision solutions and successfully stabilized industrial edge use cases with testing and diverse deployments for biopharma data pipelines. Her expertise extends to being CKAD certified and reviewing Go textbooks. She is passionate about empowering early-career, diverse professionals. Samantha is in a family of gophers, and enjoys GopherCon with her brother and identical twin sister. She's a seasoned speaker, having presented at various conferences, including GopherCon.
Read more about Samantha Coyle