Skip to content
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

Update GetModuleLogs method when tail + since + until options are provided. #4922

Merged
merged 14 commits into from
May 11, 2021

Conversation

yophilav
Copy link
Contributor

@yophilav yophilav commented Apr 30, 2021

TL;DR - This PR chances the behavior of GetModuleLogs method to better facilitate the portal experience.

Previous, when the GetModuleLogs is triggered from the azure portal with tail + since + until, all the 3 options are passed to Docker API management to fetch the log. The Docker API does the following:

  1. Fetch the log of the module
  2. Apply tail to the log
  3. Apply the since and until to the log
    This results in an empty log most of the time which is not a desirable behavior.

This PR changes the GetModuleLogs when the tail + since + until are specified together by doing the following:

  1. Fetch Docker API with since + until log option
  2. tail the returning log using LogProcessor (post-Akka).
    This allows a customer to get a tail of log within a given time frame.

Note: This PR doesn't change the behavior of any other option combinations (i.e. tail + since, tail, since, etc). These combination are still managed by Docker API.

Note2: I set RequestHandle timeout to be 30s instead of 600s by default

@yophilav yophilav marked this pull request as ready for review May 3, 2021 21:20
@yophilav yophilav changed the title [DRAFT] Update docker's log tail feature when since and until is applied. Update GetModuleLogs method when tail + since + until options are provided. May 3, 2021
@@ -255,7 +255,7 @@ public static async Task<int> MainAsync(IConfiguration configuration)
{
case "twin":
bool enableStreams = configuration.GetValue(Constants.EnableStreams, false);
int requestTimeoutSecs = configuration.GetValue(Constants.RequestTimeoutSecs, 600);
int requestTimeoutSecs = configuration.GetValue(Constants.RequestTimeoutSecs, 30);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the part that I'm not super sure about if I should change the default request timeout from 600s to 30s for all the default. I don't really have a clean way to set a particular GetModuleLogs DM's default request timeout to be 30s. Any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

dm call has a timeout that can be set to ResponseTimeout in MethodRequest class. The default change is a big difference, it might cause issues with slower connections I assume.

return filter.Tail.Match<IReadOnlyList<ModuleLogMessage>>(
t =>
{
return result.Skip(Math.Max(0, result.Count - t)).ToList().AsReadOnly();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this looks like Math.Abs can be used instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, I don't think Math.Abs() will work here. More particularly in case t > result.Count, Abs() would return the difference.. that's not what I want.

since.ForEach(s => logsUrl.AppendFormat($"&{LogsUrlSinceParameter}={Uri.EscapeUriString(s)}"));
until.ForEach(u => logsUrl.AppendFormat($"&{LogsUrlUntilParameter}={Uri.EscapeUriString(u)}"));

if (!(tail.HasValue && since.HasValue && until.HasValue))
Copy link
Contributor

Choose a reason for hiding this comment

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

does tail.HasValue need to be checked here? it looks like only since and until have to be checked that are not set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, absolutely. This is where we about to send the docker API request via mgmt.sock.
Starting from this PR, the behavior is separated into 2 scenarios:

  1. When all 3 options (tail + since + until) are specified, only the since + until is passed down to mgmt.sock
  2. When other combination of options (tail+since, tail+until, until+since) are specified, the options are then passthrough edgeAgent into mgmt.sock directly.

Once the log from (1) is returned, the result is tail-ed after Akka parsing to enforce the tail.

@@ -255,7 +255,7 @@ public static async Task<int> MainAsync(IConfiguration configuration)
{
case "twin":
bool enableStreams = configuration.GetValue(Constants.EnableStreams, false);
int requestTimeoutSecs = configuration.GetValue(Constants.RequestTimeoutSecs, 600);
int requestTimeoutSecs = configuration.GetValue(Constants.RequestTimeoutSecs, 30);
Copy link
Contributor

Choose a reason for hiding this comment

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

dm call has a timeout that can be set to ResponseTimeout in MethodRequest class. The default change is a big difference, it might cause issues with slower connections I assume.

@kodiakhq kodiakhq bot merged commit 2b650a8 into Azure:release/1.2 May 11, 2021
yophilav added a commit to yophilav/iotedge that referenced this pull request May 12, 2021
… provided. (Azure#4922)

TL;DR - This PR chances the behavior of `GetModuleLogs` method to better facilitate the portal experience. 

Previous, when the `GetModuleLogs` is triggered from the azure portal with `tail + since + until`, all the 3 options are passed to Docker API management to fetch the log. The Docker API does the following: 
1. Fetch the log of the module
2. Apply `tail` to the log
3. Apply the `since` and `until` to the log
This results in an empty log most of the time which is not a desirable behavior. 

This PR changes the `GetModuleLogs` when the `tail + since + until` are specified together by doing the following:
1. Fetch Docker API with `since + until` log option
2. `tail` the returning log using LogProcessor (post-Akka).
This allows a customer to get a tail of log within a given time frame. 

Note: This PR doesn't change the behavior of any other option combinations (i.e. `tail + since`, `tail`, `since`, etc). These combination are still managed by Docker API.

Note2: I set RequestHandle timeout to be 30s instead of 600s by default
yophilav added a commit to yophilav/iotedge that referenced this pull request May 14, 2021
… provided. (Azure#4922)

TL;DR - This PR chances the behavior of `GetModuleLogs` method to better facilitate the portal experience. 

Previous, when the `GetModuleLogs` is triggered from the azure portal with `tail + since + until`, all the 3 options are passed to Docker API management to fetch the log. The Docker API does the following: 
1. Fetch the log of the module
2. Apply `tail` to the log
3. Apply the `since` and `until` to the log
This results in an empty log most of the time which is not a desirable behavior. 

This PR changes the `GetModuleLogs` when the `tail + since + until` are specified together by doing the following:
1. Fetch Docker API with `since + until` log option
2. `tail` the returning log using LogProcessor (post-Akka).
This allows a customer to get a tail of log within a given time frame. 

Note: This PR doesn't change the behavior of any other option combinations (i.e. `tail + since`, `tail`, `since`, etc). These combination are still managed by Docker API.

Note2: I set RequestHandle timeout to be 30s instead of 600s by default
kodiakhq bot pushed a commit that referenced this pull request Jun 25, 2021
… provided (#4922) (#5171)

TL;DR - This PR chances the behavior of `GetModuleLogs` method to better facilitate the portal experience. 

Previous, when the `GetModuleLogs` is triggered from the azure portal with `tail + since + until`, all the 3 options are passed to Docker API management to fetch the log. The Docker API does the following: 
1. Fetch the log of the module
2. Apply `tail` to the log
3. Apply the `since` and `until` to the log
This results in an empty log most of the time which is not a desirable behavior. 

This PR changes the `GetModuleLogs` when the `tail + since + until` are specified together by doing the following:
1. Fetch Docker API with `since + until` log option
2. `tail` the returning log using LogProcessor (post-Akka).
This allows a customer to get a tail of log within a given time frame. 

Note: This PR doesn't change the behavior of any other option combinations (i.e. `tail + since`, `tail`, `since`, etc). These combination are still managed by Docker API.

Note2: I set RequestHandle timeout to be 30s instead of 600s by default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants