Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions api/eco_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _insert_ci_measurement(request: Request, measurement, user: User) -> Respons
if used_client_ip is None:
used_client_ip = get_connecting_ip(request)

for field in ["os_name", "cpu_arch", "job_id"]:
for field in ['os_name', 'cpu_arch', 'job_id', 'version']:
params.append(getattr(measurement, field, None))
params.append(used_client_ip)
params.append(user._id)
Expand Down Expand Up @@ -77,14 +77,15 @@ def _insert_ci_measurement(request: Request, measurement, user: User) -> Respons
os_name,
cpu_arch,
job_id,
version,
ip_address,
user_id,
note
)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
{tags_replacer},
%s, %s, %s, %s, %s, %s)
%s, %s, %s, %s, %s, %s, %s)
"""

DB().query(query=query, params=params)
Expand Down Expand Up @@ -121,7 +122,7 @@ async def post_ci_measurement_add_v3(
user: User = Depends(authenticate) # pylint: disable=unused-argument
):
"""
v3: accepts additional fields (os_name, cpu_arch, job_id) via CI_MeasurementV3.
v3: accepts additional fields (os_name, cpu_arch, job_id, version) via CI_MeasurementV3.
For now, the insert logic is the same as v2 and ignores these extra fields.
"""
return _insert_ci_measurement(request, measurement, user)
Expand Down
2 changes: 1 addition & 1 deletion api/object_specifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class CI_MeasurementV3(CI_MeasurementBase):
os_name: Optional[str] = None
cpu_arch: Optional[str] = None
job_id: Optional[str] = None
version: Optional[str] = None

model_config = ConfigDict(extra='forbid')

Expand Down Expand Up @@ -232,4 +233,3 @@ def check_empty_elements(cls, value):
if any(not item or item.strip() == '' for item in value):
raise ValueError("The list contains empty elements.")
return value

1 change: 1 addition & 0 deletions docker/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ CREATE TABLE ci_measurements (
filter_tags text[] NOT NULL,
os_name text,
cpu_arch text,
version text,
job_id text,
user_id integer NOT NULL REFERENCES users(id) ON DELETE RESTRICT ON UPDATE CASCADE,
created_at timestamp with time zone DEFAULT now(),
Expand Down
1 change: 1 addition & 0 deletions migrations/2025_11_22_add_fields_to_ci_measurements.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ALTER TABLE "public"."ci_measurements" ADD COLUMN "os_name" text;
ALTER TABLE "public"."ci_measurements" ADD COLUMN "cpu_arch" text;
ALTER TABLE "public"."ci_measurements" ADD COLUMN "job_id" text;
ALTER TABLE "public"."ci_measurements" ADD COLUMN "version" text;

UPDATE users
SET capabilities = jsonb_set(
Expand Down
3 changes: 2 additions & 1 deletion tests/api/test_api_eco_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def test_ci_deprecated_endpoint():
'workflow_name': 'testWorkflowName',
'os_name': 'testOsName',
'cpu_arch': 'testCpuArch',
'job_id': 'testJobID'}
'job_id': 'testJobID',
'version': 'v2.2'}

def test_ci_measurement_add_default_user():

Expand Down
8 changes: 2 additions & 6 deletions tests/frontend/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ def open_and_assert_ci_stats(self):
).text_content()
assert carbon_all_steps.strip() == '0.11 s (± 0.00%)'


@pytest.mark.usefixtures('use_clean_db')

def test_eco_ci_adding_data(self):
for index in range(1,4):
measurement = CI_Measurement(energy_uj=(13_000_000*index),
Expand All @@ -209,8 +206,6 @@ def test_eco_ci_adding_data(self):
assert response.status_code == 204, Tests.assertion_info('success', response.text)
self.open_and_assert_ci_stats()


@pytest.mark.usefixtures('use_clean_db')
def test_eco_ci_adding_data_v3(self):
for index in range(1, 4):
measurement = CI_MeasurementV3(energy_uj=(13_000_000 * index),
Expand All @@ -232,7 +227,8 @@ def test_eco_ci_adding_data_v3(self):
carbon_ug=323456,
os_name='Linux',
cpu_arch='x86_64',
job_id='testJobID'
job_id='testJobID',
version='v1.2'
)
response = requests.post(f"{API_URL}/v3/ci/measurement/add", json=measurement.model_dump(), timeout=15)
assert response.status_code == 204, Tests.assertion_info('success', response.text)
Expand Down