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

New sql server queries (on-prem) - refactoring and formatting #8172

Merged
merged 24 commits into from
Oct 14, 2020

Conversation

Trovalo
Copy link
Collaborator

@Trovalo Trovalo commented Sep 23, 2020

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

This PR affects only the SQL Server on-prem queries (database_type = "SQLServer"), a different PR can be opened for the Azure queries (if this is approved).
The PR does not contain any breaking change, the output is the same as before (with minor fixes)

This PR contains:

  • SQL code indentation and formatting
  • SQL code refactoring (nothing breaking)
    • Removed @EngineEdition variables (not used anymore)
    • minor edits/fixes to the "sqlServerRequests" query
      • Removed DB_NAME() as [database_name]
      • added COALESCE for [session_db_name] and [open_transaction] (priority to dm_exec_requests, then dm_exec_sessions)

An additional not breaking fix can be made in the PerfCounters query. on line 436.

	INNER JOIN sys.dm_resource_governor_resource_pools AS rgrp /*No fields from this table. remove?*/
		ON rgwg.[pool_id] = rgrp.[pool_id]

this table is joined, but no data is fetched from it. @denzilribeiro, to me this join can be removed, can you confirm? do you have ideas about why it was there?

@denzilribeiro
Copy link
Contributor

this table is joined, but no data is fetched from it. @denzilribeiro, to me this join can be removed, can you confirm? do you have ideas about why it was there?

That predates my time :)... I am not a big fan of the whole joining with workload groups/pools section as should have been just native perf counters ( not manufactured perf counters). Yes seems like join can be eliminated, in all honesty there are counters for workload groups so perhaps is there only for older versions - I left it there for back compat as didn't have context on why it was added.

@Trovalo
Copy link
Collaborator Author

Trovalo commented Sep 23, 2020

That predates my time :)... I am not a big fan of the whole joining with workload groups/pools section as should have been just native perf counters ( not manufactured perf counters). Yes seems like join can be eliminated, in all honesty there are counters for workload groups so perhaps is there only for older versions - I left it there for back compat as didn't have context on why it was added.

You are right, there are already counters about that, even in SQL 2008. (some sample data below)

object_name counter_name instance_name
MSSQL$SQL2008:Workload Group Stats Active parallel threads internal
MSSQL$SQL2008:Workload Group Stats Active requests internal
MSSQL$SQL2008:Workload Group Stats Blocked tasks internal
MSSQL$SQL2008:Workload Group Stats CPU usage % internal
MSSQL$SQL2008:Workload Group Stats CPU usage % base internal
MSSQL$SQL2008:Workload Group Stats Max request cpu time (ms) internal
MSSQL$SQL2008:Workload Group Stats Max request memory grant (KB) internal
MSSQL$SQL2008:Workload Group Stats Query optimizations/sec internal
MSSQL$SQL2008:Workload Group Stats Queued requests internal
MSSQL$SQL2008:Workload Group Stats Reduced memory grants/sec internal
MSSQL$SQL2008:Workload Group Stats Requests completed/sec internal
MSSQL$SQL2008:Workload Group Stats Suboptimal plans/sec internal

I agree on having only native perf counter so I'll make a PR to remove that section for the new query.

To me that's it, at least for this PR. I'll make some more PRs to remove some sections (the one cited above) or add a few fields.

@denzilribeiro I'd like you to have a quick look at it and if everything's looks fine just approve the changes.
(if you like/agree on the formatting style I'll make a PR to format also the Azure queries)

As usual I've tested this queries on SQL 2008 to 2019 and everything looks fine.

@ssoroka
Copy link
Contributor

ssoroka commented Sep 23, 2020

fine by me. We can merge whenever you're ready.

@Trovalo
Copy link
Collaborator Author

Trovalo commented Sep 24, 2020

Just one more info from @denzilribeiro before merging

I've run some additional tests with database_type = "AzureSQLDB", which fails now.
The reason is that the Azure queries are referencing an on-prem query (Script: sqlServerSchedulers)

queries["AzureSQLDBSchedulers"] = Query{ScriptName: "AzureSQLDBSchedulers", Script: sqlServerSchedulers, ResultByRow: false}

The same is valid also for Managed Instance
queries["AzureSQLMISchedulers"] = Query{ScriptName: "AzureSQLMISchedulers", Script: sqlServerSchedulers, ResultByRow: false}

Now that there is the check based on engine edition, when the schedulers query is called from any Azure edition an error is returned.

--THis is the check
IF SERVERPROPERTY('EngineEdition') NOT IN (2,3,4) BEGIN /*NOT IN Standard,Enterpris,Express*/
	DECLARE @ErrorMessage AS nvarchar(500) = 'Telegraf - the instance "'+ @@SERVERNAME +'" is not a SQL Server Standard,Enterprise or Express. Check the database_type parameter in the telegraf configuration.';
	RAISERROR (@ErrorMessage,11,1)
	RETURN
END

How do you want to address this kind of issue? the query itself is fully compatible but I'm not sure it's a good idea to reference the on-prem query from the azure section.
We can:

  • make the clone of the query to be used by the Azure section
  • create a "shared" query area
  • extend the check on the query (even if "marked" as on-prem) to also include the Azure editions

@Trovalo Trovalo changed the title New sql server queries - refactoring and formatting New sql server queries (on-prem) - refactoring and formatting Sep 24, 2020
@denzilribeiro
Copy link
Contributor

denzilribeiro commented Sep 24, 2020

  • make the clone of the query to be used by the Azure section

@Trovalo thanks for catching it, I would make a clone follow the same pattern rather than mixing/matching.. . Was a huge PR and I missed it :(, updated one part but not the other.
Let me know when all done and will test/take a look

@Trovalo
Copy link
Collaborator Author

Trovalo commented Sep 24, 2020

I'm done. @denzilribeiro you are free to check whenever you want

Copy link
Contributor

@denzilribeiro denzilribeiro left a comment

Choose a reason for hiding this comment

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

In this I would modify the throw of error message to include Database name and server name as logical server on Azure DB can have a ton of databases so won't be able to identify which connection string is incorrectly classified

DECLARE @ErrorMessage AS nvarchar(500) = 'Telegraf - Connection string Server:"'+ @@SERVERNAME + ',Database:' + DB_NAME() +'" is not a SQL Server Standard,Enterprise or Express. Check the database_type parameter in the telegraf configuration.';

Copy link
Collaborator Author

@Trovalo Trovalo left a comment

Choose a reason for hiding this comment

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

I've edited the error message to include the Database name.

I've also removed some DEADLOCK_PRIORITY (where only dmv were referenced), it is now used only in DatabaseIO and PerfCounters queries

@Trovalo
Copy link
Collaborator Author

Trovalo commented Oct 7, 2020

@ssoroka can you merge this?

@ssoroka
Copy link
Contributor

ssoroka commented Oct 7, 2020

Looks like there's conflicts with the other merge.

@Trovalo
Copy link
Collaborator Author

Trovalo commented Oct 7, 2020 via email

@Trovalo
Copy link
Collaborator Author

Trovalo commented Oct 9, 2020

@ssoroka I've fixed the conflict

@Trovalo
Copy link
Collaborator Author

Trovalo commented Oct 14, 2020

@ssoroka can you merge this? I'd like it to be present in the next release of Telegraf.

@ssoroka ssoroka merged commit 1d6172b into influxdata:master Oct 14, 2020
@Trovalo Trovalo deleted the New-SqlServer-Queries-Refactor branch October 14, 2020 15:36
arstercz pushed a commit to arstercz/telegraf that referenced this pull request Mar 5, 2023
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