GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Pass a header into calls to mixer for usage logs by lucyking140 · Pull Request #276 · datacommonsorg/api-python Conversation
|
|
/gcbrun |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
In principle, LG! Nitty naming thing: since both "metadata" and "source" are either already or likely to soon become overloaded terms in the DC ecosystem, WDYT of calling the parameter something like surface_header_value or feature_surface_tag or something like that?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # if this call originates from another DC product (MCP server, DataGemma, etc.), we indicate that to Mixer | ||
| if(metadata_source): | ||
| # makes it clearer to public users that this is a tag specific to other DataCommons features | ||
| if(metadata_source != "mcp" and metadata_source != "datagemma"): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Optional: Define a constant array of allowed values somewhere
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added a list! Also expanded this to include "mcp-{some number}" to support MCP versions like Christie suggested. Also renamed the param to surface_header_value!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
/gcbrun |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
/gcbrun |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This change will require a PyPi release to take effect. Let's coordinate that after it's merged.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Raised when a surface_header_value is passed in that is not a valid Data Commons surface. | ||
| This value is used in the DC usage logs in Mixer | ||
| """ | ||
| default_message = "The surface header value should only to indicate a call made from Data Commons surfaces like the MCP server or DataGemma." |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Possible edit: "The surface header value must be a surface known to the Data Commons team."
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| url = (self.base_url if endpoint is None else f"{self.base_url}/{endpoint}") | ||
| headers = self.headers | ||
| # if this call originates from another DC product (MCP server, DataGemma, etc.), we indicate that to Mixer |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Optional: mention the default here
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added! And moved this to the new location where I'm setting the header
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| dc_instance = "datacommons.org" | ||
|
|
||
| self.headers = build_headers(api_key) | ||
| self.api_key = api_key if api_key else None |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is self.api_key referenced anywhere else? If not, consider passing it as an explicit additional param to build_headers.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Moved it to a param!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @patch("requests.post") | ||
| def test_send_post_request_surface_header(mock_post): | ||
| """Tests a successful POST request with a surface header.""" | ||
| mock_response = MagicMock() |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit and usually would be auto-formatted in other repos: I think there needs to be a blank line after the comment
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.