-
Notifications
You must be signed in to change notification settings - Fork 255
feat(logging): log stream provider to cache log stream #3646
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat(logging): log stream provider to cache log stream #3646
Conversation
56385a6
to
e76bebb
Compare
packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/cloudwatch_logger_plugin.dart
Outdated
Show resolved
Hide resolved
packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/cloudwatch_logger_plugin.dart
Outdated
Show resolved
Hide resolved
packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/cloudwatch_logger_plugin.dart
Show resolved
Hide resolved
packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/cloudwatch_logger_plugin.dart
Outdated
Show resolved
Hide resolved
if (totalByteSize + size >= _maxLogEventsBatchSize || | ||
logEvents.length >= _maxNumberOfLogEventsInBatch || | ||
(logEvents.length > 1 && | ||
currentLogEvent.timestamp - logEvents.first.timestamp >= | ||
_maxLogEventsTimeSpanInBatch)) { |
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.
Please break these out into variables
); | ||
|
||
verify( | ||
() => mockCloudWatchLogStreamProvider.logStream, |
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.
Same question. Why not use the real log stream provider here?
packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/cloudwatch_logger_plugin.dart
Outdated
Show resolved
Hide resolved
return _client.putLogEvents(request).result; | ||
} on Exception { | ||
rethrow; | ||
} | ||
} | ||
|
||
Stream<_LogBatch> _getLogBatchesToSync() async* { | ||
final queuedLogs = (await _logStore.getAll()).toList(); |
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.
These can be streamed
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.
do you mean the log store to return stream instead of Future or do you mean creating stream from _logStore.getAll()
?
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.
Yes, _logStore.getAll()
can be a Stream, then this method becomes a transformer of batches of log records from the DB to batches which can be synced.
@override | ||
Future<String> get logStream async { | ||
FutureOr<String> get logStream async { |
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.
Making this FutureOr
is a decent idea, but by marking this async
it will always return a Future
.
In the cached case, this is the same as:
Future<String> get logStream {
if (_cachedLogStreams.contains(logStreamName)) {
return Future.value(logStreamName);
}
}
Further, if you await the return of a FutureOr
it is implicitly wrapped in Future.value
and you cannot use the result synchronously.
That is to say, to fully leverage FutureOr
, you need to switch on the return and treat it as a sealed class over T
and Future<T>
.
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.
updated to Future
packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/cloudwatch_logger_plugin.dart
Outdated
Show resolved
Hide resolved
cf1f3ed
to
949a371
Compare
} | ||
logger.error('Failed to sync batched logs to CloudWatch', e); | ||
final response = await _sendToCloudWatch(events); | ||
if (response.rejectedLogEventsInfo?.tooNewLogEventStartIndex != null) { |
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.
There are two other properties to this, expiredLogEventEndIndex
and tooOldLogEventEndIndex
, which will need to be handled. I'm guessing later iterations will take into account partial completion as well since currently it is an all-or-nothing approach for a batch?
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.
correct, added a TODO
Future<String> get logStream; | ||
/// Returns log stream name from cache. if cache is missing it | ||
/// calls [createLogStream] and return the log stream name. | ||
FutureOr<String> get logStream; |
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.
I would maybe change the name to currentLogStream
or similar to distinguish from createLogStream
. Is this class going to be public?
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.
the DefaultCloudWatchLogStreamProvider is not going to be public. should I move it to the cloudwatch_logger_plugin.dart
and make it private?
packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/cloudwatch_logger_plugin.dart
Outdated
Show resolved
Hide resolved
when(() => mockCloudWatchLogStreamProvider.logStream) | ||
.thenAnswer((_) async => Future<String>.value('log stream name')); | ||
|
||
when(() => mockQueuedItemStore.addItem(any(), any())) |
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.
Then there should be tests for the log stream provider as well since that's currently not being tested.
packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/log_stream_provider.dart
Outdated
Show resolved
Hide resolved
949a371
to
060eb22
Compare
060eb22
to
121fb88
Compare
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.