Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/docker/docker/main/python-3.13.0-…
Browse files Browse the repository at this point in the history
…slim-bookworm
  • Loading branch information
ArneTR authored Nov 3, 2024
2 parents e7ae7ff + 799aac7 commit 4830476
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 40 deletions.
39 changes: 19 additions & 20 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
.DS_Store
__pycache__
config.yml
config.js
docker/nginx/api.conf
docker/nginx/frontend.conf
docker/nginx/block.conf
docker/nginx/ssl/*
!docker/nginx/ssl/README.md
frontend/js/helpers/config.js
sftp-config.json
/config.yml
/docker/nginx/api.conf
/docker/nginx/frontend.conf
/docker/nginx/block.conf
/docker/nginx/ssl/*
!/docker/nginx/ssl/README.md
/frontend/js/helpers/config.js
/sftp-config.json
TODO
flows
docker/compose.yml
/docker/compose.yml
metric-provider-binary
.vscode
static-binary
.pytest_cache
test-compose.yml
tests/structure.sql
tools/sgx_enable
venv/
lib/hardware_info_root.py
tools/cluster/cleanup.sh
node_modules/
lib/c/parse_int.o
tools/backup
/docker/test-compose.yml
/tests/structure.sql
/tools/sgx_enable
/venv/
/lib/hardware_info_root.py
/tools/cluster/cleanup.sh
/node_modules/
/lib/c/parse_int.o
/tools/backup
/manager-config.yml
1 change: 1 addition & 0 deletions api/api_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def get_timeline_query(uri, filename, machine_id, branch, metrics, phase, start_
{detail_name_condition}
{limit_365_condition}
AND r.commit_timestamp IS NOT NULL
AND r.failed IS FALSE
ORDER BY
p.metric ASC, p.detail_name ASC,
p.phase ASC, {sorting_condition}
Expand Down
14 changes: 12 additions & 2 deletions cron/carbondb_compress.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import faulthandler
faulthandler.enable() # will catch segfaults and write to stderr

import os

from lib.global_config import GlobalConfig
from lib.db import DB
from lib import error_helpers
Expand All @@ -10,8 +12,15 @@
# During this process we also transform all text fields and transform them to integers and drop them into normalized
# joined tables.

########### Remove NULL values from tags
# UPDATE carbondb_data_raw
# SET tags = array_remove(tags, NULL)
# WHERE array_position(tags, NULL) IS NOT NULL;


def compress_carbondb_raw():
query = '''
INSERT INTO carbondb_types (type, user_id)
SELECT DISTINCT type, user_id
FROM carbondb_data_raw
Expand Down Expand Up @@ -39,7 +48,7 @@ def compress_carbondb_raw():
DROP TABLE IF EXISTS carbondb_data_raw_tmp;
CREATE TABLE carbondb_data_raw_tmp AS
CREATE TEMPORARY TABLE carbondb_data_raw_tmp AS
SELECT * FROM carbondb_data_raw;
UPDATE carbondb_data_raw_tmp AS cdrt
Expand Down Expand Up @@ -92,7 +101,7 @@ def compress_carbondb_raw():
DATE_TRUNC('day', TO_TIMESTAMP(cdr.time / 1000000)),
SUM(cdr.energy_kwh),
SUM(cdr.carbon_kg),
(SUM(cdr.carbon_kg)*1e3) / SUM(cdr.energy_kwh), -- weighted average instead of just averaging carbon_intensity
COALESCE(SUM(cdr.carbon_kg)*1e3 / NULLIF(SUM(cdr.energy_kwh), 0), 0), -- weighted average instead of just averaging carbon_intensity. Since the solar panel might not be producing power at all for a day, which results in 0, we need to COALESCE and insert 0 in this case
COUNT(*),
cdr.user_id
FROM
Expand All @@ -119,6 +128,7 @@ def compress_carbondb_raw():

if __name__ == '__main__':
try:
GlobalConfig().override_config(config_location=f"{os.path.dirname(os.path.realpath(__file__))}/../manager-config.yml")
compress_carbondb_raw()
except Exception as exc: # pylint: disable=broad-except
error_helpers.log_error(f'Processing in {__file__} failed.', exception=exc, machine=GlobalConfig().config['machine']['description'])
5 changes: 4 additions & 1 deletion cron/carbondb_copy_over_and_remove_duplicates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import faulthandler
faulthandler.enable() # will catch segfaults and write to stderr

import os

from lib.global_config import GlobalConfig
from lib.db import DB
from lib import error_helpers
Expand Down Expand Up @@ -75,7 +77,7 @@ def validate_table_constraints():
FROM
information_schema.columns
WHERE
table_name = 'carbondb_data_raw' -- replace 'your_table' with the table name
table_name = 'carbondb_data_raw'
AND column_name IN ('user_id', 'time', 'energy_kwh', 'carbon_kg', 'carbon_intensity_g', 'type', 'project', 'machine', 'source', 'tags')
''')

Expand Down Expand Up @@ -105,6 +107,7 @@ def remove_duplicates():

if __name__ == '__main__':
try:
GlobalConfig().override_config(config_location=f"{os.path.dirname(os.path.realpath(__file__))}/../manager-config.yml")
copy_over_eco_ci()
copy_over_gmt()
remove_duplicates()
Expand Down
8 changes: 4 additions & 4 deletions docker/compose.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ services:
- 9142:9142
restart: always
volumes:
- green-coding-shared-tmp:/tmp
- green-coding-shared-sockets:/tmp/gmt-sockets
- PATH_TO_GREEN_METRICS_TOOL_REPO:/var/www/green-metrics-tool:ro
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx/api.conf:/etc/nginx/conf.d/api_nginx.conf:ro
Expand All @@ -57,7 +57,7 @@ services:
- green-coding-postgres
restart: always
volumes:
- green-coding-shared-tmp:/tmp
- green-coding-shared-sockets:/tmp/gmt-sockets
- PATH_TO_GREEN_METRICS_TOOL_REPO:/var/www/green-metrics-tool:ro
# - TEST_CONFIG_SETUP:/var/www/green-metrics-tool/config.yml

Expand All @@ -71,10 +71,10 @@ services:


# Although it would help us very much performance-wise the
# Shared volume with only temporary data, green-coding-shared-tmp, must be
# Shared volume with only temporary data, green-coding-shared-sockets, must be
# of type overlayfs and cannot be tmpfs (https://docs.docker.com/storage/tmpfs/)
# tmpfs being a RAM stored and faster volume is sadly not shareable between containers
volumes:
green-coding-postgres-data:
green-coding-shared-tmp:
green-coding-shared-sockets:
green-coding-redis-data:
2 changes: 1 addition & 1 deletion docker/nginx/api.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ server {
}

location / {
proxy_pass http://unix:/tmp/green-coding-api.sock;
proxy_pass http://unix:/tmp/gmt-sockets/api.sock;
# Do not change this
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
Expand Down
6 changes: 3 additions & 3 deletions docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
gunicorn==23.0.0
psycopg[binary]==3.2.3
psycopg_pool==3.2.3
fastapi[standard]==0.115.2
fastapi[standard]==0.115.4
starlette>=0.35
uvicorn[standard]==0.32.0
pandas==2.2.3
PyYAML==6.0.2
anybadge==1.14.0
orjson==3.10.9
orjson==3.10.10
scipy==1.14.1
schema==0.7.7
deepdiff==8.0.1
redis==5.1.1
redis==5.2.0
hiredis==3.0.0
requests==2.32.3
uvicorn-worker==0.2.0
2 changes: 1 addition & 1 deletion docker/startup_gunicorn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source /var/www/startup/venv/bin/activate
--error-logfile=- \
--worker-tmp-dir=/dev/shm \
--worker-class=uvicorn_worker.UvicornWorker \
--bind unix:/tmp/green-coding-api.sock \
--bind unix:/tmp/gmt-sockets/api.sock \
-m 007 \
--user www-data \
--chdir /var/www/green-metrics-tool/api \
Expand Down
9 changes: 8 additions & 1 deletion frontend/js/carbondb.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ const fillBarChart = (y_axis, legend, labels, series) => {
return `<strong>${escapeString(labels[params.componentIndex].date)}</strong><br>
Type: ${escapeString(labels[params.componentIndex].type)}<br>
Value: ${escapeString(labels[params.componentIndex].value)} ${escapeString(labels[params.componentIndex].unit)}<br>
Project: ${escapeString(labels[params.componentIndex].project)}<br>
Machine: ${escapeString(labels[params.componentIndex].machine)}<br>
Source: ${escapeString(labels[params.componentIndex].source)}<br>
Tags: ${escapeString(labels[params.componentIndex].tags)}<br>
`;
}

Expand Down Expand Up @@ -220,6 +223,10 @@ const processData = (measurements) => {
carbon_barchart_data.labels.push({
type: dimensions_lookup['types'][type],
date: date,
project: dimensions_lookup['projects'][project],
machine: dimensions_lookup['machines'][machine],
source: dimensions_lookup['sources'][source],
tags: tags.map( el => dimensions_lookup['tags'][el]),
value: carbon,
unit: 'kg',
})
Expand Down
4 changes: 2 additions & 2 deletions frontend/js/helpers/config.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ const phase_time_metric_condition = (metric) => {
return false;
}

const machine_carbon_metric_condition = (metric) => {
if(metric.match(/^.*_carbon_.*_machine$/) !== null) return true;
const psu_machine_carbon_metric_condition = (metric) => {
if(metric.match(/^psu_carbon_.*_machine$/) !== null) return true;
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/js/helpers/metric-boxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ const updateKeyMetric = (phase, metric_name, clean_name, detail_name, value, std
selector = '.software-carbon-intensity';
} else if(machine_power_metric_condition(metric_name)) {
selector = '.machine-power';
} else if(machine_carbon_metric_condition(metric_name)) {
} else if(psu_machine_carbon_metric_condition(metric_name)) {
selector = '.machine-co2';
} else {
return; // could not match key metric
Expand Down
2 changes: 1 addition & 1 deletion frontend/js/helpers/phase-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const displayComparisonMetrics = (phase_stats_object) => {
bottom_chart_present_keys[key] = true
}

if (phase_stats_object.comparison_case == null && machine_carbon_metric_condition(metric_name)) {
if (phase_stats_object.comparison_case == null && psu_machine_carbon_metric_condition(metric_name)) {
if(co2_calculated) {
showWarning(phase, 'CO2 was already calculated! Do you have multiple machine energy reporters set?');
}
Expand Down
2 changes: 1 addition & 1 deletion metric_providers/psu/energy/ac/xgboost/machine/model
Submodule model updated from ac7e30 to 8cff92
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
pydantic==2.9.2
pytest==8.3.3
pylint==3.3.1
pytest-randomly==3.15.0
pytest-randomly==3.16.0
pytest-playwright==0.5.2
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ schema==0.7.7
aiohttp==3.10.10

# calibration script dep
tqdm==4.66.5
tqdm==4.66.6
plotext==5.3.2
docker==7.1.0

0 comments on commit 4830476

Please sign in to comment.