Skip to content

Commit

Permalink
Merge pull request #74 from skalenetwork/add-historic-metrics
Browse files Browse the repository at this point in the history
Add historic metrics
  • Loading branch information
dmytrotkk authored Sep 24, 2024
2 parents 9a5cb63 + 5f55cd6 commit 95f4e5f
Show file tree
Hide file tree
Showing 28 changed files with 1,353 additions and 120 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ jobs:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python 3.7
uses: actions/setup-python@v1
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.7
python-version: 3.12
cache: 'pip'
- name: Build and publish container
run: |
export BRANCH=${GITHUB_REF##*/}
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/test_metrics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test metrics
on: [push, pull_request]

jobs:
test_proxy:
defaults:
run:
working-directory: metrics
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.12]
env:
ETH_ENDPOINT: ${{ secrets.ETH_ENDPOINT }}
PYTHONPATH: ${{ github.workspace }}/metrics
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install python dependencies
run: pip install -r requirements.txt && pip install -r requirements-dev.txt
- name: Lint with ruff
run: ruff check src/
- name: Run metrics tests
run: pytest tests/
18 changes: 5 additions & 13 deletions .github/workflows/test.yml → .github/workflows/test_proxy.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
name: Test
name: Test proxy
on: [push, pull_request]

jobs:
test_proxy:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]
python-version: [3.12]
env:
ETH_PRIVATE_KEY: ${{ secrets.ETH_PRIVATE_KEY }}
ENDPOINT: ${{ secrets.ENDPOINT }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
MANAGER_TAG: "1.9.3-beta.0"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install python dependencies
run: bash ./scripts/install_python_dependencies_dev.sh
- name: Lint with flake8
run: flake8 .
# - name: Deploy manager contracts
# run: |
# bash ./helper-scripts/install_python_dependencies_dev.sh
# - name: Run tests
# run: |
# bash ./scripts/run_manager_tests.sh
# - name: Codecov
# run: |
# codecov -t $CODECOV_TOKEN
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ metrics.json
conf/upstreams/*.conf
conf/chains/*.conf

portal-metrics.log
portal-metrics.log

mysql_data/
tools/
.ruff_cache/
.DS_Store
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ JSON-RPC endpoints for SKALE chains. It is based on NGINX.
3. Export all required environment variables (see below)
4. Run `scripts/run_proxy.sh`

#### Pre-commit hook

```bash
ruff check --config metrics/pyproject.toml metrics/src/
```

#### Format code

```bash
ruff format src/
```

#### Required environment variables

- `ETH_ENDPOINT` - endpoint of the Ethereum network where `skale-manager` contracts are deployed
Expand Down
39 changes: 36 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:
skale-proxy:
environment:
Expand All @@ -20,8 +19,9 @@ services:
max-file: "5"
max-size: "200m"
restart: unless-stopped

nginx:
image: nginx:1.20.2
image: nginx:1.24.0
container_name: proxy_nginx
network_mode: host
volumes:
Expand All @@ -34,10 +34,15 @@ services:
options:
max-file: "200"
max-size: "500m"

metrics:
environment:
ETH_ENDPOINT: ${ETH_ENDPOINT}
NETWORK_NAME: ${NETWORK_NAME}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_HOST: db
MYSQL_DATABASE: metrics
image: metrics:latest
container_name: metrics
build:
Expand All @@ -50,4 +55,32 @@ services:
options:
max-file: "5"
max-size: "50m"
restart: unless-stopped
restart: unless-stopped
depends_on:
- db
networks:
- proxy

db:
image: mysql:8.0
container_name: db
restart: always
environment:
- MYSQL_DATABASE=metrics
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
volumes:
- mysql_data:/var/lib/mysql
- ./mysql-init:/docker-entrypoint-initdb.d
networks:
- proxy
ports:
- "3306:3306"

volumes:
mysql_data:

networks:
proxy:
driver: bridge
9 changes: 7 additions & 2 deletions metrics/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
FROM python:3.12.3-bookworm

RUN apt-get update
RUN apt-get update && apt-get install -y \
default-mysql-client \
build-essential \
libssl-dev \
libffi-dev \
python3-dev

RUN mkdir /usr/src/metrics /data
WORKDIR /usr/src/metrics
Expand All @@ -13,4 +18,4 @@ COPY . .
ENV PYTHONPATH="/usr/src/metrics"
ENV COLUMNS=80

CMD python /usr/src/metrics/src/main.py
CMD ["python", "/usr/src/metrics/src/main.py"]
12 changes: 12 additions & 0 deletions metrics/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[tool.ruff]
line-length = 100
indent-width = 4
lint.select = ["Q"]

target-version = "py312"

[tool.ruff.format]
quote-style = "single"

[tool.ruff.lint.flake8-quotes]
inline-quotes = 'single'
5 changes: 5 additions & 0 deletions metrics/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ruff==0.6.4
pytest==8.3.3
Faker==28.4.1
eth-typing==4.1.0
pytest-aiohttp==1.0.5
8 changes: 6 additions & 2 deletions metrics/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
web3==6.19.0
requests==2.32.3
web3==6.15.1
requests==2.31.0
aiohttp==3.9.3
peewee==3.17.1
PyMySQL==1.1.0
cryptography==42.0.5
Loading

0 comments on commit 95f4e5f

Please sign in to comment.