Merge pull request #194 from albertoxamin/dev

Add datadog monitoring
This commit is contained in:
Alberto Xamin 2022-03-25 00:36:58 +01:00 committed by GitHub
commit bc1d18d91c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 3 deletions

View File

@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.7"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
@ -17,6 +17,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
cd backend
pip install --user -r requirements.txt
pip install pylint
- name: Analysing the code with pylint
run: |

View File

@ -1,3 +1,4 @@
# pylint: skip-file
class DodgeCity():
def get_characters():

View File

@ -395,6 +395,7 @@ class FucileDaCaccia(Card):
else:
return False
# pylint: disable=function-redefined
def get_starting_deck() -> List[Card]:
cards = [
Barile(Suit.CLUBS, 'A'),

View File

@ -134,6 +134,7 @@ class DocHolyday(Character):
return True
return False
# pylint: disable=function-redefined
def all_characters() -> List[Character]:
cards = [
PixiePete(),

View File

@ -63,6 +63,7 @@ class Player:
self.committed_suit_manette = None
self.not_chosen_character = None
try:
# pylint: disable=no-member
del self.win_status
except:
pass

View File

@ -7,4 +7,5 @@ python-socketio==4.6.1
six==1.16.0
pytest==7.1.1
requests==2.27.1
discord-webhook==0.15.0
discord-webhook==0.15.0
datadog==0.44.0

View File

@ -1,5 +1,6 @@
import os
import json
import time
import random
from typing import List
import eventlet
@ -10,6 +11,17 @@ from bang.players import Player, PendingAction
import requests
from discord_webhook import DiscordWebhook
from datadog import initialize, api
send_metrics = False
if "DATADOG_API_KEY" in os.environ and "DATADOG_APP_KEY" in os.environ:
initialize()
send_metrics = True
api.Event.create(title="Backend start", text="", tags=["server:backend", f"host:{os.environ['HOST']}"], alert_type="info")
else:
print("Datadog not configured")
import sys
sys.setrecursionlimit(10**6) # this should prevents bots from stopping
@ -43,6 +55,8 @@ blacklist: List[str] = []
def advertise_lobbies():
sio.emit('lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players), 'locked': g.password != ''} for g in games if not g.started and len(g.players) < 10 and not g.is_hidden])
sio.emit('spectate_lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players), 'locked': g.password != ''} for g in games if g.started])
if send_metrics:
api.Metric.send(metric='lobbies', points=[(int(time.time()), len(games))], tags=["server:backend", "type:lobbies", f"host:{os.environ['HOST']}"])
@sio.event
def connect(sid, environ):
@ -51,6 +65,8 @@ def connect(sid, environ):
print('connect ', sid)
sio.enter_room(sid, 'lobby')
sio.emit('players', room='lobby', data=online_players)
if send_metrics:
api.Metric.send(metric='online_players', points=[(int(time.time()), online_players)], tags=["server:backend", f"host:{os.environ['HOST']}"])
@sio.event
def get_online_players(sid):
@ -73,6 +89,8 @@ def report(sid, text):
sio.emit('chat_message', room=sid, data={'color': f'green','text':f'Report OK'})
else:
print("WARNING: DISCORD_WEBHOOK not found")
if send_metrics:
api.Event.create(title="BUG REPORT", text=data, tags=["server:backend", f"host:{os.environ['HOST']}"])
print(f'New bug report, replay at https://www.toptal.com/developers/hastebin/{key}')
@sio.event
@ -156,6 +174,8 @@ def disconnect(sid):
games.pop(games.index(sio.get_session(sid).game))
print('disconnect ', sid)
advertise_lobbies()
if send_metrics:
api.Metric.send(metric='online_players', points=[(int(time.time()), online_players)], tags=["server:backend", f"host:{os.environ['HOST']}"])
@sio.event
def create_room(sid, room_name):
@ -263,11 +283,15 @@ def start_game(sid):
ses: Player = sio.get_session(sid)
ses.game.start_game()
advertise_lobbies()
if send_metrics:
api.Metric.send(metric='start_game', points=[(int(time.time()), 1)], tags=["server:backend", f"host:{os.environ['HOST']}", [f"exp:{e}" for e in ses.game.expansions]])
@sio.event
def set_character(sid, name):
ses: Player = sio.get_session(sid)
ses.game.rpc_log.append(f'{ses.name};set_character;{name}')
if send_metrics:
api.Metric.send(metric='set_character', points=[(int(time.time()), 1)], tags=["server:backend", f"host:{os.environ['HOST']}", f"char:{name}"])
ses.set_character(name)
@sio.event

View File

@ -479,7 +479,7 @@ def test_saloon():
assert p.lives == p.max_lives
# test WellsFargo
def test_diligenza():
def test_wells_fargo():
sio = DummySocket()
g = Game('test', sio)
ps = [Player(f'p{i}', f'p{i}', sio) for i in range(4)]