Giter Club home page Giter Club logo

ukgovernmentbeis.beis-opss-infrastructure's Introduction

Infrastucture

Used by cosmetics and Product Safety Database (psd). Provides extra dependencies for managing infrastructure. Currently everything is deployed so in normal circumstances, this repo won't have much use, but it is still essencial to familiarize yourself with README to understand how infrastructure is done and managed.

Environment variables

We're using user-provided services to load environment variables into our applications. Running get-env-from-vcap.sh as part of the application startup will add credentials from any service named *-env to the current environment.

Domains

We've setup our domains based on the instructions provided by PaaS. This also enables a CDN for the URL so it's important that the Cache-Control header is being set correctly. For each domain, we define a <<SPACE>> and <<SPACE>>-temp subdomain for hosting and blue-green deployments. It's important that we also allow the Authorization header through the CDN for the basic auth on non-production environments. The following command can be used to create the cdn-route service:

cf create-service cdn-route cdn-route opss-cdn-route -c '{"domain": "<<domain1>>,<<domain2>>", "headers": ["Authorization"]}'

Logging

Fluentd

We're using fluentd to aggregate the logs and send them to both an ELK stack and S3 bucket for long term storage.

Deployment

Create or target a common space using cf create-space common or cf target -o beis-opss -s common.

Deploy the fluentd app by running cf push --no-start --hostname <fluentd hostname> from the fluentd folder. <fluentd hostname> can be anything but the full domain will be used again below.

Once the app has been created, add the following environment variables for the Logit and S3 credentials. The values can be found on the respective websites.

cf set-env fluentd AWS_ACCESS_KEY_ID XXX
cf set-env fluentd AWS_SECRET_ACCESS_KEY XXX
cf set-env fluentd AWS_REGION XXX
cf set-env fluentd AWS_S3_BUCKET XXX
cf set-env fluentd LOGIT_STACK_ID XXX
cf set-env fluentd LOGIT_PORT XXX

Once the environment variables are set, start the app using cf start fluentd.

To start sending logs from an application, create a log drain on the specific space using cf cups opss-log-drain -l https://<fluentd domain from above> Then bind the service to each application using e.g. cf bind-service cosmetics-web opss-log-drain.

Logit

We're using Logit as a hosted ELK stack. If you want to view the logs, you'll need an account - ask someone on the team to invite you. You should sign up using GitHub OAuth to ensure MFA.

logstash-filters.conf provides a set of rules which logstash can use to parse logs.

We're using ElastAlerts within Logit to track the logs and send alerts in certain scenarios (eg. a spike in unsuccessful file uploads). The config files for these alerts can be found in the elastalert folder. Please note the email address and the Slack webhook URL are placeholder values and will need updating. These values can be obtained from the existing alerts on Logit.

S3

We're using AWS S3 as a long term storage for logs. See the root README for more details about setting up an account.

Monitoring

Metrics

Our metrics are sent to an ELK stack and S3 using the paas-metric-exporter app.

We have set up a regular job to query the database and to print certain metrics into the logs. This was all done in PR #962. The metrics are sent in JSON format and logstash is clever enough to split these out into separate logs for each key-value pair. However, you will need to add an extra filter in logstash-filters.conf, in order to create new fields on the logs instead of the data all being captured in the message field.

Deployment

Create or target a common space using cf create-space common or cf target -o beis-opss -s common.

Deploy the app by running cf push --no-start from the paas-metric-exporter folder. Once the app has been created, define the following environment variables:

Set the metrics to be logged to stdout using:

cf set-env metric-exporter DEBUG true

Tell the app to connect to the London PaaS API

cf set-env metric-exporter API_ENDPOINT https://api.london.cloud.service.gov.uk

Provide some credentials (these should be for a user with only the "Space auditor" permission on the spaces to be monitored) to connect to the API with:

cf set-env metric-exporter USERNAME XXX
cf set-env metric-exporter PASSWORD XXX

Follow the instructions above to create and bind the opss-log-drain to the metric-exporter app.

Finally, start the app using cf start metric-exporter. Running cf logs metric-exporter should show metrics from all of the spaces that the user has the "Space auditor" permission for.

Uptime check

We're using UptimeRobot to perform a regular uptime check on our website. If you want to receive emails, ask someone on the team to add you to the list of "Alert Contacts".

Sentry

We're using Sentry to monitor exceptions. If you want to view the exceptions, you'll need an account - ask someone on the team to invite you. You should sign up using GitHub OAuth to ensure MFA.

ukgovernmentbeis.beis-opss-infrastructure's People

Contributors

slawosz 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.