Saga Documentation 0.9.434-4

Architecture Overview

Saga is developed in Javascript ES6 and based on node.js v14. It’s based on a flat architecture and relies on 5 core components that are derived from a single codebase. The only core dependencies are MongoDB 4.2 for data storage, Rabbit MQ for inter-component messaging and Redis for socket session management.

Overview

Each component is addressable and usable as a docker image, they all based on a single docker image hexagram/saga_base since they share a large part of the codebase among each other. The docker image size is based on a multi-stage build for extremely light docker images. Each component is started with its individual npm command. Each component can also be provided as it’s own docker-image with the command baked in.

  • hexagram/saga_base/http
  • hexagram/saga_base/udp
  • hexagram/saga_base/script
  • hexagram/saga_base/scheduler
  • hexagram/saga_base/job

The docker images are hosted in a private repository on docker.com.

Each component is independently scalable and do not need to live in the same environment as long as each component has access to Rabbit MQ, MongoDB and Redis.

Below is an example docker-compose configuration to start the system locally with an added nginx proxy for the HTTP API.

version: '3'
Services:

   rabbitmq:
       image: hexagram/rabbitmq 
       logging:
           driver: none
       ports:
           - 5672
       
   mongodb:
       image: mongo:4.2
       volumes:
         - ../data/db:/data/db:delegated
       ports:
           - 27017:27017
       command: mongod --smallfiles --bind_ip_all --noauth --quiet   
              
   redis:
       image: redis
       ports:
           - 6379     
       logging:
           driver: none

   nginx:
     build: ./docker/nginx/  
     ports:
       - 88:80
       - 488:443
     volumes:
       - ./server/localhost/certs/:/etc/nginx/ssl/
       - ./server/localhost/conf/:/etc/nginx/sites-enabled/
       - ./logs/:/var/log/nginx/


   web:
       image: hexagram/saga_base                 
       ports:
           - 3000:3000        
       env_file: .env_dev     
       volumes:
           - ./logs:/logs          
       environment:
           - PORT=3000           
           - REDIS_URL=redis
           - MONGOHQ_URL=mongodb://mongodb/dev
           - CLOUDAMQP_URL=amqp://guest:guest@rabbitmq:5672 
           - DEBUG=hexos/chat,hexos/properties,hexos/queue

       command:  npm run dev_web

   udp:
       image: hexagram/saga_base                                
       ports:
           - "3005:3005/udp"           
       env_file: .env_dev     
       volumes:
           - ./logs:/logs
       command:  npm run dev_udp

   clock:
       image: hexagram/saga_base
       env_file: .env_dev  
       volumes:
           - ./logs:/logs         
       command:  npm run dev_clock
  
   job:
       image: hexagram/saga_base    
       env_file: .env_dev   
       volumes:
           - ./logs:/logs           
       command: npm run job

   script:
       image: hexagram/saga_base
       depends_on:   
           - rabbitmq        
           - redis 
           - mongodb     
       env_file: .env_dev
       volumes:
           - ./logs:/logs                  
       command: npm run script

Configuration

Configuration is supplied over environment variables supplied to the container at startup time. List of environment variables

Chatbots

Hexagram chatbots are deployed as individual docker images, they have an update mechanisms to pull new content from Github using SSL keys and various life cycle commands that are accessible via the SAGA HTTP API to ping, rebuild and investigate.

Logging

By default saga uses standard file logging. This can be changed to log to S3 or an ELK System. The saga component make heavy use of a hierarchical category logging system to fine-tune the logging output.

New Relic

Saga can be configured to post data to NewRelic for application behavior insights.