Kieran Spear
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# Ops Exercises ## Bastion Logs Bastion is our front-router, which means it is the entrypoint into our system for all requests to 99designs.com (and other domains). It is bastion's job to direct requests to other 99designs services according to the path in the request URL (e.g., `/accounts/login` goes to the `accounts` service). You might have heard the term reverse-proxy before - this is essentially what bastion does. The service where the request is sent is often called a "backend." For every request, Bastion logs information about both the request received and the response sent back that can be used to see things like: - The client's IP - The URL (sometimes called the "path" or "route") - The backend that handled the request - The HTTP code of the response (e.g., `200` for OK, `5xx` for server errors) - How long the response took to send Bastion logs are structured in JSON lines format, where each line is a separate JSON object. Each JSON object looks something like this: ```json { "id": "01FC4YB069ME1S3MDCGYJM61HA", "request": { "99seshID": "01FC4MW5GWT5MJ0KT6BZAGQ4B5", "acceptEncoding": "gzip, deflate, br", "clientIp": "200.100.205.30", "cookieLength": 2486, "effectiveUserId": "xxx", "geoIpCountry": "ID", "host": "99designs.com", "method": "GET", "remoteAddress": "103.162.205.30:24080", "sid": "017b0658-f38c-fe53-b414-7342c668445e", "url": "/app/graphql", "userAgent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36", "userId": "xxx", "vid": "01746002-0f02-3321-1b31-841e73ff9ea3" }, "response": { "backend": "spa_backend", "bodyBytes": 0, "code": 101, "duration": 0.004678575, "hostname": "ip-10-2-1-84.ec2.internal", "timeToFirstByte": 0.004677327, "version": "c3b967c4dd958439b32d91d5701597853fe958b3" }, "time": "2021-08-03T12:44:00+10:00" } ``` You can view these logs with the `99cli logs` command: ```shell aws-vault exec platform -- 99cli logs --filter '{$.response.backend = "start"}' --from="2021-08-08 09:30:00" --to="2021-08-08 09:50:00" --format '{{ .request.clientIp }}' /bastion/access.log | sort | uniq -c | sort -hr ``` The above example will show how many requests were made by each unique IP to the `start` backend. The `/bastion/access.log` refers to a `log group` configured in AWS that receives logs from all of our running Bastion instances. Start by copying the `99cli` command above and adjusting the `from` and `to` values to search from "10 minutes ago" to "1 year in the future". 1. How would you find the top user agents that are hitting the `blog` backend? 2. What about the most popular urls for the `accounts` backend? 3. Go to https://99designs.com.au/user/profile, login and note your user ID in the URL bar. Adjust the `filter` and `format` options to show logs for your user ID, printing the backend and the URL. Note: Since we want to see every request in this case, there's no need to pipe the output to `sort` or `uniq`. ## Dashboards As you've seen above, while we can answer some questions using `99cli` and filtering logs, the whole process is a bit fiddly. Usually much of the same information is available on dashboards in our Datadog tool: https://app.datadoghq.com/ All services should have dashboards available that show important metrics relating to the health of a service. Things like: - Request volume - Response time - Error counts - Resource usage (Container count, CPU, Memory, Connections, Network Bandwidth) - Aggregated trace information (more on this in the next section) Scenario: It's just after midnight on the 28th of July, and you receive an alert complaining about a high number of open connections from Bastion. This links you to the following dashboard in Datadog: https://app.datadoghq.com/dashboard/6ha-bjk-iuj/bastion?from_ts=1627393584926&to_ts=1627403066407&live=false 1. Which backend(s) does Bastion have high numbers of connections to, relative to the other backends? 2. With the backend(s) in mind, do any other graphs stick out? What are they telling you about the health of the backend services? 3. What are some other places you might look to dig into this further? ## Traces Bastion logs are useful for finding out about the types of requests that are coming in and which backend is serving them, but they don't give you much insight into what the backend actually did with the request apart from generic things like duration and error code. For this we can use tracing. Tracing relies on services sending events when they do something interesting. These events are called `spans`, as they usually wrap an operation that the service is performing. Which spans are sent can be service-specific, as usually the service needs to be instrumented specifically to send them. The most basic span a service sends is usually from the start to the end of a response to a single request. A service might also send a span every time it queries its database, so you know how much of the response time was spent querying data. The real power with traces comes when different services are all sending spans as they handle a particular request. For one request, `bastion` might forward the request to `projects`, which then talks to another service `messages` to get some data. If all these services are sending spans, our tooling can collate them and show the interaction between services. This lets you answer questions like: why is this particular route sometimes very slow? While the Bastion logs (and dashboards) can tell you *which* backend is having performance problems, they don't usually give you insight into *why* when the problem is deeper inside a service or dependent on the exact shape of a request. Traces allow you to drill down on a per-request level to find the exact service or operation that is responsible for the problem. Here's a live example you can find in production: 1. From the Bastion dashboard, find the "top resources" pane: https://app.datadoghq.com/dashboard/6ha-bjk-iuj/bastion 2. Click on `GET /profiles/*`, which is usually the top resource, then click `View related traces` in the context menu. 3. Click on one of the lines in the table to see the flame graph for this request. In tracing, a single request consists of many nested "spans" sent from each service that does work to handle the request. Datadog collates these into the view you see here. Hover over or click on each span to get further information. What does the flame graph tell you about the relationship between `workbench` and `bastion`? 5. Now, let's try to find some slow requests... close the current trace and look to the left of the list of spans. There you'll see facet controls that you can use to select a subset of spans. Try moving the lower bound for `Duration` up to around 2/3rds of the max duration shown (most likely a few seconds). 6. The list of spans now just shows the slower requests. Click on a span to get more detail. The flame graph probably looks quite different, and can be difficult to read with a large number of spans. 7. Click on the "Span List" tab to get an aggregated list of spans with their count and durations. Can you identify why this response is taking longer? Hint: there are N+1 reasons.

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully