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

Fix telemetry unicode errors #1937

Merged
merged 28 commits into from Jul 20, 2020

Conversation

larohra
Copy link
Contributor

@larohra larohra commented Jul 7, 2020

Description

This PR mainly deals with ensuring that the telemetry events sent by the agent are encoded properly in UTF-8 for both Py2 and Py3. This is to support special characters in telemetry.

Issue #


PR information

  • The title of the PR is clear and informative.
  • There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, see this page.
  • Except for special cases involving multiple contributors, the PR is started from a fork of the main repository, not a branch.
  • If applicable, the PR references the bug/issue that it fixes in the description.
  • New Unit tests were added for the changes made and Travis.CI is passing.

Quality of Code and Contribution Guidelines

@codecov
Copy link

codecov bot commented Jul 7, 2020

Codecov Report

Merging #1937 into develop will increase coverage by 0.01%.
The diff coverage is 79.26%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1937      +/-   ##
===========================================
+ Coverage    69.65%   69.66%   +0.01%     
===========================================
  Files           85       85              
  Lines        11925    11983      +58     
  Branches      1666     1676      +10     
===========================================
+ Hits          8306     8348      +42     
- Misses        3251     3263      +12     
- Partials       368      372       +4     
Impacted Files Coverage Δ
azurelinuxagent/common/utils/restutil.py 90.76% <ø> (ø)
azurelinuxagent/common/utils/textutil.py 61.53% <53.84%> (-0.49%) ⬇️
azurelinuxagent/common/protocol/wire.py 76.56% <80.00%> (-0.44%) ⬇️
azurelinuxagent/ga/monitor.py 77.96% <87.50%> (+0.64%) ⬆️
azurelinuxagent/common/event.py 86.10% <90.47%> (+0.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2416e79...4aa8880. Read the comment docs.

@@ -362,7 +362,7 @@ def test_send_event(self, mock_http_request, *args):

event_str = u'a test string'
client = WireProtocol(WIRESERVER_URL).client
client.send_event("foo", event_str)
client.send_event("foo", event_str.encode('utf-8'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should inputs to send_event be of type str, or of type ustr? This maybe harkens back to my prior comment about keeping encode secluded within communicating with the outside world.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm assuming that this is, like explained in the other comment, designed to keep changes out of the send_event function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically it should be ustr (which is the same as str for Py3) here and only be encoded in the restutil function which actually sends the data out. But since right now I'm only focusing the changes for the telemetry event, we're encoding the string in this function which is just 1 level up from the restutil function to limit the blast radius of this change.

Does that make sense? We can discuss more on this offline if you have additional doubts.

azurelinuxagent/ga/monitor.py Outdated Show resolved Hide resolved
azurelinuxagent/common/event.py Outdated Show resolved Hide resolved
azurelinuxagent/common/protocol/wire.py Show resolved Hide resolved
azurelinuxagent/common/protocol/wire.py Show resolved Hide resolved
azurelinuxagent/common/utils/restutil.py Show resolved Hide resolved
azurelinuxagent/common/utils/textutil.py Show resolved Hide resolved
narrieta
narrieta previously approved these changes Jul 15, 2020
Copy link
Member

@narrieta narrieta left a comment

Choose a reason for hiding this comment

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

A couple of small comments

kevinclark19a
kevinclark19a previously approved these changes Jul 15, 2020
pgombar
pgombar previously approved these changes Jul 15, 2020
@@ -488,7 +488,7 @@ def put_page_blob(self, url, data):


def event_param_to_v1(param):
param_format = '<Param Name="{0}" Value={1} T="{2}" />'
param_format = ustr('<Param Name="{0}" Value={1} T="{2}" />')
Copy link
Member

Choose a reason for hiding this comment

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

can we add utf_8 somewhere in the function name to be more explicit on what it returns ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@larohra larohra dismissed stale reviews from pgombar, kevinclark19a, and narrieta via 6913447 July 16, 2020 19:15
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.

None yet

4 participants