Added duration of rule execution #49 (#50)

* Added duration of rule execution #49

* Updated CI platforms
This commit is contained in:
Bernie White 2021-08-26 11:43:42 +10:00 коммит произвёл GitHub
Родитель 677f9c820f
Коммит 730685e66c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 34 добавлений и 16 удалений

Просмотреть файл

@ -5,7 +5,7 @@ variables:
version: '0.3.0'
buildConfiguration: 'Release'
disable.coverage.autogenerate: 'true'
imageName: 'ubuntu-18.04'
imageName: 'ubuntu-20.04'
# Use build number format, i.e. 0.3.0-B1811001
name: $(version)-B$(date:yyMM)$(rev:rrr)
@ -136,8 +136,8 @@ stages:
- template: jobs/test.yaml
parameters:
name: ubuntu_18_04_coverage
imageName: 'ubuntu-18.04'
name: ubuntu_20_04_coverage
imageName: 'ubuntu-20.04'
displayName: 'PowerShell coverage'
coverage: 'false'
publishResults: 'false'
@ -159,7 +159,7 @@ stages:
name: ps_7_ubuntu_18_04
displayName: 'PowerShell 7.0 - ubuntu-18.04'
imageName: mcr.microsoft.com/powershell
imageTag: 7.0.3-ubuntu-18.04
imageTag: 7.1.3-ubuntu-18.04
- template: jobs/testContainer.yaml
parameters:
@ -168,13 +168,6 @@ stages:
imageName: mcr.microsoft.com/powershell
imageTag: 7.1.3-ubuntu-20.04
- template: jobs/testContainer.yaml
parameters:
name: ps_6_ubuntu_18_04
displayName: 'PowerShell 6.2 - ubuntu-18.04'
imageName: mcr.microsoft.com/powershell
imageTag: 6.2.4-ubuntu-18.04
# Release pipeline
- stage: Release
displayName: Release

1
.vscode/settings.json поставляемый
Просмотреть файл

@ -20,6 +20,7 @@
"editor.tabSize": 2
},
"cSpell.words": [
"Kusto",
"cmdlet",
"cmdlets",
"hashtable"

Просмотреть файл

@ -2,6 +2,11 @@
## Unreleased
What's changed since pre-release v0.3.0-B2108008:
- General improvements:
- Added `Duration_d` that duration in milliseconds that the rule took to execute. [#49](https://github.com/microsoft/PSRule.Monitor/issues/49)
## v0.3.0-B2108008 (pre-release)
What's changed since v0.2.0:

Просмотреть файл

@ -1,8 +1,8 @@
# PSRule to Azure Monitor
# PSRule for Azure Monitor
Log PSRule analysis results to Azure Monitor.
![ci-badge]
[![Open in Visual Studio Code](https://open.vscode.dev/badges/open-in-vscode.svg)](https://open.vscode.dev/microsoft/PSRule.Monitor)
## Support
@ -16,9 +16,10 @@ If you have any problems with the [PSRule][engine] engine, please check the proj
Support for this project/ product is limited to the resources listed above.
## Getting the modules
## Getting the module
This project requires the `PSRule` PowerShell module. For details on each see [install].
This project requires the `PSRule` PowerShell module.
For detail on installation and dependencies see [install].
You can download and install these modules from the PowerShell Gallery.
@ -111,9 +112,11 @@ $results | Send-PSRuleMonitorRecord -WorkspaceId <workspaceId> -SharedKey <prima
### Querying logs from Azure Monitor
By default, PSRule results are stored in the `PSRule_CL` table.
The results can be queries from the Log Analytics workspace using Kusto.
The following query returns all rule records from the last hour that failed:
```text
```kusto
PSRule_CL
| where Outcome_s == "Fail" and TimeGenerated > ago(1h)
```

Просмотреть файл

@ -0,0 +1,12 @@
# Sample queries
## Slowest rules
Get the top 10 slowest rules to execute by average execution time in milliseconds.
```kusto
PSRule_CL
| where TimeGenerated >= ago(30d) and isnotnull(Duration_d)
| summarize Avg_ms = avg(Duration_d), Max_ms = max(Duration_d), Min_ms = min(Duration_d), Count = count() by RuleId_s
| top 10 by Avg_ms desc nulls last
```

Просмотреть файл

@ -41,5 +41,7 @@ namespace PSRule.Monitor.Data
public string RunId { get; set; }
public Guid CorrelationId { get; set; }
public long Duration { get; set; }
}
}

Просмотреть файл

@ -94,6 +94,7 @@ namespace PSRule.Monitor.Pipeline
var moduleName = GetField(info, "moduleName");
var annotations = GetProperty(info, "annotations");
var runId = GetPropertyValue(sourceObject, "runId");
var duration = GetProperty<long>(sourceObject, "time");
var record = new LogRecord
{
RuleId = ruleId,
@ -109,6 +110,7 @@ namespace PSRule.Monitor.Pipeline
Annotations = GetPropertyMap(annotations),
RunId = runId,
CorrelationId = _CorrelationId,
Duration = duration,
};
return record;
}