Skip to content

Commit c98809a

Browse files
authored
Merge pull request #1059 from aguzev/sql_assessment_api_docs_update
Update SQL Assessment API docs
2 parents 1104afe + 0c5f2ef commit c98809a

16 files changed

Lines changed: 254 additions & 25 deletions
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Message template
2+
3+
## Overview
4+
5+
A check produces a recommendation message specified in the [__mesasge__](./Rule.md#message) property. The message can contain data returned from a probe or calculated by the check.
6+
7+
Message template resembles [C# string interpolation](https://learn.microsoft.com/dotnet/csharp/language-reference/tokens/interpolated). Data variables can be inserted in curly braces preceded by the 'at' sign '@'.
8+
9+
In the following example a probe returns `@indexName`, `@Schema`, and `@Object` string variables. The API will substitute the references in curly braces with actual values.
10+
11+
```json
12+
"message": "Drop hypothetical @{IndexName} index for @{Schema}.@{Object}"
13+
```
14+
15+
Message template supports format specifiers as well. The specifier must follow the variable name separated by a colon ':'. For more information on formatting values see [How to format numbers, dates, enums, and other types in .NET](https://learn.microsoft.com/dotnet/standard/base-types/formatting-types)
16+
17+
In the following example the number `@fragmentation` will be multiplied by 100, rounded to 2 digits after decimal point, and decorated with percent sign '%'.
18+
19+
```json
20+
"message": "Current fragmentation level is @{fragmentation:P2}"
21+
```
22+
23+
Output:
24+
25+
```plain
26+
Current fragmentation level is 37.20%
27+
```
28+
29+
Formatting for string values is extended. The format string will inserted into the resulting message if the value is not null and not an empty string. The pound sign '#' is replaced by the string value itself. This could be useful for adding sentence parts when additional information is present.
30+
31+
Take the following example:
32+
33+
```json
34+
"message": "Create index on @{Table} with key columns @{KeyCols}@{IncludedCols: and included columns: #}"
35+
```
36+
37+
When `@IncludedCols` is empty the message would be
38+
39+
```plain
40+
Create index on MyTable with key columns Id, Name
41+
```
42+
43+
When `@IncludedCols` is contains names of included columns "_SpaceAvailable, CPULoad_", tha message will be:
44+
45+
```plain
46+
Create index on MyTable with key columns Id, name and included columns: SpaceAvailable, CPULoad
47+
```

samples/manage/sql-assessment-api/docs/Customization/Probe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Probes from the default rule set read metadata only, e.g. update logs or server
1212

1313
Probe implementation is represented by a JSON object. Its properties define procedures for getting data and selecting appropriate implementation.
1414

15-
![Probe structure](img\ProbeStructure.svg)
15+
![Probe structure](./img/ProbeStructure.svg)
1616

1717
## Probe properties
1818

samples/manage/sql-assessment-api/docs/Customization/ProbeReference.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Data for checks comes from probes. Probe reference is a JSON object that describes a probe needed by the check. When a probe is referenced with no additional options or parameters, a probe reference may be abbreviated to a string containing probe ID.
44

5-
![Probe reference structure](img\ProbeRefStructure.svg)
5+
![Probe reference structure](./img/ProbeRefStructure.svg)
66

77
## Properties
88

@@ -94,9 +94,4 @@ In the following example *DatabaseMasterFiles* probe finds volume IDs for all di
9494
}
9595
}
9696
]
97-
```
98-
99-
100-
101-
102-
97+
```

samples/manage/sql-assessment-api/docs/Customization/Rule.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A rule is represented by a JSON object. A rule applies its properties to a new or existing check.
44

5-
![Rule structure](img\RuleStructure.svg)
5+
![Rule structure](./img/RuleStructure.svg)
66

77
## Rule properties
88

@@ -24,19 +24,19 @@ An array of IDs or tags of checks to be modified by this rule. A rule can modify
2424

2525
### target
2626

27-
Target pattern is a JSON object used to select applicable rules. A rule will be applied if the assessed object matches the `target` pattern. For more information, see [Target pattern]().
27+
Target pattern is a JSON object used to select applicable rules. A rule will be applied if the assessed object matches the `target` pattern. For more information, see [Target pattern](./TargetPattern.md).
2828

2929
### targetFilter
3030

31-
Target pattern with the same syntax as the target property, but used exclusively in overrides. For more information on the usage and object format, see [Overrides]() and [Target pattern](), respectively.
31+
Target pattern with the same syntax as the target property, but used exclusively in overrides. For more information on the usage and object format, see [Overrides](./RulesandProbes.md) and [Target pattern](./TargetPattern.md), respectively.
3232

3333
### displayName
3434

3535
Short display names are shown in checklists. You may think of a display name as of a file name if a rule was stored in a separate file. Usually, the display name tells what the check is looking for.
3636

3737
### message
3838

39-
A string which is used as a template for generating messages to the user. Such a message appears when the check detects configurations that are not in compliance with the best practice recommendation. For more information, see [Message template]().
39+
A string which is used as a template for generating messages to the user. Such a message appears when the check detects configurations that are not in compliance with the best practice recommendation. For more information, see [Message template](./MessageTemplate.md).
4040

4141
### description
4242

@@ -54,7 +54,7 @@ The severity level of the issue detected by this check.
5454

5555
### probes
5656

57-
The `probes` array contains references to probes to be used to get data required by this check. For more information, see [Probe References]().
57+
The `probes` array contains references to probes to be used to get data required by this check. For more information, see [Probe References](./ProbeReference.md).
5858

5959
### condition
6060

samples/manage/sql-assessment-api/docs/Customization/RulesandProbes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Understanding rules and probes
22

3-
The SQL Assessment API uses sets of best practice recommendations to check if a SQL Server environment or configuration could be improved. Best practices are not universal. Guidelines depend on SQL Server version, edition, and configuration, hosting platform, and even usage pattern. For example, some best practices are applicable only to cloud environments, whereas others work for SQL Server instances installed on a physical machine. Databases may also be of different types. For example, a set of best practices for the `msdb` database might be different from that used for user databases.
3+
The SQL Assessment API uses sets of best practice recommendations to check if a SQL Server environment or configuration could be improved. Best practices are not universal. Guidelines depend on SQL Server version, edition, and configuration, hosting platform, and even usage pattern. For example, some best practices are applicable only to cloud environments, whereas others work for SQL Server instances installed on a physical machine. Databases may also be of different types. For example, a set of best practices for the `msdb` database might be different from that used for user databases.
44

55
SQL Assessment API makes recommendations more specific by implementing a two-step process:
66

@@ -82,7 +82,7 @@ The following rule disables the `MaxMemory` check and all performance-related ch
8282

8383
Each check needs data to analyze. Checks do not retrieve any data from the target server or database but refer to *probes* instead. Most of the probes use T-SQL queries, but the SQL Assessment API also supports probes for WMI, Windows registry, Azure Instance Metadata Service, as well as custom probes implemented as .NET classes.
8484

85-
Each probe returns zero or more data rows containing named items. If a check gets data from multiple probes, the resulting data set is constructed as *all* combinations of rows. This behavior is similar to `CROSS JOIN` in T-SQL.
85+
Each probe returns zero or more data rows containing named items. If a check gets data from multiple probes, the resulting data set is constructed as *all* combinations of rows. This behavior is similar to `CROSS JOIN` in T-SQL.
8686

8787
A check has a condition expression which formally describes best practice as an arithmetic expression referring to data from a data row. Condition is calculated and checked if it holds for each row separately. For example, when a database uses 3 disks for storing its files, then a free space best practice may apply to each disk independently. If a check uses data from two probes, and one probe produces 2 rows while another one produces 3, the check condition will be evaluated 2×3=6 times. If condition gives *false* 2 times out of 6, the check will produce 2 messages.
8888

samples/manage/sql-assessment-api/docs/Customization/RulesetFileStructure.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
Rule set is stored in a text file that contains a JSON object. The rule set object has three simple mandatory properties: `name`, `version`, and `schemaVersion`. The latter specifies the file format version. As of the time of writing this document, the file format version is 1.0. The `name` and `version` properties comprise the identity of the set.
55

6-
An essential part of a ruleset is the optional `rules` property that stores an array of SQL Assessment API rules. Rules are used to build a checklist. For more information, see [Understanding Rules and Probes](.\RulesandProbes.md).
6+
An essential part of a ruleset is the optional `rules` property that stores an array of SQL Assessment API rules. Rules are used to build a checklist. For more information, see [Understanding Rules and Probes](./RulesandProbes.md).
77

8-
The optional `probes` property contains definitions for probes. Probes are used to get actual data from target SQL Server instances, hosting machines, and other sources. Each probe definition is a JSON array of one or more implementations. For more information, see [Probes](..\Reference\Probes\README.md).
8+
The optional `probes` property contains definitions for probes. Probes are used to get actual data from target SQL Server instances, hosting machines, and other sources. Each probe definition is a JSON array of one or more implementations. For more information, see [Probes](../Reference/Probes/README.md).
99

1010
The `rules` and `probes` properties are optional because rules from one ruleset can use probes from another one.
1111

12-
![Ruleset Structure](img\RulesetStructure.svg)
12+
![Ruleset Structure](./img/RulesetStructure.svg)
1313

1414
```json
1515
{
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Target pattern
2+
3+
Target pattern specifies criteria for filtering rules and probe implementations. A rule will be applied to those SQL Server instances and databases, which match the rule's [target](./Rule.md#target) pattern.
4+
5+
this mechanism allows rules specific to certain SQL Server versions or editions, or even specific to a certain database. When used in custom rulesets, SQL Server instances can be distinguished by name to apply different rules. For example, servers servers used for application development might not need frequent backups.
6+
7+
## Target pattern structure
8+
9+
Target pattern is represented by a JSON object of the following structure. All properties are optional. Every value is a match when a property is omitted.
10+
11+
![Target pattern structure](./img/TargetPatternStructure.svg)
12+
13+
### engineEdition
14+
15+
__Allowed values__: `PersonalOrDesktopEngine`, `Standard`, `Enterprise`, `Express`, `AzureDatabase`, `DataWarehouse`, `StretchDatabase`, `ManagedInstance`;
16+
17+
`Azure` = `AzureDatabase`, `DataWarehouse`, `StretchDatabase`, `ManagedInstance`;
18+
19+
`SqlServer` = `PersonalOrDesktopEngine`, `Standard`, `Enterprise`, `Express`.
20+
21+
Any combination of comma-separated values above is allowed. Lists SQL Server engine editions matching this target pattern. `Azure` and `SqlServer` are short names for frequently used lists.
22+
23+
In the following example __engineEdition__ is any on-premises edition or Azure Managed Instance.
24+
25+
```json
26+
"engineEdtion": "SqlServer, ManagedInstance"
27+
```
28+
29+
### name
30+
31+
A [string pattern](#string-pattern) for the target SQL
32+
Server object name. It's a database name or an instance name.
33+
34+
In the following example __name__ matches anything except _master_, _tempdb_, and _model_.
35+
36+
```json
37+
"name": { "not": [ "master", "tempdb", "model"]}
38+
```
39+
40+
### machineType
41+
42+
A [string pattern](#string-pattern) for the type of machine hosting target SQL Server instance.
43+
44+
Supported machine type values are: `Physical`, `AzureVm`, `Hypervisor`, `Other`.
45+
46+
In the following example any physical or Azure virtual machine mathes the pattern.
47+
48+
```json
49+
"machineType": ["AzureVm", "Physical"]
50+
```
51+
52+
### platform
53+
54+
A [string pattern](#string-pattern) for the platform of machine hosting target SQL Server instance.
55+
56+
Supported machine type values are: `Windows`, `Linux`.
57+
58+
In the following example Windows and Linux installations match.
59+
60+
```json
61+
"platform": ["Windows", "Linux"]
62+
```
63+
64+
### serverName
65+
66+
A [string pattern](#string-pattern) for the SQL Server instance name. If target is a SQL SErver instance, then _serverName_ equals _name_, otherwise it's the name of SQL Server instance hosting the target object.
67+
68+
In the following example all instances match except those with names ending with _Test_.
69+
70+
```json
71+
"serverName": {"not": "/*.Test$/"}
72+
```
73+
74+
### type
75+
76+
__Allowed values__: `Server`, `Database`.
77+
78+
Any comma-separated list of allowed values defines which type of SQL Server object matches this pattern.
79+
80+
Check's target is always either `Sever` or `Database`. For a probe it's often both.
81+
82+
In the following example only databases match the pattern.
83+
84+
```json
85+
"type": "Database"
86+
```
87+
88+
### version
89+
90+
A [version pattern](#version-pattern) specifying ranges of matching SQL Server versions.
91+
92+
In the following example the pattern matches SQL Server 2016 SP2+, 2014 SP3+, and 2019+.
93+
94+
```json
95+
"version": ["[13.0.5026.0, 14.0)", "[12.0.6024.0, 13.0)", "[15.0)"]
96+
```
97+
98+
## String pattern
99+
100+
String pattern defines matching strings. It can be a string, a JSON object, or a JSON array of string patterns. With arrays, string patterns have a recursive structure. An array matches a string when any of its elements is a match.
101+
102+
A string pattern can be an arbitrary string. In this case SQL Assessment API looks for an exact match.
103+
104+
When the string starts and ends with slash '/' ti represents a [regular expression](#regular-expression).
105+
106+
When string pattern is represented by a JSON object, it may have only one property named __not__. The property value must be any string pattern. This means that the pattern matches anything which is not a match for the __not__property value.
107+
108+
For example, the following matches anything that does not end with _Test_.
109+
110+
```json
111+
{ "not": "/*.Test$/c" }
112+
```
113+
114+
### Regular expression
115+
116+
Regular expressions are enclosed in slashes: `"/Win*./"`. Regular expression options can be specified after the closing slash. For example, this is the case sensitive search: `"/win.*/c"`. If the string does not start with a slash, it is treated as an exact string match. The string "_Linux_" is equivalent to the regular expression "_/^Linux$/_".
117+
118+
SQL Assessment API supports [.NET Regular Expressions.](https://learn.microsoft.com/dotnet/standard/base-types/regular-expressions).
119+
120+
Regular expression options are listed in the [Regular expression options](https://learn.microsoft.com/dotnet/standard/base-types/regular-expression-options) article.
121+
122+
__NOTE:__ Regular expressions are case-insensitive by default. For case-sensitive matching use 'c' option.
123+
124+
125+
## Version pattern
126+
127+
The version range list is a single [version range](#version-range) or an array of version ranges. A single version range is equivalent to an array containing the only element. The version range list matches any version matching any of its ranges.
128+
129+
```json
130+
"version": [
131+
"[10.0.4326,10.0.4371]",
132+
"[10.0.5794,10.50)",
133+
"[10.50.2806,11.0)",
134+
"[11.0.2316,)"
135+
]
136+
```
137+
138+
### Version range
139+
140+
A range of versions is encoded by a string. The string contains one or two versions delimited by the comma and enclosed into optional parenthesis or brackets. If there are two versions, the former version must be less than or equal to the latter. They represent the range boundaries. The version must be specified at least by two numbers separated by the period: major and minor version numbers.
141+
142+
Th version range format follows [Nuget version range format](https://learn.microsoft.com/nuget/concepts/package-versioning#version-ranges).
143+
144+
|Version Range|Matches|
145+
|-|-|
146+
|"10.0"|Version 10.0 exactly.|
147+
|"[10.0, 13.0]"|Anything between 10.0 and 13.0, inclusive: 10.0, 10.50, 11.0.345, 13.0.|
148+
|"(10.0, 13.0)"|Anything between 10.0 and 13.0, exclusive: 10.50, 11.0.345. Does not match 10.0 or 13.0.|
149+
|"[10.0, 13.1)"|Anything between 10.0 and 13.1, excluding the right boundary: 10.0, 10.50, 11.0.345, 13.0, 13.0.234. Does not match 13.1.|
150+
|"(10.0, 13.1]"|Anything between 10.0 and 13.1, excluding 10.0.|
151+
|"[10.0,)"|10.0 and abo|
152+
|"(10.0,)"|Above 10.0, but not itself|
153+
|"(,10.0]"|10.0 or below|
154+
|"(,10.0)"|Below 10.0, but not 10.0.|

0 commit comments

Comments
 (0)