Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Develop #6

Merged
merged 26 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0fab7b6
count points
lucbellicaud Mar 31, 2023
759ae4d
alert symbol instead of abbrevation
lucbellicaud Apr 3, 2023
2ba39b8
Squashed commit of the following:
lucbellicaud Apr 6, 2023
ca9b168
DDS lead
lucbellicaud Apr 12, 2023
54ff53b
feat: Add otel into development docker-compose
zdraganov Apr 13, 2023
10399da
Fix small cards dds 2
lucbellicaud Apr 13, 2023
4b6006d
Merge branch 'develop' of https://github.com/Seven-of-Di/ben into dev…
lucbellicaud Apr 13, 2023
9a1e5f0
test lead
lucbellicaud Apr 13, 2023
2660d36
Merge branch 'staging' into develop
lucbellicaud Apr 13, 2023
80bd6eb
feat: Intrument Ben with Tracing for PlayCard flow
zdraganov Apr 13, 2023
481b0db
feat: Add integrnal loadtest package for simplify running loadtests
zdraganov Apr 14, 2023
6c2fc07
feat: Update the README.md for the loadtest package
zdraganov Apr 14, 2023
421ac69
fixed big bug : not taking pb into account
lucbellicaud Apr 17, 2023
103ae6b
Merge branch 'develop' of https://github.com/Seven-of-Di/ben into dev…
lucbellicaud Apr 17, 2023
421e035
Update transform_play_card.py
lucbellicaud Apr 17, 2023
760dd47
feat: Reconstructure the code and add more samples
zdraganov Apr 18, 2023
52269b4
optimize sample ordering
lucbellicaud Apr 18, 2023
97aa583
Clean up variables names + time tricking
lucbellicaud Apr 18, 2023
1f007e0
feat: Change to use hypercorn
zdraganov Apr 18, 2023
f8c6873
Add some tracers
lucbellicaud Apr 18, 2023
0814048
Merge branch 'develop' of https://github.com/Seven-of-Di/ben into dev…
lucbellicaud Apr 18, 2023
3297b54
feat: Make the number of leading samples configurable
zdraganov Apr 19, 2023
d1073b6
Less redoubles + fix tracer of dds
lucbellicaud Apr 19, 2023
e111c6e
Merge branch 'develop' of https://github.com/Seven-of-Di/ben into dev…
lucbellicaud Apr 19, 2023
4ce4bbe
back to 100 samples
lucbellicaud Apr 19, 2023
4cbd2cb
feat: Include game information in the traces attributes
zdraganov Apr 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ services:
build: .
user: root
# command: python api.py
command: python create_alerts_database.py
# command: python create_alerts_database.py
command: hypercorn --bind 0.0.0.0:5001 --workers 4 api:app
ports:
- 8081:8081
- 5001:5001
volumes:
- ./src:/app/src
- ./build/alerts_db:/var/lib/alerts_db
Expand All @@ -23,5 +24,16 @@ services:
- PORT=5001
- DEBUG=true
- USE_RELOADER=true
- OTEL_EXPORTER_OTLP_TRACES_INSECURE=True
- OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=otel:4317
- OTEL_SERVICE_NAME=robot
networks:
- ben

otel:
image: jaegertracing/opentelemetry-all-in-one:latest
ports:
- "4317"
- "16686:16686"
networks:
- ben
26 changes: 26 additions & 0 deletions examples/play_card_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"hand": "KT7.9.KT643.875",
"dummy_hand": ".AJ754.A52.AQ94",
"dealer": "S",
"vuln": "E-W",
"contract": "3N",
"contract_direction": "S",
"auction": [
"PASS",
"PASS",
"1H",
"PASS",
"1S",
"PASS",
"2C",
"PASS",
"2N",
"PASS",
"3N",
"PASS",
"PASS",
"PASS"
],
"next_player": "W",
"tricks": [["SJ", "S3", "S2", "S4"]]
}
31 changes: 31 additions & 0 deletions examples/play_card_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"hand": "Q82.KQ863.9.JT63",
"dummy_hand": "65.AJ75.AQ.AQ94",
"dealer": "S",
"vuln": "E-W",
"contract": "3N",
"contract_direction": "S",
"auction": [
"PASS",
"PASS",
"1H",
"PASS",
"1S",
"PASS",
"2C",
"PASS",
"2N",
"PASS",
"3N",
"PASS",
"PASS",
"PASS"
],
"next_player": "E",
"tricks": [
[
"SJ",
"C2"
]
]
}
12 changes: 12 additions & 0 deletions loadtest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Loadtesting tool for Robot API ##

### How to use ###
1. Install dependency using [poetry](https://github.com/python-poetry/poetry).
```sh
$ poetry install
```

2. Help
```sh
$ python loadtest/command.py --help
```
Empty file added loadtest/loadtest/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions loadtest/loadtest/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import click
from play_card import PlayCardTest

@click.command()
@click.option('--threads', default=1, help='Number of parallel threads to run the load from', type=int)
@click.option('--count', help='Total count of requests to make', type=int)
@click.option('--url', help='The URL to execute the test agaist')
def play_card(threads, count, url):
PlayCardTest(threads=threads, count=count, url=url).execute()

if __name__ == '__main__':
play_card()
70 changes: 70 additions & 0 deletions loadtest/loadtest/play_card.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import concurrent
from concurrent.futures import ThreadPoolExecutor
import time
import requests
import json

class PlayCardTest:
def __init__(self, threads, count, url) -> None:
self.threads = threads
self.count = count
self.url = url

def execute(self):
completion_times = []

with ThreadPoolExecutor(max_workers=self.threads) as executor:
futures = [executor.submit(send_request, self.url, json_data) for i in range(self.count)]

for future in concurrent.futures.as_completed(futures):
data = future.result()
completion_times.append(data)

executor.shutdown()

average_request_time = round(sum(completion_times) / len(completion_times), 2)

print('Took {} seconds in average per request to complete'.format(average_request_time))


def send_request(url, json_data) -> float:
start = time.time()
res = requests.post('{}/play_card'.format(url), json=json_data)

return time.time()-start

json_data = {
"hand": "KT7.9.KT643.875",
"dummy_hand": ".AJ754.A52.AQ94",
"dealer": "S",
"vuln": "E-W",
"contract": "3NS",
"contract_direction": "S",
"auction": [
"PASS",
"PASS",
"1H",
"PASS",
"1S",
"PASS",
"2C",
"PASS",
"2H",
"PASS",
"3H",
"PASS",
"3N",
"PASS",
"PASS",
"PASS"
],
"next_player": "W",
"tricks": [
[
"SJ",
"S3",
"S2",
"S4"
]
]
}
181 changes: 181 additions & 0 deletions loadtest/poetry.lock

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions loadtest/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.poetry]
name = "loadtest"
version = "0.1.0"
description = ""
authors = ["Zhivko Draganov <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.8"
click = "^8.1.3"
requests = "^2.28.2"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Empty file added loadtest/tests/__init__.py
Empty file.
38 changes: 34 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
tensorflow==2.11.0
aiofiles==23.1.0
asgiref==3.6.0
blinker==1.6.2
certifi==2022.12.7
click==8.1.3
Deprecated==1.2.13
h11==0.14.0
h2==4.1.0
hpack==4.0.0
hypercorn==0.14.3
hyperframe==6.0.1
importlib-metadata==6.0.1
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.2
opentelemetry-api==1.17.0
opentelemetry-sdk==1.17.0
opentelemetry-exporter-otlp-proto-grpc==1.17.0
opentelemetry-instrumentation==0.38b0
opentelemetry-instrumentation-asgi==0.38b0
opentelemetry-semantic-conventions==0.38b0
opentelemetry-util-http==0.38b0
pickle5==0.0.11
priority==2.0.0
protobuf==3.19.0
psutil==5.9.4
quart==0.18.3
hypercorn==0.14.3
sentry-sdk==1.16.0
psutil==5.9.4
sqlitedict==2.1.0
pickle5==0.0.11
tensorflow==2.11.0
toml==0.10.2
typing_extensions==4.5.0
urllib3==1.26.15
Werkzeug==2.2.3
wrapt==1.15.0
wsproto==1.2.0
zipp==3.15.0

4 changes: 4 additions & 0 deletions resp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"card": "S4",
"claim_the_rest": false
}
1 change: 0 additions & 1 deletion src/Sequence.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations
from dataclasses import dataclass
from functools import cache
import logging

from utils import Direction, BiddingSuit
Expand Down
20 changes: 19 additions & 1 deletion src/api.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
from copy import deepcopy
from typing import Dict, List
from quart import Quart, request
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware

from nn.models import MODELS
from game import AsyncBotBid, AsyncBotLead
from FullBoardPlayer import AsyncFullBoardPlayer
from health_checker import HealthChecker
from alerting import find_alert

from opentelemetry import trace
from tracing import tracing_enabled
import numpy as np

import os
import sentry_sdk
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware

from sentry_sdk.integrations.asgi import SentryAsgiMiddleware

from transform_play_card import get_ben_card_play_answer
from human_carding import lead_real_card
Expand All @@ -30,6 +35,7 @@

app = Quart(__name__)
app.asgi_app = SentryAsgiMiddleware(app.asgi_app)._run_asgi3
app.asgi_app = OpenTelemetryMiddleware(app.asgi_app)

health_checker = HealthChecker(app.logger)
health_checker.start()
Expand Down Expand Up @@ -123,6 +129,17 @@ async def play_card():
# app.logger.warn(data)
req = PlayCard(data)

if tracing_enabled:
current_span = trace.get_current_span()
current_span.set_attributes({
"game.next_player": req.next_player,
"game.hand": req.hand,
"game.dummy_hand": req.dummy_hand,
"game.contract": req.contract,
"game.contract_direction": req.contract_direction,
"game.tricks": ",".join(np.array(req.tricks).flatten().tolist()),
})

dict_result = await get_ben_card_play_answer(
req.hand,
req.dummy_hand,
Expand All @@ -135,6 +152,7 @@ async def play_card():
req.tricks,
MODELS
)

"""
dict_result = {
"card": "H4",
Expand Down
Loading