-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
#9733: Extend RemoteMonitor to send data as application/json #9734
Changes from 1 commit
4bdff54
8dd60a4
e08351b
a1da392
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -547,25 +547,29 @@ class RemoteMonitor(Callback): | |
Events are sent to `root + '/publish/epoch/end/'` by default. Calls are | ||
HTTP POST, with a `data` argument which is a | ||
JSON-encoded dictionary of event data. | ||
If send_as_json is set to True, the content type of the request will be application/json. | ||
Otherwise the serialized JSON will be send within a form | ||
|
||
# Arguments | ||
root: String; root url of the target server. | ||
path: String; path relative to `root` to which the events will be sent. | ||
field: String; JSON field under which the data will be stored. | ||
headers: Dictionary; optional custom HTTP headers. | ||
send_as_json: whether the request should be send as application/json | ||
""" | ||
|
||
def __init__(self, | ||
root='http://localhost:9000', | ||
path='/publish/epoch/end/', | ||
field='data', | ||
headers=None): | ||
headers=None, send_as_json=False): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. skip a line to be consistent |
||
super(RemoteMonitor, self).__init__() | ||
|
||
self.root = root | ||
self.path = path | ||
self.field = field | ||
self.headers = headers | ||
self.send_as_json = send_as_json | ||
|
||
def on_epoch_end(self, epoch, logs=None): | ||
if requests is None: | ||
|
@@ -580,9 +584,13 @@ def on_epoch_end(self, epoch, logs=None): | |
else: | ||
send[k] = v | ||
try: | ||
requests.post(self.root + self.path, | ||
{self.field: json.dumps(send)}, | ||
headers=self.headers) | ||
if self.send_as_json: | ||
payload = {self.field: send} if self.field else send | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this if is not documented There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Dref360 There is this fragment in the class documentation: Do you want me to add something more? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's also inconsistent with line 593 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Dref360 the |
||
requests.post(self.root + self.path, json=payload, headers=self.headers) | ||
else: | ||
requests.post(self.root + self.path, | ||
{self.field: json.dumps(send)}, | ||
headers=self.headers) | ||
except requests.exceptions.RequestException: | ||
warnings.warn('Warning: could not reach RemoteMonitor ' | ||
'root server at ' + str(self.root)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the type to be consistent
send_as_json: Boolean, ...