GithubHelp home page GithubHelp logo

alex-k-7 / go_psql_redis_example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hamnsk/go_psql_redis_example

0.0 0.0 0.0 227 KB

This is an example of a simple microservice written in go use Postgres as database and Redis as cache.

Makefile 8.98% Go 88.11% Dockerfile 2.13% Shell 0.78%

go_psql_redis_example's Introduction

Caching in Go: Redis

This is an example of a simple microservice written in go. Microservice gives us the requested ID from the user database. After getting from the database, the query result is cached in Redis for 25 seconds. For logging, a zap is used, a gorilla / mux is selected as a router. For stack trace of errors use Sentry.

This example starts an http server on port 8080 at any available ip address.

Set APP_LOG_FILE=file_name environment variable for enable output logs in project dir to file_name.

Requirements

  1. Go 1.17
  2. PostgreSQL: either a remote instance, local binary or docker container.
  3. Redis: either a remote instance, local binary or docker container.
  4. Load testing data: included in this repo
  5. Benchmark tests: use a gobench tool
  6. Prometheus Metrics: about collected metrics
  7. Grafana Dashboards: recommended for use with this stack
  8. Kubernetes Probes: app k8s probes

Running

For the convenience of using all possible commands, a makefile has been prepared.

Download the required packages:

$ make deps

Then you can run this example with the PostgreSQL and Redis and importing testing data:

$ make run

PostgreSQL

This example Using Docker Container with Postgres 12

Good article from the report on how to work with Postgres from GO (rus).

An article about the speed of work of requests from the Postgres database with an increase in connections to it more than 100 (eng).

$ make postgres

Redis

This example Using Docker Container with Redis 6

$ make redis

Load testing data

This repository contains test data in the sql folder to demonstrate how the example works. The data was taken from here.

$ make initdb

Benchmark tests

The gobench tool is used for load testing.

First install tool by command:

$ make bench-install

Then you can use it with command:

$ make stress

Prometheus Metrics

For run and use ELK, Prometheus and Grafana run stack via docker-compose, before run make .env file with content:

DATABASE_URL=postgres://rexamp:password@pgbouncer:6432/redisexamp?sslmode=disable
REDIS=redis:6379 
SENTRY_DSN=your_sentry_dsn
$ make run-stack

For down this stack use:

$ make down-stack

For show running containers use:

$ make ps-stack
  • Prometheus collect metrics from go-redis-app at port 8081 on /metrics url
  • Also collect metrics from Redis, Pgbouncer and Fluent-Bit services by default settings for this services

Work with prometheus historgram on doc or blog post

Grafana Dashboards

Kubernetes Probes

Application export two url on monitoring port 8081 for k8s probes.

  • /live - for liveness probe, return 200 ok if live or 503 if dead
  • /ready - for readiness probe, return 200 ok if live and read to working or 503 if live and not ready to working

go_psql_redis_example's People

Contributors

hamnsk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.