Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GMIM-353: Add utility method to fetch widget data... #79

Open
wants to merge 43 commits into
base: master
Choose a base branch
from

Conversation

yashdattsawant
Copy link

No description provided.

@ekauzlarich
Copy link

Is there any context on these changes? I'm unable to access the GMI jira project to look at the ticket

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 16.66667% with 50 lines in your changes missing coverage. Please review.

Project coverage is 22.50%. Comparing base (2f79afa) to head (bc7434e).

Files with missing lines Patch % Lines
smsdk/client.py 20.45% 35 Missing ⚠️
smsdk/ma_session.py 6.25% 15 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #79      +/-   ##
==========================================
- Coverage   22.54%   22.50%   -0.05%     
==========================================
  Files          11       11              
  Lines        1433     1480      +47     
  Branches      342      351       +9     
==========================================
+ Hits          323      333      +10     
- Misses       1110     1147      +37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@oostendo
Copy link
Member

oostendo commented Jan 6, 2025

@ekauzlarich can you take a look and re-review?

@ekauzlarich ekauzlarich changed the title GMI-353: Add utility method to fetch widget data... GMIM-353: Add utility method to fetch widget data... Jan 6, 2025
Copy link

@ekauzlarich ekauzlarich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also add some unit test coverage for the new functionality? doesn't need to be 100% or anything but it's very low right now.

raise ValueError("Error - {}".format(response.text))
data = response.json()["panels"]
except Exception as e:
raise ValueError(e)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason for covering up the original exception? at least raise ... from e would be good to keep the stack context

@@ -52,6 +61,10 @@ def create_share_link(
url_params = {}
url_params["state_hash"] = str(uuid.uuid4())[:8]
url_params["context"] = "/analysis/datavis"
try:
url_params["in_use_workspace"] = self.session.headers["X-Sm-Workspace-Id"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the resource constant: X_SM_WORKSPACE_ID instead of magic string

url_params["state_hash"] = str(uuid.uuid4())[:8]
url_params["context"] = context
try:
url_params["in_use_workspace"] = self.session.headers["X-Sm-Workspace-Id"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the resource constant: X_SM_WORKSPACE_ID instead of magic string

try:
url_params["in_use_workspace"] = self.session.headers["X-Sm-Workspace-Id"]
except:
pass

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this caught and passed? what would be the reason for this header missing and why can it be ignored?

{"field": {"name": "offset_endtime", "type": "datetime"}}
]
if are_line_params_available:
pass

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be raised an indent level and changed to if model == "line" and not are_line_params_available: and remove the pass/else branch for readability

def create_widget_share_link(self, context, **kwargs):
url = "{}{}".format(self.base_url, ENDPOINTS["DataViz"]["share_link"])
url_params = {}
url_params["state_hash"] = str(uuid.uuid4())[:8]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the use of this param? this isn't making a hash of anything currently

try:
url_params["in_use_workspace"] = self.session.headers["X-Sm-Workspace-Id"]
except:
pass

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same except: pass comment from above here

html_content = self.session.get(url).text
soup = BeautifulSoup(html_content, "html.parser")
table = soup.find("table")
rows = table.find("tbody").find_all("tr")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you simplify via something like rows = soup.select("table tbody tr") ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also I'm unfamiliar with what is callable from this SDK or not, is /dev/udf/notebooks available instead of parsing the HTML table? this is prone to breaking if the page is ever updated

async_task_id: str = results.json().get("response").get("task_id")

results = self.session.get(url + "/" + async_task_id).json()
time.sleep(10)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of sleeping manually 10s twice, this should loop until a specified timeout for task completion


if "machine__source" not in kwargs and "machine__source__in" not in kwargs:
log.warn("Machine source not specified.")
return []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this function called? also should this return a request error of some sort since it seems like these params are required for it to do anything?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will take a look at these. Thanks for feedback

@ekauzlarich ekauzlarich self-assigned this Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants