-
-
Notifications
You must be signed in to change notification settings - Fork 808
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
Small fixes Import-DbaXESessionTemplate #4917
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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.
Can you clarify why this change is required?
Template is a valid parameter and as documentation states:
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.
Name is for the name of the XE session to be created.
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 attached issue #4923 to it. This caught my attention while scanning the code trying to understand what is happening.
The warning message contradicts the code,
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.
Based on the message then Template should still be checked and the Name parameter simply added to the logic:
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.
@wsmelton
The message is: "Name cannot be specified with multiple files or templates because the Session will already exist."
Notice that the parameter -Path also specifies a template, but it needs the full path and the file extention. Apart from this, the parameter -Template has the same function.
Breaking it into pieces:
"Name cannot be specified" : (Test-Bound -ParameterName Name)
"multiple files or templates" : ($Path.Count -gt 1 -or $Template.Count -gt 1)
--> multiple files means $Path.Count -gt 1, sames goes for templates
For me it's still clear the developer just made a typo, using the wrong parameter. Very small issue.
To prove my case further, let me show this test:
Import-DbaXESessionTemplate -SqlInstance vmSQL -Path 'C:\Users\ijeb\Documents\GitHub\dbatools\bin\XEtemplates\Failing Queries.xml','C:\Users\ijeb\Documents\GitHub\dbatools\bin\XEtemplates\Function Executions.xml' -Name 'NewSession'
This should give the warning and abort, because it is not possible to have two sessions with the same name.
With the code I committed the result is:
WARNING: [08:23:07][Import-DbaXESessionTemplate] Name cannot be specified with multiple files or templates because the Session will already exist.
And with your suggested change (after deleting NewSession manually) the result is:
ComputerName : vmSQL
InstanceName : MSSQLSERVER
SqlInstance : vmSQL
Name : NewSession
Status : Stopped
StartTime :
AutoStart : False
State : Existing
Targets : {}
TargetFile : {}
Events : {sqlserver.error_reported}
MaxMemory : 4096
MaxEventSize : 0
WARNING: [08:27:03][Import-DbaXESessionTemplate] NewSession already exists on vmSQL
So no warning is shown. This is wrong.
However, today I thought of another possibility. It is possible to use the parameters -Path and -Template at the same time.
This should also show the warning, but it does not
Import-DbaXESessionTemplate -SqlInstance vmSQL -Path 'C:\Users\ijeb\Documents\GitHub\dbatools\bin\XEtemplates\Failing Queries.xml' -Template 'Function Executions' -Name 'NewSession'
So $Path.Count equals 1
$Template.Count equals 1
These two numbers need to be added together. The developer did not think of this case.
This can be solved
if ((($Path.Count + $Template.Count) -gt 1) -and (Test-Bound -ParameterName Name)) {
However, in this case the warning message is not good anymore. I would suggest:
It is not possible to import multiple templates together and give them the same name. Either import one template at a time or do not use the Name parameter.
What do you think of this?
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 intention is not for you to use Template with the Path parameter. Path is only used when you want to provide your own custom template. The Template path is used when you want to utilize the templates we include in the module (the command will iterate through and find the file that matches the Template name).
So you can use:
Import-DbaXeSessionTemplate … -Path '<path to my xml file>' -Name MySession
Import-DbaXeSessionTemplate … -Template 'Profiler Tuning' -Name MySession
Combining the following parameters should throw a message as invalid parameter combinations:
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.
This is leading nowhere.
My intention is to only change a small inconsistency in the code. I don't want to change the original design.
How should I clean this up in a clean way? Just delete the branch / revoke the PR?