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

Non windows persistent storage short-term fix #655

Merged
merged 17 commits into from
Nov 28, 2017

Conversation

cijothomas
Copy link
Contributor

@cijothomas cijothomas commented Nov 20, 2017

Fix issue microsoft/ApplicationInsights-aspnetcore#551
Short description of the fix:
For non-windows users ServerTelemetryChannel will not automatically create a directory and store telemetry items when network issues occur. This is because, currently .net core does not have an api to set file permissions, so this temp directory cannot be secured. Users can, however, set a flag AllowUnsecureLocalStorage to true, on ServerTelemetryChannel. to override this behavior. Alternatively, users can create a directory themselves, and pass it to ServerTelemetryChannel.StorageFolder. (this functionality existed originally)

Checklist:

  • I ran all unit tests locally
    For significant contributions please make sure you have completed the following items:

  • Design discussion issue #

  • Changes in public surface reviewed

  • CHANGELOG.md updated with one line description of the fix, and a link to the original issue.

  • The PR will trigger build, unit test, and functional tests automatically. If your PR was submitted from fork - mention one of committers to initiate the build for you.

@cijothomas cijothomas changed the title Cithomas/linuxchannel Non windows persistent storage short-term fix Nov 20, 2017
@cijothomas
Copy link
Contributor Author

Some notes:
#654

@@ -369,7 +369,7 @@ public void TransmissionSendingFailedWarning(string transmissionId, string excep
[Event(
55,
Keywords = Keywords.UserActionable,
Message = "Access to the local storage was denied (User: {1}). If you want Application Insights SDK to store telemetry locally on disk in case of transient network issues please give the process access either to %LOCALAPPDATA% or to %TEMP% folder. After you gave access to the folder you need to restart the process. Currently monitoring will continue but if telemetry cannot be sent it will be dropped. Error message: {0}.",
Message = "Local storage access has resulted in an error (User: {1}). If you want Application Insights SDK to store telemetry locally on disk in case of transient network issues please give the process access to %LOCALAPPDATA% or %TEMP% folder. After you gave access to the folder you need to restart the process. Currently monitoring will continue but if telemetry cannot be sent it will be dropped. Error message: {0}.",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

might need to link to an actual documentation instead of this long but in-complete (due to lack of instruction for linux/docker) text.

@cijothomas
Copy link
Contributor Author

based on offline dicussion with dmitry,
(This will be modified to discontinue use of the confusing flag - AllowUnsecureLocalStorage’ , and allow local persistence folder in Non-Windows ONLY if user explicitly supply a StorageFolder.)

private readonly IDictionary environment;
private readonly string customFolderName;
private readonly WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();
private IIdentityProvider identityProvider;

public ApplicationFolderProvider(string folderName = null)
: this(Environment.GetEnvironmentVariables(), folderName)
Copy link
Contributor

Choose a reason for hiding this comment

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

you may not have permissions to environment variables and this code will crash. Something like #416 will happen

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Will track separately as I don't want to make additional changes with this fix.
#657

private readonly IDictionary environment;
private readonly string customFolderName;
private readonly WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();
private IIdentityProvider identityProvider;
Copy link
Contributor

Choose a reason for hiding this comment

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

it can still be readonly. It's initialized in constructor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@SergeyKanzhelev SergeyKanzhelev left a comment

Choose a reason for hiding this comment

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

I'm generally OK with the fix

@@ -128,6 +154,10 @@ private IPlatformFolder CreateAndValidateApplicationFolder(string rootPath, bool
if (createSubFolder)
{
telemetryDirectory = this.CreateTelemetrySubdirectory(telemetryDirectory);
if (!this.ApplySecurityToDirectory(telemetryDirectory))
{
throw new SecurityException("Unable to apply security restrictions to the storage directory.");
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this exception/message is going to be thrown every time this channel is created in non-Windows environment because this.ApplySecurityToDirectory() will return false there. Comment in the catch below states that "// The caller does not have code access permission to create the directory" is the reason for this SecurityException. However, the actual reason is that we simply do not support that platform.

@@ -481,6 +482,12 @@ public void ItemRejectedNoInstrumentationKey(string item, string appDomainName =
this.WriteEvent(67, item ?? string.Empty, this.ApplicationName);
}

[Event(68, Message = "Failed to set access permissions on storage directory {0}. Error : {1}.", Level = EventLevel.Warning)]
Copy link
Member

Choose a reason for hiding this comment

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

Should it direct user to the creation of the custom folder for the telemetry storage in case of non-Windows platforms?

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 a warning message and won't be automatically picked up y SDK diagnostics. There is an error message which will inform the user to create folder themselves.

@cijothomas cijothomas merged commit c3da6cc into develop Nov 28, 2017
@TimothyMothra TimothyMothra deleted the cithomas/linuxchannel branch April 17, 2018 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants