Skip to content

Commit 6a13f8c

Browse files
midgemacfMacFarland, Midgie
andauthored
Fixing Bugs found in 1.1.0 (#6)
Co-authored-by: MacFarland, Midgie <macfarlandmj@ornl.gov>
1 parent d28e623 commit 6a13f8c

6 files changed

Lines changed: 21 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).
3737
*Unreleased* versions radiate potential—-and dread. Once you merge an infernal PR, move its bullet under a new version heading with the actual release date.*
3838
3939
-->
40+
## [1.1.1] - 2025-07-09
41+
### Fixed
42+
- 🩹 Added tabulate dependency to pyproject.toml
43+
- 🩹 Corrected logic for differentiating between universal probe metadata and vendor specifics.
4044

4145
## [1.1.0] - 2025-07-02
4246
### Added

opensampl/load/table_factory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ def write(self, data: dict[str, Any], if_exists: conflict_actions = "update"):
198198
new_entry = self.model(**data)
199199
self.session.add(new_entry)
200200
logger.debug(f"New entry created in {self.name}")
201+
self.session.flush()
201202
return new_entry
202203

203204
if if_exists == "error":

opensampl/load_data.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from sqlalchemy.orm import Session
1010

1111
from opensampl.config.base import BaseConfig
12-
from opensampl.db.orm import Base, ProbeData, ProbeMetadata
12+
from opensampl.db.orm import Base, ProbeData
1313
from opensampl.load.routing import route
1414
from opensampl.load.table_factory import TableFactory
1515
from opensampl.metrics import MetricType
@@ -176,22 +176,13 @@ def load_probe_metadata(
176176
raise TypeError("Session must be a SQLAlchemy session")
177177

178178
try:
179-
probe = (
180-
session.query(ProbeMetadata)
181-
.filter(ProbeMetadata.probe_id == probe_key.probe_id, ProbeMetadata.ip_address == probe_key.ip_address)
182-
.first()
183-
)
184-
logger.debug(f"{probe=}")
185-
if not probe:
186-
probe_info = {"probe_id": probe_key.probe_id, "ip_address": probe_key.ip_address, "vendor": vendor.name}
187-
model = data.pop("model", None)
188-
if model:
189-
probe_info["model"] = str(model)
179+
pm_factory = TableFactory(name="probe_metadata", session=session)
190180

191-
probe = ProbeMetadata(**probe_info)
181+
pm_cols = {col.name for col in pm_factory.inspector.columns}
182+
probe_info = {k: data.pop(k) for k in list(data.keys()) if k in pm_cols}
183+
probe_info.update({"probe_id": probe_key.probe_id, "ip_address": probe_key.ip_address, "vendor": vendor.name})
184+
probe = pm_factory.write(data=probe_info, if_exists="update")
192185

193-
session.add(probe)
194-
session.flush()
195186
data["probe_uuid"] = probe.uuid
196187

197188
write_to_table(table=vendor.metadata_table, data=data, session=session, if_exists="update")

opensampl/server/grafana/grafana-dashboards/twst_dash.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@
627627
"format": "table",
628628
"hide": false,
629629
"rawQuery": true,
630-
"rawSql": "select \n time_bucket(${resolution:sqlstring}, pd.time AT TIME ZONE 'UTC') AS time,\n pm.name,\n AVG(pd.value::FLOAT) * 1e9 AS value\nFROM \n get_probe_data_by_probe_and_metric(${modem:sqlstring}, ${phase_offset_uuid:sqlstring}) pd\njoin castdb.reference r on pd.reference_uuid = r.uuid\nJOIN \n castdb.probe_metadata pm ON r.compound_reference_uuid = pm.uuid\nwhere \n $__timeFilter(pd.time)\n and r.compound_reference_uuid in (${compound_ref:sqlstring})\nGROUP BY \n time_bucket(${resolution:sqlstring}, pd.time AT TIME ZONE 'UTC'),\n pm.name\nORDER BY \n time_bucket(${resolution:sqlstring}, pd.time AT TIME ZONE 'UTC')",
630+
"rawSql": "select \n time_bucket(${resolution:sqlstring}, pd.time AT TIME ZONE 'UTC') AS time,\n COALESCE(pm.name, pm.probe_id) as name,\n AVG(pd.value::FLOAT) * 1e9 AS value\nFROM \n get_probe_data_by_probe_and_metric(${modem:sqlstring}, ${phase_offset_uuid:sqlstring}) pd\njoin castdb.reference r on pd.reference_uuid = r.uuid\nJOIN \n castdb.probe_metadata pm ON r.compound_reference_uuid = pm.uuid\nwhere \n $__timeFilter(pd.time)\n and r.compound_reference_uuid in (${compound_ref:sqlstring})\nGROUP BY \n time_bucket(${resolution:sqlstring}, pd.time AT TIME ZONE 'UTC'),\n pm.uuid\nORDER BY \n time_bucket(${resolution:sqlstring}, pd.time AT TIME ZONE 'UTC')",
631631
"refId": "B",
632632
"sql": {
633633
"columns": [
@@ -762,7 +762,7 @@
762762
"format": "table",
763763
"hide": false,
764764
"rawQuery": true,
765-
"rawSql": "select \n time_bucket(${resolution:sqlstring}, pd.time AT TIME ZONE 'UTC') AS time,\n pm.name,\n (MAX(pd.value::FLOAT) - MIN(pd.value::FLOAT)) * 1e9 AS value\nFROM \n get_probe_data_by_probe_and_metric(${modem:sqlstring}, ${phase_offset_uuid:sqlstring}) pd\njoin castdb.reference r on pd.reference_uuid = r.uuid\nJOIN \n castdb.probe_metadata pm ON r.compound_reference_uuid = pm.uuid\nwhere \n $__timeFilter(pd.time)\n and r.compound_reference_uuid in (${compound_ref:sqlstring})\nGROUP BY \n time_bucket(${resolution:sqlstring}, pd.time AT TIME ZONE 'UTC'),\n pm.name\nORDER BY \n time_bucket(${resolution:sqlstring}, pd.time AT TIME ZONE 'UTC')",
765+
"rawSql": "select \n time_bucket(${resolution:sqlstring}, pd.time AT TIME ZONE 'UTC') AS time,\n COALESCE(pm.name, pm.probe_id) as name,\n (MAX(pd.value::FLOAT) - MIN(pd.value::FLOAT)) * 1e9 AS value\nFROM \n get_probe_data_by_probe_and_metric(${modem:sqlstring}, ${phase_offset_uuid:sqlstring}) pd\njoin castdb.reference r on pd.reference_uuid = r.uuid\nJOIN \n castdb.probe_metadata pm ON r.compound_reference_uuid = pm.uuid\nwhere \n $__timeFilter(pd.time)\n and r.compound_reference_uuid in (${compound_ref:sqlstring})\nGROUP BY \n time_bucket(${resolution:sqlstring}, pd.time AT TIME ZONE 'UTC'),\n pm.uuid\nORDER BY \n time_bucket(${resolution:sqlstring}, pd.time AT TIME ZONE 'UTC')",
766766
"refId": "B",
767767
"sql": {
768768
"columns": [
@@ -1524,15 +1524,15 @@
15241524
"type": "grafana-postgresql-datasource",
15251525
"uid": "castdb-datasource"
15261526
},
1527-
"definition": "SELECT uuid AS __value, COALESCE(name, CONCAT(ip_address, ' Interface ', probe_id)) AS __text FROM castdb.probe_metadata where vendor = 'MicrosemiTWST' and probe_id = 'modem'",
1527+
"definition": "SELECT uuid AS __value, COALESCE(name, CONCAT(ip_address, ' Interface ', probe_id)) AS __text FROM castdb.probe_metadata where vendor = 'MicrochipTWST' and probe_id = 'modem'",
15281528
"description": "The modem from which \"local time\" is derived, also the stream from which we are receiving the data. ",
15291529
"hide": 0,
15301530
"includeAll": false,
15311531
"label": "Receiver",
15321532
"multi": false,
15331533
"name": "modem",
15341534
"options": [],
1535-
"query": "SELECT uuid AS __value, COALESCE(name, CONCAT(ip_address, ' Interface ', probe_id)) AS __text FROM castdb.probe_metadata where vendor = 'MicrosemiTWST' and probe_id = 'modem'",
1535+
"query": "SELECT uuid AS __value, COALESCE(name, CONCAT(ip_address, ' Interface ', probe_id)) AS __text FROM castdb.probe_metadata where vendor = 'MicrochipTWST' and probe_id = 'modem'",
15361536
"refresh": 1,
15371537
"regex": "",
15381538
"skipUrlSync": false,

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "opensampl"
3-
version = "1.1.0"
3+
version = "1.1.1"
44
description = "Python tools for adding clock data to a timescale db."
55
license = {file = "LICENSE"}
66
authors = [
@@ -30,6 +30,7 @@ dependencies = [
3030
"astor",
3131
"libcst",
3232
"jinja2>=3.1.6",
33+
"tabulate"
3334
]
3435

3536
[project.urls]

tests/test_load_data.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,10 @@ def test_real_session_flow(
286286
count_before = mock_session.query(ProbeMetadata).count()
287287
assert count_before == 0
288288

289-
with patch("opensampl.load_data.ProbeMetadata", ProbeMetadata):
290-
result = load_probe_metadata(
291-
vendor=VENDORS.ADVA, probe_key=sample_probe_key, data=sample_adva_metadata, session=mock_session
292-
)
293-
assert result is None
289+
result = load_probe_metadata(
290+
vendor=VENDORS.ADVA, probe_key=sample_probe_key, data=sample_adva_metadata, session=mock_session
291+
)
292+
assert result is None
294293

295294
metadata = mock_session.query(ProbeMetadata).all()
296295
assert len(metadata) == 1

0 commit comments

Comments
 (0)