Skip to content

Commit

Permalink
Merge branch 'develop' into 224-pause-ponggame
Browse files Browse the repository at this point in the history
  • Loading branch information
massahito authored Oct 20, 2024
2 parents d7699c0 + b247aa3 commit 0c6dfe0
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 34 deletions.
4 changes: 4 additions & 0 deletions .devcontainer/.env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ DJANGO_SUPERUSER_PASSWORD=django_superuser_password
DJANGO_SUPERUSER_EMAIL=django_superuser_email
NGINX_ORIGIN=nginx_origin
DJANGO_2FA_ISSUER=2fa_issuer
GF_SECURITY_ADMIN_USER="fuga"
GF_SECURITY_ADMIN_PASSWORD="fuga"
DISCORD_WEBHOOK="#TODO"

23 changes: 12 additions & 11 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ services:
- .env

prometheus:
image: "prom/prometheus"
build:
context: ./requirements/Prometheus/
dockerfile: ./Containerfile
ports:
- "9090:9090"
volumes:
- type: bind
source: ./requirements/Prometheus/
target: /etc/prometheus/
- type: volume
source: prometheus_data
target: /prometheus
command: "--config.file=/etc/prometheus/prometheus.yaml"
depends_on:
app:
condition: service_healthy
restart: always
env_file:
- .env

grafana:
image: "grafana/grafana-oss"
Expand All @@ -104,20 +104,21 @@ services:
app:
condition: service_healthy
restart: always
env_file:
- .env

alertmanager:
image: "prom/alertmanager"
build:
context: ./requirements/Alertmanager/
dockerfile: ./Containerfile
ports:
- "9093:9093"
volumes:
- type: bind
source: ./requirements/Alertmanager/
target: /etc/alertmanager/
command: "--config.file=/etc/alertmanager/alertmanager.yaml"
depends_on:
app:
condition: service_healthy
restart: always
env_file:
- .env

nginx-exporter:
image: "nginx/nginx-prometheus-exporter"
Expand Down
13 changes: 13 additions & 0 deletions .devcontainer/requirements/Alertmanager/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM prom/alertmanager:latest

# スクリプトをコンテナにコピー
ADD ./entrypoint.sh /usr/local/bin/entrypoint.sh

# 実行権限を付与
USER root
RUN chmod +x /usr/local/bin/entrypoint.sh

# エントリポイントを指定
ENTRYPOINT ["entrypoint.sh"]

CMD ["/bin/alertmanager", "--config.file=/alertmanager/alertmanager.yml", "--storage.path=/alertmanager/data"]
12 changes: 0 additions & 12 deletions .devcontainer/requirements/Alertmanager/alertmanager.yaml

This file was deleted.

17 changes: 17 additions & 0 deletions .devcontainer/requirements/Alertmanager/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
cat << EOF > /alertmanager/alertmanager.yml
global:
route:
group_wait: 5s
group_interval: 5s
repeat_interval: 1h
receiver: 'discord'
receivers:
- name: 'discord'
discord_configs:
- webhook_url: '${DISCORD_WEBHOOK}'
EOF

exec "$@"
15 changes: 15 additions & 0 deletions .devcontainer/requirements/Prometheus/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM prom/prometheus:latest

# スクリプトをコンテナにコピー
COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh
COPY ./server-down.rules /etc/prometheus/server-down.rules

# 実行権限を付与
USER root
RUN chmod +x /usr/local/bin/entrypoint.sh

# エントリポイントを指定
ENTRYPOINT ["entrypoint.sh"]

CMD ["/bin/prometheus", "--config.file=/prometheus/prometheus.yml", "--storage.tsdb.path=/prometheus"]

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh
cat << EOF > /prometheus/prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_interval: 5s
evaluation_interval: 5s
external_labels:
monitor: 'codelab-monitor'
Expand All @@ -18,8 +20,8 @@ scrape_configs:
static_configs:
- targets: ['app:8000']
basic_auth:
username: '#TODO enter the same value as DJANGO_SUPERUSER_USERNAME in .env'
password: '#TODO enter the same value as DJANGO_SUPERUSER_PASSWORD in .env'
username: '${DJANGO_SUPERUSER_USERNAME}'
password: '${DJANGO_SUPERUSER_PASSWORD}'
- job_name: 'nginx'
static_configs:
- targets: ['nginx-exporter:9113']
Expand All @@ -29,3 +31,7 @@ alerting:
- static_configs:
- targets:
- 'alertmanager:9093'
EOF


exec "$@"
2 changes: 1 addition & 1 deletion .devcontainer/requirements/Prometheus/server-down.rules
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ groups:
# Alert for any instance that is unreachable for >30 seconds.
- alert: InstanceDown
expr: up == 0
for: 30s
for: 10s
labels:
severity: page
annotations:
Expand Down
9 changes: 5 additions & 4 deletions pong/chat/chat_consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ def send_initial_messages(self):
self.close()

def disconnect(self, close_code):
logger.info(f"Disconnecting from room: {self.room_name}")
async_to_sync(self.channel_layer.group_discard)(
self.room_group_name, self.channel_name
)
if hasattr(self, "room_group_name"):
async_to_sync(self.channel_layer.group_discard)(
self.room_group_name, self.channel_name
)

def receive(self, text_data):
text_data_json = json.loads(text_data)
Expand Down Expand Up @@ -240,6 +240,7 @@ def receive(self, text_data):
self.user, room, "退出しました。"
)
Rooms.objects.leave_room(self.user, room_id)

users = Rooms.objects.get_users_in_room(room_id)

users = [serialize_user(user) for user in users]
Expand Down
2 changes: 1 addition & 1 deletion pong/chat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_users_in_room(self, room_id):
)
return users
except self.model.DoesNotExist:
raise ValueError("指定された部屋が存在しません")
return []

def leave_room(self, user, room_uuid):
room = self.model.objects.get(uuid=room_uuid)
Expand Down
10 changes: 10 additions & 0 deletions pong/pong/static/pong/components/DirectoryContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ export class DirectoryContainer extends Component {
modalRoomName.textContent = room.name;
modal.style.display = "block";

confirmJoinButton.removeEventListener(
"click",
this.eventListeners.confirmJoinButtonListener,
);
cancelJoinButton.removeEventListener(
"click",
this.eventListeners.cancelJoinButtonListener,
);
window.removeEventListener("click", this.eventListeners.modalClickListener);

this.eventListeners.confirmJoinButtonListener = () => {
if (this.socket && this.socket.readyState === WebSocket.OPEN) {
const joinRequest = {
Expand Down
2 changes: 1 addition & 1 deletion pong/reaction_game/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.conf.urls.static import static
from .views import get_user_match_result

app_name = "realtime_pong_game"
app_name = "reaction_game"
urlpatterns = [
path(
"api/v1/match-result/<str:name>",
Expand Down

0 comments on commit 0c6dfe0

Please sign in to comment.