Skip to content

Commit

Permalink
Merge branch 'main' into codespaces
Browse files Browse the repository at this point in the history
* main:
  New depencies for XGboost added
  add workflow to build codespace container
  Bump scipy from 1.11.3 to 1.11.4 (#548)
  Bump psycopg[binary] from 3.1.12 to 3.1.13 (#549)
  Fomantic update to 2.9.3 (#547)
  Allow digits in env var keys (#541)
  Hardware info root mac (#544)
  Trying if ref works
  Bump pydantic from 2.5.0 to 2.5.1 (#539)
  Adds the citation file (#537)
  HOG returned after mutliple loops
  Info button now works for page 2+ task coalitions
  Bump pydantic from 2.4.2 to 2.5.0 (#538)
  TDP typo
  Bump pandas from 2.1.2 to 2.1.3 (#534)
  Makes the root_hardware_info root writable only
  Hog API Fix for broken payload (#532)
  Adding report url instead of just ID (#531)
  Makes error optional except if there is data we need (#530)
  • Loading branch information
ArneTR committed Nov 21, 2023
2 parents 170c19e + 6410c67 commit 9c72d65
Show file tree
Hide file tree
Showing 39 changed files with 437 additions and 324 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests-vm-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: 'Checkout repository'
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
ref: ${{ github.ref }}
submodules: 'true'

- name: Eco CI Energy Estimation - Initialize
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ test-config.yml
tests/structure.sql
tools/sgx_enable
venv/
lib/hardware_info_root.py
30 changes: 30 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
cff-version: 1.2.0
title: Green Metrics Tool
message: >-
If you use this software, please cite it using the
metadata from this file.
type: software
authors:
- given-names: Arne
family-names: Tarara
email: [email protected]
affiliation: Green Coding Berlin
- given-names: Dan
family-names: Mateas
email: [email protected]
affiliation: Green Coding Berlin
- given-names: Geerd-Dietger
family-names: Hoffmann
email: [email protected]
affiliation: Green Coding Berlin
repository-code: 'https://github.com/green-coding-berlin/green-metrics-tool'
url: 'https://www.green-coding.berlin/'
repository: 'https://github.com/green-coding-berlin/'
abstract: >-
The Green Metrics Tool is a developer tool indented for
measuring the energy and CO2 consumption of software
through a software life cycle analysis (SLCA).
keywords:
- Green Coding
- 'Software Life Cycle Assessment '
license: AGPL-3.0-or-later
57 changes: 53 additions & 4 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from starlette.responses import RedirectResponse
from starlette.exceptions import HTTPException as StarletteHTTPException

from pydantic import BaseModel
from pydantic import BaseModel, ValidationError

import anybadge

Expand Down Expand Up @@ -576,6 +576,48 @@ def replace_nan_with_zero(obj):
return obj


def validate_measurement_data(data):
required_top_level_fields = [
'coalitions', 'all_tasks', 'elapsed_ns', 'processor', 'thermal_pressure'
]
for field in required_top_level_fields:
if field not in data:
raise ValueError(f"Missing required field: {field}")

# Validate 'coalitions' structure
if not isinstance(data['coalitions'], list):
raise ValueError("Expected 'coalitions' to be a list")

for coalition in data['coalitions']:
required_coalition_fields = [
'name', 'tasks', 'energy_impact_per_s', 'cputime_ms_per_s',
'diskio_bytesread', 'diskio_byteswritten', 'intr_wakeups', 'idle_wakeups'
]
for field in required_coalition_fields:
if field not in coalition:
raise ValueError(f"Missing required coalition field: {field}")
if field == 'tasks' and not isinstance(coalition['tasks'], list):
raise ValueError(f"Expected 'tasks' to be a list in coalition: {coalition['name']}")

# Validate 'all_tasks' structure
if 'energy_impact_per_s' not in data['all_tasks']:
raise ValueError("Missing 'energy_impact_per_s' in 'all_tasks'")

# Validate 'processor' structure based on the processor type
processor_fields = data['processor'].keys()
if 'ane_energy' in processor_fields:
required_processor_fields = ['combined_power', 'cpu_energy', 'gpu_energy', 'ane_energy']
elif 'package_joules' in processor_fields:
required_processor_fields = ['package_joules', 'cpu_joules', 'igpu_watts']
else:
raise ValueError("Unknown processor type")

for field in required_processor_fields:
if field not in processor_fields:
raise ValueError(f"Missing required processor field: {field}")

# All checks passed
return True

@app.post('/v1/hog/add')
async def hog_add(measurements: List[HogMeasurement]):
Expand All @@ -591,9 +633,16 @@ async def hog_add(measurements: List[HogMeasurement]):
#Check if the data is valid, if not this will throw an exception and converted into a request by the middleware
try:
_ = Measurement(**measurement_data)
except RequestValidationError as exc:
print(f"Caught Exception {exc}")
except (ValidationError, RequestValidationError) as exc:
print(f"Caught Exception in Measurement() {exc.__class__.__name__} {exc}")
print(f"Errors are: {exc.errors()}")
if GlobalConfig().config['admin']['no_emails'] is False:
email_helpers.send_admin_email('Hog parsing error', str(exc))

try:
validate_measurement_data(measurement_data)
except ValueError as exc:
print(f"Caught Exception in validate_measurement_data() {exc.__class__.__name__} {exc}")
raise exc

coalitions = []
Expand Down Expand Up @@ -752,7 +801,7 @@ async def hog_add(measurements: List[HogMeasurement]):
)
DB().fetch_one(query=query, params=params)

return Response(status_code=204) # No-Content
return Response(status_code=204) # No-Content


@app.get('/v1/hog/top_processes')
Expand Down
6 changes: 3 additions & 3 deletions docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
gunicorn==21.2.0
psycopg[binary]==3.1.12
psycopg[binary]==3.1.13
fastapi==0.104.1
uvicorn[standard]==0.24.0.post1
pandas==2.1.2
pandas==2.1.3
PyYAML==6.0.1
anybadge==1.14.0
orjson==3.9.10
scipy==1.11.3
scipy==1.11.4
schema==0.7.5
166 changes: 87 additions & 79 deletions frontend/dist/css/semantic_reduced.min.css

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions frontend/dist/js/accordion.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9c72d65

Please sign in to comment.