-
Notifications
You must be signed in to change notification settings - Fork 267
Refactoring GuestAgent based Logging Mechanism #1978
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
Open
arisettisanjana
wants to merge
50
commits into
Azure:master
Choose a base branch
from
arisettisanjana:dev/sarisetti/EventLoggingRefactoring
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+39
−17
Open
Changes from 48 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
be88895
Removed VSCode Files
arisettisanjana b4507ec
AddedChecks
arisettisanjana 69343cf
UpdatedForLoggingTheError
arisettisanjana d88f30e
UpdatedCode
arisettisanjana 38d75dc
Revert "UpdatedCode"
arisettisanjana e643dd6
Revert "updated lsblk command by using more flags"
arisettisanjana 752e627
reverting to master
arisettisanjana d3614c3
Merge branch 'Azure:master' into master
arisettisanjana f2a25a3
Merge branch 'Azure:master' into master
arisettisanjana 7fbb0d1
Merge branch 'Azure:master' into master
arisettisanjana 93f5171
Merge remote-tracking branch 'upstream/master'
arisettisanjana 45b670d
Merge branch 'master' of https://github.com/arisettisanjana/azure-lin…
arisettisanjana 6ee2ef7
Merge remote-tracking branch 'upstream/master'
arisettisanjana d32caeb
Merge branch 'Azure:master' into master
arisettisanjana 5b5d7d1
Merge branch 'master' of https://github.com/arisettisanjana/azure-lin…
arisettisanjana 6910c56
Merge remote-tracking branch 'upstream/master'
arisettisanjana f89bed4
Merge branch 'Azure:master' into master
arisettisanjana a3412dc
Merge branch 'master' of https://github.com/arisettisanjana/azure-lin…
arisettisanjana 129c7a4
Merge remote-tracking branch 'upstream/master'
arisettisanjana 0011cd4
removed sudo
arisettisanjana d89fbfd
Revert "removed sudo"
arisettisanjana 085b60d
Merge branch 'Azure:master' into master
arisettisanjana 6e02140
Merge branch 'master' of https://github.com/arisettisanjana/azure-lin…
arisettisanjana df94315
Merge branch 'Azure:master' into master
arisettisanjana 7f5c965
Merge branch 'master' of https://github.com/arisettisanjana/azure-lin…
arisettisanjana 937870d
Merge branch 'Azure:master' into master
arisettisanjana 2381fe8
Merge branch 'master' of https://github.com/arisettisanjana/azure-lin…
arisettisanjana 4a2a67d
Merge branch 'Azure:master' into master
arisettisanjana a351b1e
Merge branch 'master' of https://github.com/arisettisanjana/azure-lin…
arisettisanjana 82dd260
Merge branch 'Azure:master' into master
arisettisanjana 56053e9
Merge branch 'Azure:master' into master
arisettisanjana 469cbfd
Merge branch 'Azure:master' into master
arisettisanjana fd13f36
Merge branch 'Azure:master' into master
arisettisanjana 1a863f6
Merge branch 'Azure:master' into master
arisettisanjana 93446a9
Merge branch 'Azure:master' into master
arisettisanjana 3bf57c4
Merge branch 'Azure:master' into master
arisettisanjana 821278c
Merge branch 'Azure:master' into master
arisettisanjana 555ab2c
Merge branch 'Azure:master' into master
arisettisanjana 57e700e
Merge branch 'Azure:master' into master
arisettisanjana 56abd24
Merge branch 'Azure:master' into master
arisettisanjana 7346668
Merge branch 'Azure:master' into master
arisettisanjana 7a1f38b
Merge branch 'master' of https://github.com/arisettisanjana/azure-lin…
arisettisanjana 783d01e
Merge branch 'Azure:master' into master
arisettisanjana 471ef99
Merge branch 'master' of https://github.com/arisettisanjana/azure-lin…
arisettisanjana 9dbc18f
Merge branch 'Azure:master' into master
arisettisanjana 8960b53
Merge branch 'Azure:master' into master
arisettisanjana ed42f23
Merge branch 'master' of https://github.com/arisettisanjana/azure-lin…
arisettisanjana c9a09e8
modified logging path
arisettisanjana dbf9025
temp changes
arisettisanjana 01886b7
draft
arisettisanjana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ class EventLogger: | |
|
|
||
| def __init__(self, event_directory, severity_level, use_async_event_logging = 0): | ||
| global logger | ||
| self.temporary_directory = os.path.join(event_directory, 'Temp') | ||
| self.space_available_in_event_directory = 0 | ||
| self.event_processing_interval = 0 | ||
| self.disposed = False | ||
|
|
@@ -40,11 +39,7 @@ def __init__(self, event_directory, severity_level, use_async_event_logging = 0) | |
| self.operation_id = uuid.UUID(int=0) | ||
| self.log_severity_level = severity_level | ||
| logger.log("Information: EventLogging severity level setting is {0}".format(self.log_severity_level)) | ||
| # creating a temp directory | ||
| if not os.path.exists(self.temporary_directory): | ||
| os.makedirs(self.temporary_directory) | ||
| FileHelpers.clearOldJsonFilesInDirectory(self.temporary_directory) | ||
|
|
||
|
|
||
| FileHelpers.clearOldJsonFilesInDirectory(self.events_folder) | ||
|
|
||
| self.current_message = '' | ||
|
|
@@ -173,18 +168,19 @@ def _process_events(self): | |
| return | ||
| if not self.event_queue.empty(): | ||
| if sys.version_info[0] == 2: | ||
| event_file_path = os.path.join(self.temporary_directory, "{}.json".format(int(time.time() * 1000000000))) | ||
| event_file_path = os.path.join(self.events_folder, "{}.json".format(int(time.time() * 1000000000))) | ||
|
||
| else: | ||
| event_file_path = os.path.join(self.temporary_directory, "{}.json".format(int(datetime.datetime.utcnow().timestamp() * 1000000000))) | ||
| event_file_path = os.path.join(self.events_folder, "{}.json".format(int(datetime.datetime.utcnow().timestamp() * 1000000000))) | ||
| with self._create_event_file(event_file_path) as file: | ||
| if file is None: | ||
| logger.log("Warning: Could not create the event file in the path mentioned.") | ||
| return | ||
| print("Clearing out event queue for processing...") | ||
| old_queue = self.event_queue | ||
| self.event_queue = queue.Queue() | ||
| #self._check_space_in_event_directory(event_file_path) | ||
| self._write_events_to_event_file(file, old_queue, event_file_path) | ||
| self._send_event_file_to_event_directory(event_file_path, self.events_folder) | ||
|
|
||
| except Exception as e: | ||
| print("Exception occurred in _process_events {0}".format(str(e))) | ||
|
|
||
|
|
@@ -207,13 +203,28 @@ def _create_event_file(self, event_file_path): | |
|
|
||
| def _write_events_to_event_file(self, file, events, event_file_path): | ||
| data_list = [] | ||
| file_size = 0 | ||
| while not events.empty(): | ||
| data = events.get() | ||
| data_list.append(data) | ||
| json_data = json.dumps(data_list) | ||
| if not json_data: | ||
| print("Warning: Unable to serialize events. Events for this iteration will not be reported.") | ||
| return | ||
| try: | ||
| if sys.version_info[0] == 2: | ||
| file_size = len(json_data) # Since in python2.x we get a string of bytes so no need of encoding. | ||
| else: | ||
| file_size = len(json_data.encode('utf-8')) | ||
| except Exception as e: | ||
| print("Warning: Error calculating the size of the event file. Exception: {0}".format(str(e))) | ||
|
|
||
| if self.space_available_in_event_directory - file_size >= 0: | ||
| self.space_available_in_event_directory -= file_size | ||
| else: | ||
| self.space_available_in_event_directory = 0 | ||
| print("Information: Event reporting has paused due to reaching maximum capacity in the Event directory. Reporting will resume once space is available. Events for this iteration will not be reported.") | ||
| return | ||
|
|
||
| success_msg = "Successfully wrote events to file: %s" % event_file_path | ||
| retry_msg = "Failed to write events to file: %s. Retrying..." % event_file_path | ||
|
|
@@ -227,41 +238,6 @@ def _write_events_to_event_file(self, file, events, event_file_path): | |
| err_msg, | ||
| lambda: file.write(json_data) | ||
| ) | ||
|
|
||
| def _send_event_file_to_event_directory(self, file_path, events_folder): | ||
| file_info = os.stat(file_path) | ||
| file_size = file_info.st_size | ||
|
|
||
| if self.space_available_in_event_directory - file_size >= 0: | ||
| new_path_for_event_file = os.path.join(events_folder, os.path.basename(file_path)) | ||
| success_msg = "Successfully moved event file to event directory: %s" % new_path_for_event_file | ||
| retry_msg = "Unable to move event file to event directory: %s. Retrying..." % file_path | ||
| err_msg = "Unable to move event file to event directory: %s . No longer retrying. Events for this iteration will not be reported." % file_path | ||
|
|
||
| self.filehelper.execute_with_retries( | ||
| LoggingConstants.MaxAttemptsForEventFileCreationWriteMove, | ||
| LoggingConstants.ThreadSleepDuration, | ||
| success_msg, | ||
| retry_msg, | ||
| err_msg, | ||
| lambda: shutil.move(file_path, new_path_for_event_file) | ||
| ) | ||
|
|
||
| self.space_available_in_event_directory -= file_size | ||
| else: | ||
| self.space_available_in_event_directory = 0 | ||
| FileHelpers.deleteFile(file_path) | ||
| print("Information: Event reporting has paused due to reaching maximum capacity in the Event directory. Reporting will resume once space is available. Events for this iteration will not be reported.") | ||
|
|
||
| def clear_temp_directory(self, directory_path): | ||
| try: | ||
| if os.path.exists(directory_path): | ||
| if len(os.listdir(directory_path)) == 0: | ||
| os.rmdir(directory_path) | ||
| else: | ||
| shutil.rmtree(directory_path) | ||
| except Exception as ex: | ||
| print("Warning: Error clearing the temp directory. Exception: {0}".format(str(ex))) | ||
|
|
||
| def dispose(self): | ||
| print("Information: Dispose(), called on EventLogger. Event processing is terminating...") | ||
|
|
@@ -287,8 +263,6 @@ def _dispose(self, disposing): | |
| logger.log("Warning: Unable to process events before termination of extension. Exception: {0}" .format(str(ex))) | ||
| self.disposed = True | ||
| print("Information: Event Logger has terminated") | ||
| print("Clearing the temp directory") | ||
| self.clear_temp_directory(self.temporary_directory) | ||
| self.event_logging_enabled = False | ||
| except Exception as ex: | ||
| print("Warning: Processing Dispose() of EventLogger resulted in Exception: {0}" .format(str(ex))) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.