Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Adding live metrics manager #78

Merged
merged 11 commits into from
May 11, 2020

Conversation

hectorhdzg
Copy link
Member

Needed for #52

@hectorhdzg hectorhdzg requested a review from lzchen as a code owner April 15, 2020 23:52
@hectorhdzg hectorhdzg requested a review from markwolff April 16, 2020 18:11
self.value = value


class LiveMetricDocument(BaseObject):
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, where are the specs for these schemas defined? I can't seem to find them here https://github.com/microsoft/ApplicationInsights-Home/tree/master/EndpointSpecs/Schemas/Bond

Copy link
Member Author

Choose a reason for hiding this comment

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

@lzchen
Copy link
Contributor

lzchen commented Apr 19, 2020

Can you include a description of the control flow of live metrics? What are each of these classes used for and how (if any) is the user expected to interact with it?

"Expect": "100-continue",
"Content-Type": "application/json; charset=utf-8",
LIVE_METRICS_TRANSMISSION_TIME_HEADER: str(
round(time.time()) * 1000
Copy link
Contributor

@lzchen lzchen Apr 22, 2020

Choose a reason for hiding this comment

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

According to the specs:

  1. Expressed as the number of 100-nanosecond intervals -> should be divide 100 instead of times 1000
  2. That have elapsed since 12:00:00 midnight on January 1, 0001 -> epoch date for time.time() is different

machine_name=azure_monitor_context.get("ai.device.id"),
metrics=None,
stream_id=STREAM_ID,
timestamp="/Date({0})/".format(str(int(time.time()) * 1000)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as here.

def __init__(self, instrumentation_key):
self._instrumentation_key = instrumentation_key
self._sender = LiveMetricsSender(self._instrumentation_key)
self.subscribed = True
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like the exporter keeping the state of subscribed, however there doesn't seem to be a nice way to do this. One way is to use the context, where the key is LIVE_METRICS_{x} where x is the unique UUID for that manager and the value is subscribed or not. Another (ugly) way is to have a reference to the manager from the exporter and keep the state of subscribed in the manager.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since UUID is unique per application and not manager instance, I think it is fine to have a global variable in the context keeping track of the state of subscribed. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

Problem is with internal threads, we have 3 different threads that would be using this global context variable, making this code easier to break in specific cases, my point is that is not worth to add this logic only because subscribed flag feels out of place.

Copy link
Contributor

@lzchen lzchen left a comment

Choose a reason for hiding this comment

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

LGTM

@hectorhdzg hectorhdzg merged commit b093bde into microsoft:master May 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants