-
Notifications
You must be signed in to change notification settings - Fork 1
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
DNM: feat: support metrics log stream #28
Draft
airkei
wants to merge
1
commit into
main
Choose a base branch
from
feat/support_metrics_log_stream
base: main
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.
+280
−123
Draft
Changes from all commits
Commits
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 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -237,6 +237,14 @@ def aws_cloudwatch_log_group(self) -> str: | |
f"{self.account_id}/{self.profile}-edge-otaclient" | ||
) | ||
|
||
@computed_field | ||
@property | ||
def aws_cloudwatch_metrics_log_group(self) -> str: | ||
return ( | ||
f"/aws/greengrass/edge/{self.region}/" | ||
f"{self.account_id}/{self.profile}-edge-otaclient-metrics" | ||
) | ||
|
||
Comment on lines
+240
to
+247
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. new log group name for metrics |
||
@computed_field | ||
@property | ||
def aws_credential_refresh_url(self) -> str: | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Copyright 2022 TIER IV, INC. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""OTA Client IoT Logging Server v1 implementation.""" | ||
|
||
from __future__ import annotations | ||
|
||
import logging | ||
import time | ||
from queue import Full | ||
|
||
from otaclient_iot_logging_server._common import LogGroupType, LogMessage, LogsQueue | ||
from otaclient_iot_logging_server.ecu_info import ECUInfo | ||
from otaclient_iot_logging_server.v1.types import ( | ||
ErrorCode, | ||
LogType, | ||
PutLogRequest, | ||
PutLogResponse, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class OTAClientIoTLoggingServerServicer: | ||
"""Handlers for otaclient IoT logging service.""" | ||
|
||
def __init__( | ||
self, | ||
*, | ||
ecu_info: ECUInfo, | ||
queue: LogsQueue, | ||
): | ||
self._queue = queue | ||
self._allowed_ecus = None | ||
|
||
if ecu_info: | ||
self._allowed_ecus = ecu_info.ecu_id_set | ||
logger.info( | ||
f"setup allowed_ecu_id from ecu_info.yaml: {ecu_info.ecu_id_set}" | ||
) | ||
else: | ||
logger.warning( | ||
"no ecu_info.yaml presented, logging upload filtering is DISABLED" | ||
) | ||
|
||
async def put_log(self, request: PutLogRequest) -> PutLogResponse: | ||
""" | ||
NOTE: use <ecu_id> as log_stream_suffix, each ECU has its own | ||
logging stream for uploading. | ||
""" | ||
|
||
def convert_from_log_type_to_log_group_type(log_type): | ||
""" | ||
Convert input log type to log group type | ||
""" | ||
if log_type == LogType.METRICS: | ||
return LogGroupType.METRICS | ||
return LogGroupType.LOG | ||
|
||
_ecu_id = request.ecu_id | ||
_log_group_type = convert_from_log_type_to_log_group_type(request.log_type) | ||
_timestamp = ( | ||
request.timestamp if request.timestamp else int(time.time()) * 1000 | ||
) # milliseconds | ||
_message = request.message | ||
# don't allow empty message request | ||
if not _message: | ||
return PutLogResponse(code=ErrorCode.NO_MESSAGE) | ||
# don't allow unknowned ECUs | ||
# if ECU id is unknown(not listed in ecu_info.yaml), drop this log. | ||
if self._allowed_ecus and _ecu_id not in self._allowed_ecus: | ||
return PutLogResponse(code=ErrorCode.NOT_ALLOWED_ECU_ID) | ||
|
||
_logging_msg = LogMessage( | ||
timestamp=_timestamp, | ||
message=_message, | ||
) | ||
# logger.debug(f"receive log from {_ecu_id}: {_logging_msg}") | ||
try: | ||
self._queue.put_nowait((_log_group_type, _ecu_id, _logging_msg)) | ||
except Full: | ||
logger.debug(f"message dropped: {_logging_msg}") | ||
return PutLogResponse(code=ErrorCode.SERVER_QUEUE_FULL) | ||
|
||
return PutLogResponse(code=ErrorCode.NO_FAILURE) |
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
change the data format of the queue.