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

Add Support for Dump File Name Templates #6675

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

wsugarman
Copy link

@wsugarman wsugarman commented May 18, 2024

Summary

Enable users to configure the name of artifacts for the following actions:

  • CollectDump
  • CollectExceptions
  • CollectGCDump
  • CollectLiveMetrics
  • CollectLogs
  • CollectStacks
  • CollectTrace

Furthermore, the following placeholders have been added to bring parity with the placeholders used by the environment variable DOTNET_DbgMiniDumpName/COMPlus_DbgMiniDumpName as detailed here.

Specifier Value
$(Process.Hostname) Host name return by gethostname()
$(Action.UnixTime) Time of the action, expressed as seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC)

Resolve #3917

Release Notes Entry
  • Add support for configuring the artifact name
  • Add new placeholders $(Process.Hostname) and $(Action.UnixTime)

@wsugarman wsugarman requested a review from a team as a code owner May 18, 2024 02:32
@wsugarman
Copy link
Author

I have not yet added tests. I thought I'd first put out a first draft to gauge interest and assess the overall design. I'm no expert on this tool nor this project, so please provide any and all feedback.

Copy link
Member

@wiktork wiktork left a comment

Choose a reason for hiding this comment

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

Some design considerations:

  • We may want to have some uniformity around token substitutions. I.e. doing $(Process.ProcessId) in one context but %p in another can be confusing.
  • Having a one-off configuration for dumps works, but we'll need to consider if this should be more generic and apply to other artifacts
  • Should the setting be possible to provide at an api level? Or strictly configuration.

@wsugarman
Copy link
Author

Some design considerations:

  • We may want to have some uniformity around token substitutions. I.e. doing $(Process.ProcessId) in one context but %p in another can be confusing.
  • Having a one-off configuration for dumps works, but we'll need to consider if this should be more generic and apply to other artifacts
  • Should the setting be possible to provide at an api level? Or strictly configuration.

Thank you for the thoughts!

  • The first point makes sense to me. I am having trouble tracking down in the code or docs where this syntax is already used for things like $(Process.ProcessId). Could you provide a link?
  • I agree, especially because the artifact name concept is used across artifact types.
  • It could make sense in the web APIs. The only tricky part is that the artifact appears to be typically returned to the user via the HTTP response unless otherwise indicated, like specifying egress for the /dump route. Then the settings for the egress are all made via a configuration instead of via the request. In other words, by default, the name may be irrelevant and only becomes relevant once a custom egress is specified. Given that existing egress settings are specified via configuration, I would reckon that artifact name should be the same. However, artifact name is a concept that is separate from each egress type, so maybe it makes more sense to be configurable per request?

@wiktork
Copy link
Member

wiktork commented May 24, 2024

The first point makes sense to me. I am having trouble tracking down in the code or docs where this syntax is already used for things like $(Process.ProcessId). Could you provide a link?

https://github.com/dotnet/dotnet-monitor/blob/main/src/Tools/dotnet-monitor/ConfigurationTokenParser.cs

This class would likely require some refactoring to support scalar string values instead of properties

It could make sense in the web APIs.

I think we could do this piece wise. Start with just configuration and consider an api level override later.

@wsugarman
Copy link
Author

The first point makes sense to me. I am having trouble tracking down in the code or docs where this syntax is already used for things like $(Process.ProcessId). Could you provide a link?

https://github.com/dotnet/dotnet-monitor/blob/main/src/Tools/dotnet-monitor/ConfigurationTokenParser.cs

This class would likely require some refactoring to support scalar string values instead of properties

It could make sense in the web APIs.

I think we could do this piece wise. Start with just configuration and consider an api level override later.

I've changed the pattern. Let me know what you think. I'm uncertain about two things:

  • The name of the placeholders $(Action.UnixTime and $(Process.Hostname)
  • The hostname isn't really that of the process; it's for the monitor. If we want the hostname, if there a remote scenario for dotnet-monitor, then we may need to retrieve it remotely.

@@ -159,7 +160,9 @@ public object SubstituteOptionValues(IDictionary<string, CollectionRuleActionRes
RuntimeId = _ruleContext.EndpointInfo?.RuntimeInstanceCookie ?? Guid.Empty,
ProcessId = _ruleContext.EndpointInfo?.ProcessId ?? 0,
CommandLine = commandLine,
ProcessName = _ruleContext.ProcessInfo?.ProcessName ?? string.Empty
ProcessName = _ruleContext.ProcessInfo?.ProcessName ?? string.Empty,
Hostname = Dns.GetHostName(),
Copy link
Member

Choose a reason for hiding this comment

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

nit: Would it be better to use Environment.MachineName?

Copy link
Member

Choose a reason for hiding this comment

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

As you pointed out, this would be dotnet-monitor's machine name, which is not what we are looking for. We can get the target process environment variables, that should be enough for the host name in aks and Windows scenarios. Not sure about Linux though.


public static readonly string RuntimeIdReference = CreateTokenReference(ProcessInfoReference, RuntimeId);
public static readonly string ProcessIdReference = CreateTokenReference(ProcessInfoReference, ProcessId);
public static readonly string ProcessNameReference = CreateTokenReference(ProcessInfoReference, ProcessName);
public static readonly string CommandLineReference = CreateTokenReference(ProcessInfoReference, CommandLine);
public static readonly string HostnameReference = CreateTokenReference(ProcessInfoReference, Hostname);
Copy link
Member

Choose a reason for hiding this comment

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

As it is, this variable (Process.Hostname) is semantically referring to the hostname of the target process. But the callers are collecting the hostname information of the host that .NET Monitor is running on. While these might be the same in many cases, I think this should be either:


public static readonly string RuntimeIdReference = CreateTokenReference(ProcessInfoReference, RuntimeId);
public static readonly string ProcessIdReference = CreateTokenReference(ProcessInfoReference, ProcessId);
public static readonly string ProcessNameReference = CreateTokenReference(ProcessInfoReference, ProcessName);
public static readonly string CommandLineReference = CreateTokenReference(ProcessInfoReference, CommandLine);
public static readonly string HostnameReference = CreateTokenReference(ProcessInfoReference, Hostname);
public static readonly string UnixTimeReference = CreateTokenReference(ActionReference, UnixTime);
Copy link
Member

Choose a reason for hiding this comment

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

I think we should use a different category for Timestamp than Action. These typically refer to other actions in a chain.

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_CollectArtifactOptions_ArtifactName))]
public string ArtifactName { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

I'm ok with this level of configuration, but I think long term we'll want a higher tier of configuration on a per artifact type rather than per egress type. We can add that later though.

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.

Customize artifact names
3 participants