-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Sql server old version compatibility #7495
Sql server old version compatibility #7495
Conversation
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.
Wow. Excellent effort here; thank you.
I do wonder if this plugin is getting a little too complicated for its own good. Open to any thoughts you might have here.
What versions have you tested against? [edit: never mind, I see you specified that; thanks!].
Any thoughts on how we can keep future updates from breaking backwards compatibility?
A downside of these giant SQL scripts is we probably won't find out until it doesn't work in production for someone.
TLDR:
About complexity In any case, I doubt that the queries will be less complex, in my opinion, the dynamic SQL is the best option to manage additional/different columns/objects by checking edition and version of SQL Server. About avoiding compatibility breaks
other things not strictly related to telegraf are:
|
@denzilribeiro Can you take a look when you have time? |
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.
Note I haven't tested these against all versions, semantics have by and large not changed, these ae more standardization. There is no need to change sqlServerPropertiesV2 to dynamic SQL it does not achieve a whole lot I would not make this change - what we should do for this is split into on-prem v/s cloud.
Formulating the approach you have for dynamic SQL is fine IF you need dynamic SQL, I wouldn't convert those queries that don't need dynamic SQL to dynamic SQL.
Maybe a bit of over complication in variable section don't need a derived table - this is in multiple places - example below - you could even have that assigned as part of declare statement itself.
SELECT
@EngineEdition = CAST(SERVERPROPERTY('EngineEdition') AS int)
,@majorversion = CAST(PARSENAME(CAST(SERVERPROPERTY('ProductVersion') as nvarchar),4) AS int)
Secondly not sure of the reason for this change
- Session_db_name comes form the session DMV not the request DMV?
- DB_NAME(r.database_id) as session_db_name
My thought is you can support older versions forever and you pay for them in some way :) both with maintaining and a huge text matrix. End of life support for 2008/R2 has been reached last year I don't even have any 2008 lying around to test. I don't agree with changing everything to dynamic SQL - debuggability of dynamic SQL is painful as well - makes sense when you are already using dynamic SQL to adhere to a standard. |
|
About supporting older versions (even out of extended support), I think it's worth it since those versions are still around (I have an instance of SQL 2000...) and as a dba being able to monitor them is really helpful. There are already several switches to manage different versions and adding at worst two more (for SQL 2008 and 2008R2) won't make a difference Personally, if I have to choose between maintaining a set of scripts (in the worst case one for each version) and a more complex dynamic SQL script I would choose the latest. Currently, my idea to make it more readable is to create the "standard" script with some placeholders/variables (ie: for the columns), at the beginning the placeholder variable will be populated with the columns appropriate for the version and then injected in the SQL string, this should improve the query readability by a lot since it moves all the CASE statements to a different area leaving the query cleaner. |
In the last version of this branch:
Tests:
|
My long running test is raising several warnings
The same error sometimes occurs for the sqlserver input plugin, but the same error occurs also on the official version of telegraf even if with less frequency. |
@Trovalo That warning is likely unrelated to this plugin. It happens for lossy output connections, and can happen with the old v1 InfluxDB output when gzip is not turned on and there is a lot of data to send. By itself it just means that the write to InfluxDB took longer than whatever you have set for "flush_interval" in your settings, and is not necessarily indicative of an immediate problem. |
@denzilribeiro, @danielnelson any update on this? |
/* [volume_mount_point] TRIMS trailing "\" which are not allowed in InfluxDB */ | ||
SET @Columns += N',LEFT(vs.[volume_mount_point], LEN(vs.[volume_mount_point])-(PATINDEX(''%[^\]%'',REVERSE([volume_mount_point]))-1)) AS [volume_mount_point]' |
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.
Let's do something for #7558 first so we can avoid it in the query.
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 code removes the trailing \
from the string. It looks complex but it's the safest way to remove all the trailing chars in case the strings ends with multiple \
. (which does not make any sense but it's better to be safe)
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 hate for you to have to do this in query, and for outputs that do support trailing slashes it imposes the line protocol limitations on them too. I opened #7652, let's see what others think of having the solution there.
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.
Since this has been fixed on the telegraf side I will try it out and then make a PR to avoid this logic in the query itself
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.
Would revert the sqlServerPropertiesV2 change as it changes a non dynmic SQL to dynamic SQL and even in that there are server property calls in the query anyways.. Also agree with Daniel in removing the debug prints.
' | ||
+ @Tables; | ||
|
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.
Remove Debug print statement?
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 part of the query sqlDatabaseIOV2 and is an actual part of the SQL statement, it adds the following when appropriate
CROSS APPLY sys.dm_os_volume_stats(vfs.[database_id], vfs.[file_id]) AS vs
EXEC sp_executesql @SqlStatement | ||
|
||
END | ||
|
||
` | ||
|
||
// Conditional check based on Azure SQL DB, Azure SQL Managed instance OR On-prem SQL Server | ||
// EngineEdition=5 is Azure SQL DB, EngineEdition=8 is Managed instance | ||
|
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 complexity isn't worth it as we have taken a query that you could copy/paste and run to one that has dynamic SQL and to see the SQL generated you have to print it. If there was already dynamic SQL I get changing it to tidy up but if not I wouldn't make a change to dynamic SQL unless is providing value.
About reverting sqlServerPropertiesV2.
I will also change the |
@Trovalo congrats on getting this merged 😃. That was an impressive effort; Thank you! ❤️ |
Required for all PRs:
closes #7292
This PR adds compatibility for all the queries from SQL Server 2008 SP4 and later version, I made a very similar PR some weeks ago, the difference is that this one contains only the minimum to obtain compatibility.
Main changes:
It has been tested on:
Additional Fix:
In the current version of telegraf, in the "performance counters" query, the column [total_cpu_usage_preemptive_ms] is never considered, it is added as follows:
Now that the switches are based on variables (with proper data type) the metric will be loaded for SQL Server 2016 and later, in previous versions it does not exists