Skip to content

Commit

Permalink
fixing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
l0k0ms committed Oct 11, 2018
1 parent 1fd6e26 commit e143afb
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 11 deletions.
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ services:
- DD_APM_ANALYZED_SPANS=users-api|express.request=1,sensors-api|flask.request=1,pumps-service|flask.request=1,iot-frontend|flask.request=1
- DD_TAGS='env:workshop'
- DD_PROCESS_AGENT_ENABLED=true
- DD_AC_EXCLUDE='image:agent'
- DD_LOGS_ENABLED=true
- DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true

ports:
- "8126:8126"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /proc/:/host/proc/:ro
- /sys/fs/cgroup/:/host/sys/fs/cgroup:ro
- /etc/passwd:/etc/passwd:ro
- /opt/datadog-agent/run:/opt/datadog-agent/run:rw

labels:
com.datadoghq.ad.logs: '[{"source": "docker", "service": "agent"}]'

Expand All @@ -40,7 +41,7 @@ services:
depends_on:
- db
labels:
com.datadoghq.ad.logs: '[{"source": "iot-frontend", "service": "iot-frontend"}}]'
com.datadoghq.ad.logs: '[{"source": "frontend", "service": "frontend"}]'

noder:
container_name: "noder"
Expand Down
Binary file modified frontend/__pycache__/api.cpython-37.pyc
Binary file not shown.
24 changes: 21 additions & 3 deletions frontend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

from ddtrace import tracer, patch, config
from ddtrace.contrib.flask import TraceMiddleware
from ddtrace.ext.priority import USER_REJECT, USER_KEEP
import logging
import subprocess
import random

# Tracer configuration
tracer.configure(hostname='agent')
tracer.configure(hostname='agent', priority_sampling=True)
tracer.set_tags({'env': 'workshop'})
patch(requests=True)

Expand Down Expand Up @@ -84,9 +86,25 @@ def call_generate_requests():
str(payload['total']) + ' requests total.',
'url': payload['url']})

# generate requests for one user to see tagged
# enable user sampling because low request count
@app.route('/generate_requests_user')
def call_generate_requests_user():
users = requests.get('http://noder:5004/users').json()
user = random.choice(users)
span = tracer.current_span()
span.context.sampling_priority = USER_KEEP
span.set_tags({'user_id': user['id']})

output = subprocess.check_output(['/app/traffic_generator.py',
'20',
'100',
'http://noder:5004/users/' + user['uid']])
app.logger.info(f"Chose random user {user['name']} for requests: {output}")
return jsonify({'random_user': user['name']})

@app.route('/simulate_sensors')
def simulate_sensors():
sensors = requests.get('http://sensors:5002/refresh_sensors').json()
#app.logger.info(f"Simulating sensors {sensors}")
app.logger.info(f"LOOOL")
app.logger.info(f"Simulating sensors {sensors}")
return jsonify(sensors)
2 changes: 1 addition & 1 deletion frontend/static/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en" dir="ltr"><head><meta charset="utf-8"><meta name="viewport" content="minimum-scale=1,initial-scale=1,width=device-width,shrink-to-fit=no"><meta name="theme-color" content="#000000"><title>Datadog APM Water Management Example</title><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"/></head><body><div id="root"></div><script type="text/javascript" src="/static/js/main.df577d7c.js"></script></body></html>
<!doctype html><html lang="en" dir="ltr"><head><meta charset="utf-8"><meta name="viewport" content="minimum-scale=1,initial-scale=1,width=device-width,shrink-to-fit=no"><meta name="theme-color" content="#000000"><title>Datadog APM Water Management Example</title><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"/></head><body><div id="root"></div><script type="text/javascript" src="/static/js/main.5bb1c4b6.js"></script></body></html>
2 changes: 2 additions & 0 deletions frontend/static/js/main.5bb1c4b6.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/static/js/main.5bb1c4b6.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/static/js/service-worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed images/.DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion iot-devices/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM arm64v8/python:3.7.0-alpine3.8
# uncomment below for arm container (runs on macos w/ no issues)
#FROM arm64v8/python:3.7.0-alpine3.8
FROM python:3.7.0-alpine3.8

RUN apk add build-base eudev-dev openzwave openzwave-dev cython postgresql-dev
COPY requirements.txt /app/requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion log_workshop_instructions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
" frontend:\n",
" (...)\n",
" labels:\n",
" com.datadoghq.ad.logs: '[{\"source\": \"iot-frontend\", \"service\": \"iot-frontend\"}}]'\n",
" com.datadoghq.ad.logs: '[{\"source\": \"iot-frontend\", \"service\": \"iot-frontend\"}]'\n",
"\n",
" noder:\n",
" (...)\n",
Expand Down
11 changes: 11 additions & 0 deletions node-api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async function addUsers() {
else {
console.log('creating ' + user.uid)
const created = await hmsetAsync('user-' + user.uid, {
'id': user.id,
'uid': user.uid,
'name': user.name,
'demand_gph': user.demand_gph,
Expand Down Expand Up @@ -90,6 +91,16 @@ app.post('/users', async (req, res) => {
}
})

app.get('/users/:userId/', async (req, res) => {
try {
const userId = req.params.userId
const user = await hgetallAsync('user-' + userId)
return res.json(user)
} catch (e) {
res.sendStatus(500)
}
})

app.post('/users/:userId/concurrent-users/:userCount(\\d+)', async (req, res) => {
try {
const userCount = parseInt(req.params.userCount)
Expand Down
4 changes: 3 additions & 1 deletion sensors/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM arm64v8/python:3.7.0-alpine3.8
# uncomment below for arm container (runs on macos w/ no issues)
#FROM arm64v8/python:3.7.0-alpine3.8
FROM python:3.7.0-alpine3.8

RUN apk add build-base eudev-dev openzwave openzwave-dev cython postgresql-dev
COPY requirements.txt /app/requirements.txt
Expand Down
12 changes: 12 additions & 0 deletions single-page-frontend/src/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Grid from '@material-ui/core/Grid';
import Button from '@material-ui/core/Button';
import TextField from '@material-ui/core/TextField';
import Snackbar from '@material-ui/core/Snackbar';
import purple from '@material-ui/core/colors/purple';
import axios from 'axios';
import { isNumber } from 'recharts/lib/util/DataUtils';

Expand Down Expand Up @@ -205,6 +206,14 @@ class Dashboard extends React.Component {
}
}

handleUserRequestConcurrent = (e) => {
e.preventDefault()
axios.get(rootURL + "/generate_requests_user",
{crossdomain: true}).then(response => {
this.setState({requestsOpen: true, requestCount: 100})
})
}

handleUserSubmit = (e) => {
e.preventDefault()
axios.post(rootURL + '/users', this.state.newUser, {crossdomain: true}).then(response => {
Expand Down Expand Up @@ -384,6 +393,9 @@ class Dashboard extends React.Component {
<br /><Button id="300" className={classes.trafficButton} size="large" variant="contained" color="secondary" onClick={this.handleRequestConcurrent}>
300 users @ 30 concurrent requests
</Button>
<br /><Button id="100" style={{backgroundColor: purple[500]}} className={classes.trafficButton} size="large" variant="contained" color="secondary" onClick={this.handleUserRequestConcurrent}>
Generate Requests for Random User
</Button>
</Paper>
</Grid>
</main>
Expand Down

0 comments on commit e143afb

Please sign in to comment.