Skip to content

Add telemetry support#20

Merged
that1guy15 merged 20 commits intomainfrom
add_telemetry_support
May 19, 2022
Merged

Add telemetry support#20
that1guy15 merged 20 commits intomainfrom
add_telemetry_support

Conversation

@rajagopalans
Copy link
Copy Markdown
Contributor

No description provided.

@rajagopalans rajagopalans requested a review from that1guy15 May 10, 2022 13:08
Copy link
Copy Markdown
Contributor

@that1guy15 that1guy15 left a comment

Choose a reason for hiding this comment

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

Few NIT comments but overall look great.
The one thing missing is a document in /docs/example-scripts with a walk-through of its usage. I usually use the same code from scripts and add some comentery around it. This is optional for this PR

Comment thread aos/client.py
from .resources import AosResources
from .external_systems import AosExternalSystems

from .telemetry import AosTelemetryManager
Copy link
Copy Markdown
Contributor

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 both imports? line 8 and 15

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed the one in line 8

Comment thread aos/telemetry.py Outdated

@classmethod
def from_json (cls, d:dict):
return AosTelemetryEndpointStatus( connected=d.get("connected"), connection_log=d.get("connectionLog"), connection_time=d.get("connectionTime"), last_tx_time=d.get("lastTransmitedTime"),epoch=d.get("epoch"),connection_reset_count=d.get("connectionResetCount"), dns_log=d.get("dnsLog"), disconnection_time=d.get("disconnectionTime"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

need to wrap this line please. Suggested approach is to use black (installed in the venv) on all files you work with before commiting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread aos/telemetry.py Outdated

@classmethod
def from_json(cls, d:dict):
return AosTelemetryEndpoint(id=d.get("id"), host=d.get("host"), port=d.get("port"), streaming_type=d.get("streaming_type"), protocol=d.get("protocol"),sequencing_mode=d.get("sequencing_mode"), ep_status=AosTelemetryEndpointStatus.from_json(d.get("status")))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread aos/telemetry.py Outdated
"""
Telemetry manager class used to manage the telemetry endpoints
"""
def add_endpoint(self, host, port, streaming_type, protocol = "protoBufOverTcp", mode = "sequenced"):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please provide an output type for all functions/methods and their arguments.
https://docs.python.org/3/library/typing.html

Comment thread aos/telemetry.py Outdated
"sequencing_mode": mode,
"protocol": protocol,
}
self.rest.json_resp_post(uri = "/api/streaming-config", data = body)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I dont see a return here. We need to give some response even if its just returning the output of the post.

Comment thread aos/telemetry.py Outdated
Get the existing streaming endpoints as AosTelemetryEndpoint objects
"""
r = self.rest.json_resp_get(uri = "/api/streaming-config")
return [AosTelemetryEndpoint.from_json(i) for i in r['items'] ]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This assumes you will get a payload with ["items"] present.
Either set a try/except for return codes or validate r["items"] is present with an if/else.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In other areas we have null() data class for a blank object or one that is not returned. This would be a good option that lines up with the rest of the code base. ex

if sz is None:

Comment thread aos/telemetry.py Outdated
id
(str) id of the endpoint
"""
self.rest.delete(uri="/api/streaming-config/"+id)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

return self.rest.delete()

Comment thread aos/telemetry.py Outdated
"""
eps = self.get_endpoints()
for ep in eps:
self.delete_endpoint(ep.id)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same, need a return.

Comment thread tests/test_telemetry.py Outdated
mock_rest = mock.Mock()
mgr = AosTelemetryManager(mock_rest)

mock_rest.json_resp_get.return_value = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest moving this to a fixture so we can track it with the right Apostra version.
There are fixture tools in tests/utils.py to use.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please address.

Comment thread tests/test_telemetry.py Outdated

def test_add_endpoint():
mgr.add_endpoint("fakehost", "fakeport", "faketype")
mock_rest.json_resp_post.assert_called_with(uri='/api/streaming-config', data={'hostname': 'fakehost', 'port': 'fakeport', 'streaming_type': 'faketype', 'sequencing_mode': 'sequenced', 'protocol': 'protoBufOverTcp'})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wrap this line please. Suggest running black on all files you worked with.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please address this comment.

Copy link
Copy Markdown
Contributor

@that1guy15 that1guy15 left a comment

Choose a reason for hiding this comment

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

Looks good. please address comments on test file.

Comment thread tests/test_telemetry.py Outdated

def test_add_endpoint():
mgr.add_endpoint("fakehost", "fakeport", "faketype")
mock_rest.json_resp_post.assert_called_with(uri='/api/streaming-config', data={'hostname': 'fakehost', 'port': 'fakeport', 'streaming_type': 'faketype', 'sequencing_mode': 'sequenced', 'protocol': 'protoBufOverTcp'})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please address this comment.

Comment thread tests/test_telemetry.py Outdated
mock_rest = mock.Mock()
mgr = AosTelemetryManager(mock_rest)

mock_rest.json_resp_get.return_value = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please address.

Comment thread tests/test_telemetry.py
r = mgr.get_endpoints()
assert len(r) == 3
mock_rest.json_resp_get.assert_called()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tox -e py38 flake8 fails multiple lines here. Please address and make sure it passes.

flake8 run-test: commands[0] | flake8 aos/ tests/
tests/test_telemetry.py:2:1: F401 'telnetlib.AO' imported but unused
tests/test_telemetry.py:6:1: F401 'unittest.mock.call' imported but unused
tests/test_telemetry.py:9:1: F401 'tests.util.make_session' imported but unused
tests/test_telemetry.py:12:1: E302 expected 2 blank lines, found 0
tests/test_telemetry.py:130:1: E302 expected 2 blank lines, found 1
tests/test_telemetry.py:132:86: E501 line too long (220 > 85 characters)
tests/test_telemetry.py:134:1: E302 expected 2 blank lines, found 1
tests/test_telemetry.py:138:1: E302 expected 2 blank lines, found 1
tests/test_telemetry.py:144:1: W391 blank line at end of file
ERROR: InvocationError for command /Users/boothr/apstra-api-python/.tox/flake8/bin/flake8 aos/ tests/ (exited with code 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Which has me curious why the GitHub actions to run these test don't fail. Ill dig into this.

Copy link
Copy Markdown
Contributor

@that1guy15 that1guy15 left a comment

Choose a reason for hiding this comment

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

LGTM

@that1guy15 that1guy15 merged commit 220cace into main May 19, 2022
@that1guy15 that1guy15 deleted the add_telemetry_support branch May 20, 2022 15:17
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.

3 participants