From a5461a46fa6ca7d74f871a793f84c540eae86385 Mon Sep 17 00:00:00 2001 From: Moshe Malka Date: Tue, 5 Nov 2024 19:30:18 +0200 Subject: [PATCH 1/3] fix tests --- .../src/steps/to-azure/to-azure-prom-alerting-rule.test.ts | 2 +- .../to-azure/to-azure-prom-rule-group-properties.test.ts | 2 +- tools/az-prom-rules-converter/src/steps/yaml2json.test.ts | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/az-prom-rules-converter/src/steps/to-azure/to-azure-prom-alerting-rule.test.ts b/tools/az-prom-rules-converter/src/steps/to-azure/to-azure-prom-alerting-rule.test.ts index b136da294..ef3935a23 100644 --- a/tools/az-prom-rules-converter/src/steps/to-azure/to-azure-prom-alerting-rule.test.ts +++ b/tools/az-prom-rules-converter/src/steps/to-azure/to-azure-prom-alerting-rule.test.ts @@ -7,7 +7,7 @@ test('Empty source should add the default properties', () => { const converted = toAzurePromAlertingRule(({} as AlertingRule), {actionGroupId: 'actionGroupId'}); expect(converted.severity).toBe(3); expect(converted.resolveConfiguration).toEqual({ - autoResolve: true, + autoResolved: true, timeToResolve: "PT10M" }); expect(converted.actions[0].actionGroupId).toBe("[parameters('actionGroupId')]"); diff --git a/tools/az-prom-rules-converter/src/steps/to-azure/to-azure-prom-rule-group-properties.test.ts b/tools/az-prom-rules-converter/src/steps/to-azure/to-azure-prom-rule-group-properties.test.ts index e8ad71db2..c28f4911c 100644 --- a/tools/az-prom-rules-converter/src/steps/to-azure/to-azure-prom-rule-group-properties.test.ts +++ b/tools/az-prom-rules-converter/src/steps/to-azure/to-azure-prom-rule-group-properties.test.ts @@ -43,7 +43,7 @@ test('Distinguish between alerting and recording rule', () => { expect(converted.rules[1].alert).toBe("alertName"); expect(converted.rules[1].severity).toBe(3); expect(converted.rules[1].resolveConfiguration).toEqual({ - autoResolve: true, + autoResolved: true, timeToResolve: "PT10M" }); expect(converted.rules[1].actions[0].actionGroupId).toBe("[parameters('actionGroupId')]"); diff --git a/tools/az-prom-rules-converter/src/steps/yaml2json.test.ts b/tools/az-prom-rules-converter/src/steps/yaml2json.test.ts index 0b46cba4e..8f3a2b0b2 100644 --- a/tools/az-prom-rules-converter/src/steps/yaml2json.test.ts +++ b/tools/az-prom-rules-converter/src/steps/yaml2json.test.ts @@ -6,5 +6,11 @@ test("Happy flow", () => { expect(json.output).toEqual({bla: 'a'}); }); +test("Json input should return same json", () => { + const json = yaml2json('{"bla": "a"}'); + expect(json.success).toBe(true); + expect(json.output).toEqual({bla: 'a'}); +}); + From 21060ae741866e0986b1a2dafc78907199a2c5e4 Mon Sep 17 00:00:00 2001 From: Moshe Malka Date: Fri, 22 Nov 2024 23:53:56 +0200 Subject: [PATCH 2/3] Features/momalka/add stdi stream support (#1010) [comment]: # (Note that your PR title should follow the conventional commit format: https://conventionalcommits.org/en/v1.0.0/#summary) # PR Description [comment]: # (The below checklist is for PRs adding new features. If a box is not checked, add a reason why it's not needed.) # New Feature Checklist - [ ] List telemetry added about the feature. - [ ] Link to the one-pager about the feature. - [ ] List any tasks necessary for release (3P docs, AKS RP chart changes, etc.) after merging the PR. - [ ] Attach results of scale and perf testing. [comment]: # (The below checklist is for code changes. Not all boxes necessarily need to be checked. Build, doc, and template changes do not need to fill out the checklist.) # Tests Checklist - [ ] Have end-to-end Ginkgo tests been run on your cluster and passed? To bootstrap your cluster to run the tests, follow [these instructions](/otelcollector/test/README.md#bootstrap-a-dev-cluster-to-run-ginkgo-tests). - Labels used when running the tests on your cluster: - [ ] `operator` - [ ] `windows` - [ ] `arm64` - [ ] `arc-extension` - [ ] `fips` - [ ] Have new tests been added? For features, have tests been added for this feature? For fixes, is there a test that could have caught this issue and could validate that the fix works? - [ ] Is a new scrape job needed? - [ ] The scrape job was added to the folder [test-cluster-yamls](/otelcollector/test/test-cluster-yamls/) in the correct configmap or as a CR. - [ ] Was a new test label added? - [ ] A string constant for the label was added to [constants.go](/otelcollector/test/utils/constants.go). - [ ] The label and description was added to the [test README](/otelcollector/test/README.md). - [ ] The label was added to this [PR checklist](/.github/pull_request_template). - [ ] The label was added as needed to [testkube-test-crs.yaml](/otelcollector/test/testkube/testkube-test-crs.yaml). - [ ] Are additional API server permissions needed for the new tests? - [ ] These permissions have been added to [api-server-permissions.yaml](/otelcollector/test/testkube/api-server-permissions.yaml). - [ ] Was a new test suite (a new folder under `/tests`) added? - [ ] The new test suite is included in [testkube-test-crs.yaml](/otelcollector/test/testkube/testkube-test-crs.yaml). --------- Co-authored-by: Moshe Malka Co-authored-by: Vishwanath Co-authored-by: Renato Monteiro <45536168+monteiro-renato@users.noreply.github.com> --- tools/az-prom-rules-converter/README.md | 5 ++ tools/az-prom-rules-converter/dist/cli.js | 25 ++++++-- .../dist/steps/to-arm-template.js | 1 - .../examples/json-example1.json | 18 ++++++ .../examples/result1.json | 62 +++++++++++++++++++ .../template-example.json | 0 .../yaml-example1.yml} | 0 tools/az-prom-rules-converter/package.json | 2 +- tools/az-prom-rules-converter/src/cli.ts | 30 +++++++-- .../az-prom-rules-converter/src/index.test.ts | 32 ++++++++++ tools/az-prom-rules-converter/src/index.ts | 2 +- .../src/steps/to-arm-template.ts | 1 - 12 files changed, 165 insertions(+), 13 deletions(-) create mode 100644 tools/az-prom-rules-converter/examples/json-example1.json create mode 100644 tools/az-prom-rules-converter/examples/result1.json rename tools/az-prom-rules-converter/{test-files => examples}/template-example.json (100%) rename tools/az-prom-rules-converter/{test-files/yaml-example.yml => examples/yaml-example1.yml} (100%) create mode 100644 tools/az-prom-rules-converter/src/index.test.ts diff --git a/tools/az-prom-rules-converter/README.md b/tools/az-prom-rules-converter/README.md index 1740a90fd..1da800ad5 100644 --- a/tools/az-prom-rules-converter/README.md +++ b/tools/az-prom-rules-converter/README.md @@ -36,3 +36,8 @@ Options: -l, --location Rule group location. -h, --help display help for command ``` + +## usage with pipeline +```bash +Get-Content .\examples\yaml-example1.yml | node az-prom-rules-converter +``` \ No newline at end of file diff --git a/tools/az-prom-rules-converter/dist/cli.js b/tools/az-prom-rules-converter/dist/cli.js index 7c33f5f98..274014929 100644 --- a/tools/az-prom-rules-converter/dist/cli.js +++ b/tools/az-prom-rules-converter/dist/cli.js @@ -24,9 +24,10 @@ program.description('Azure Prometheus rule groups tool'); function yaml2arm(inputPath, options, command) { var _a, _b, _c; return __awaiter(this, void 0, void 0, function* () { - const inputAbsolutePath = path_1.default.resolve(inputPath); - const str = (_a = (yield promises_1.default.readFile(inputAbsolutePath))) === null || _a === void 0 ? void 0 : _a.toString(); - const flowResult = (0, _1.default)(str, options); + const inputStr = inputPath ? + (_a = (yield promises_1.default.readFile(path_1.default.resolve(inputPath)))) === null || _a === void 0 ? void 0 : _a.toString() : + yield readStdin(); + const flowResult = (0, _1.default)(inputStr, options); if (flowResult.success == false) { console.error((_b = flowResult.error) === null || _b === void 0 ? void 0 : _b.title); console.error(JSON.stringify((_c = flowResult.error) === null || _c === void 0 ? void 0 : _c.details, null, 2)); @@ -44,7 +45,7 @@ function yaml2arm(inputPath, options, command) { } program //.command('yaml2arm') .description('Convert Prometheus rules Yaml file to ARM template') - .argument('', 'Input Prometheus rule groups Yaml file path.') + .argument('[input]', 'Input Prometheus rule groups Yaml (or Json) file path.') .option('-amw, --azure-monitor-workspace ', 'Azure monitor workspace id\'s that this rule group is scoped to.') .option('-c, --cluster-name ', 'The cluster name of the rule group evaluation.') .option('-a, --action-group-id ', 'The resource id of the action group to use for alerting rules.') @@ -53,3 +54,19 @@ program //.command('yaml2arm') .option('-l, --location ', 'Rule group location.') .action(yaml2arm); program.parse(); +function readStdin() { + return __awaiter(this, void 0, void 0, function* () { + return new Promise((resolve, reject) => { + let input = ''; + process.stdin.on('data', chunk => { + input += chunk; + }); + process.stdin.on('end', () => { + resolve(input); + }); + process.stdin.on('error', err => { + reject(err); + }); + }); + }); +} diff --git a/tools/az-prom-rules-converter/dist/steps/to-arm-template.js b/tools/az-prom-rules-converter/dist/steps/to-arm-template.js index 7aefe654e..768d1f9ca 100644 --- a/tools/az-prom-rules-converter/dist/steps/to-arm-template.js +++ b/tools/az-prom-rules-converter/dist/steps/to-arm-template.js @@ -68,7 +68,6 @@ const getArmTemplateFormat = (params) => { resources: [] }; ['clusterName', 'actionGroupId', 'azureMonitorWorkspace', 'location'].forEach((paramName) => { - console.log(paramName, params[paramName]); if (params[paramName]) { result.parameters[paramName].defaultValue = params[paramName]; } diff --git a/tools/az-prom-rules-converter/examples/json-example1.json b/tools/az-prom-rules-converter/examples/json-example1.json new file mode 100644 index 000000000..8aba1d96e --- /dev/null +++ b/tools/az-prom-rules-converter/examples/json-example1.json @@ -0,0 +1,18 @@ +{ + "groups": [ + { + "name": "example", + "interval": "2m", + "rules": [ + { + "record": "job:http_inprogress_requests:sum", + "expr": "sum by (job) (http_inprogress_requests)" + }, + { + "alert": "alert name", + "expr": "sum by (job) (http_inprogress_requests)" + } + ] + } + ] +} diff --git a/tools/az-prom-rules-converter/examples/result1.json b/tools/az-prom-rules-converter/examples/result1.json new file mode 100644 index 000000000..7bf35645c --- /dev/null +++ b/tools/az-prom-rules-converter/examples/result1.json @@ -0,0 +1,62 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + }, + "clusterName": { + "type": "string", + "metadata": { + "description": "Cluster name" + } + }, + "actionGroupId": { + "type": "string", + "metadata": { + "description": "Action Group ResourceId" + } + }, + "azureMonitorWorkspace": { + "type": "string", + "metadata": { + "description": "ResourceId of Azure monitor workspace to associate to" + } + } + }, + "variables": {}, + "resources": [ + { + "name": "example", + "type": "Microsoft.AlertsManagement/prometheusRuleGroups", + "apiVersion": "2023-03-01", + "location": "[parameters('location')]", + "properties": { + "interval": "PT2M", + "scopes": ["[parameters('azureMonitorWorkspace')]"], + "clusterName": "[parameters('clusterName')]", + "rules": [ + { + "record": "job:http_inprogress_requests:sum", + "expression": "sum by (job) (http_inprogress_requests)" + }, + { + "severity": 3, + "resolveConfiguration": { + "autoResolved": true, + "timeToResolve": "PT10M" + }, + "actions": [ + { + "actionGroupId": "[parameters('actionGroupId')]" + } + ], + "alert": "alert name", + "expression": "sum by (job) (http_inprogress_requests)" + } + ] + } + } + ] +} diff --git a/tools/az-prom-rules-converter/test-files/template-example.json b/tools/az-prom-rules-converter/examples/template-example.json similarity index 100% rename from tools/az-prom-rules-converter/test-files/template-example.json rename to tools/az-prom-rules-converter/examples/template-example.json diff --git a/tools/az-prom-rules-converter/test-files/yaml-example.yml b/tools/az-prom-rules-converter/examples/yaml-example1.yml similarity index 100% rename from tools/az-prom-rules-converter/test-files/yaml-example.yml rename to tools/az-prom-rules-converter/examples/yaml-example1.yml diff --git a/tools/az-prom-rules-converter/package.json b/tools/az-prom-rules-converter/package.json index de767dab8..8615086a7 100644 --- a/tools/az-prom-rules-converter/package.json +++ b/tools/az-prom-rules-converter/package.json @@ -1,6 +1,6 @@ { "name": "az-prom-rules-converter", - "version": "1.0.0", + "version": "1.1.0", "description": "", "main": "dist/index.js", "bin": "dist/cli.js", diff --git a/tools/az-prom-rules-converter/src/cli.ts b/tools/az-prom-rules-converter/src/cli.ts index 78afcf465..922e3922d 100644 --- a/tools/az-prom-rules-converter/src/cli.ts +++ b/tools/az-prom-rules-converter/src/cli.ts @@ -12,9 +12,10 @@ program.description('Azure Prometheus rule groups tool'); // program.version(pack.version); async function yaml2arm(inputPath: string, options: any, command: Command) { - const inputAbsolutePath = path.resolve(inputPath); - const str = (await fs.readFile(inputAbsolutePath))?.toString(); - const flowResult: StepResult = toArmTemplateFlow(str, options); + const inputStr = inputPath ? + (await fs.readFile(path.resolve(inputPath)))?.toString() : + await readStdin(); + const flowResult: StepResult = toArmTemplateFlow(inputStr, options); if (flowResult.success == false){ console.error(flowResult.error?.title); @@ -33,7 +34,7 @@ async function yaml2arm(inputPath: string, options: any, command: Command) { program//.command('yaml2arm') .description('Convert Prometheus rules Yaml file to ARM template') - .argument('', 'Input Prometheus rule groups Yaml file path.') + .argument('[input]', 'Input Prometheus rule groups Yaml (or Json) file path.') .option('-amw, --azure-monitor-workspace ', 'Azure monitor workspace id\'s that this rule group is scoped to.') .option('-c, --cluster-name ', 'The cluster name of the rule group evaluation.') .option('-a, --action-group-id ', 'The resource id of the action group to use for alerting rules.') @@ -42,4 +43,23 @@ program//.command('yaml2arm') .option('-l, --location ', 'Rule group location.') .action(yaml2arm); -program.parse(); \ No newline at end of file +program.parse(); + + +async function readStdin(): Promise { + return new Promise((resolve, reject) => { + let input = ''; + + process.stdin.on('data', chunk => { + input += chunk; + }); + + process.stdin.on('end', () => { + resolve(input); + }); + + process.stdin.on('error', err => { + reject(err); + }); + }); +} \ No newline at end of file diff --git a/tools/az-prom-rules-converter/src/index.test.ts b/tools/az-prom-rules-converter/src/index.test.ts new file mode 100644 index 000000000..d61d2c8ec --- /dev/null +++ b/tools/az-prom-rules-converter/src/index.test.ts @@ -0,0 +1,32 @@ +import yamlToArmTemplateFlow from './index'; +import StepResult from './types/step-result'; +import fs from "fs/promises"; + +describe('toArmTemplateFlow example 1', () => { + let expectedResult: any; + + beforeAll(async () => { + expectedResult = JSON.parse( + await fs.readFile("./examples/result1.json", { encoding: "utf-8" }) + ); + }); + + test('Successful flow with valid YAML input', async () => { + await readFileAndRunFlow("./examples/yaml-example1.yml"); + + }); + + test("Successful flow with valid JSON input", async () => { + await readFileAndRunFlow("./examples/json-example1.json"); + }); + + async function readFileAndRunFlow(examplePath : string) { + const options = {}; + const str = (await fs.readFile(examplePath))?.toString(); + const result: StepResult = yamlToArmTemplateFlow(str, options); + + expect(result.success).toBe(true); + expect(result.output).toEqual(expectedResult); + } + +}); \ No newline at end of file diff --git a/tools/az-prom-rules-converter/src/index.ts b/tools/az-prom-rules-converter/src/index.ts index 7bfd74642..684b9efd0 100644 --- a/tools/az-prom-rules-converter/src/index.ts +++ b/tools/az-prom-rules-converter/src/index.ts @@ -1,6 +1,6 @@ import yaml2json from './steps/yaml2json' import StepResult from './types/step-result' -import validatePromSchema from './steps/validate-prom-schemas' +import validatePromSchema from './steps/validate-prom-schemas' import validateArmTemplate from './steps/validate-arm-template' import toArmTemplate from './steps/to-arm-template' import validateInputNotEmpty from './steps/validate-input-not-empty' diff --git a/tools/az-prom-rules-converter/src/steps/to-arm-template.ts b/tools/az-prom-rules-converter/src/steps/to-arm-template.ts index 2faed4679..becf6dabb 100644 --- a/tools/az-prom-rules-converter/src/steps/to-arm-template.ts +++ b/tools/az-prom-rules-converter/src/steps/to-arm-template.ts @@ -66,7 +66,6 @@ const getArmTemplateFormat = (params: any) : any => { resources: [ ] }; ['clusterName', 'actionGroupId', 'azureMonitorWorkspace', 'location'].forEach( (paramName) => { - console.log(paramName, params[paramName]); if (params[paramName]) { result.parameters[paramName].defaultValue = params[paramName]; } From 620001de9bbb7efe04bf729c0d78d86a0f793807 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:56:52 -0800 Subject: [PATCH 3/3] Bump pascalgn/size-label-action from 0.5.4 to 0.5.5 (#1004) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [pascalgn/size-label-action](https://github.com/pascalgn/size-label-action) from 0.5.4 to 0.5.5.
Release notes

Sourced from pascalgn/size-label-action's releases.

Release 0.5.5

What's Changed

Full Changelog: https://github.com/pascalgn/size-label-action/compare/v0.5.4...v0.5.5

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pascalgn/size-label-action&package-manager=github_actions&previous-version=0.5.4&new-version=0.5.5)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Vishwanath --- .github/workflows/size.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/size.yml b/.github/workflows/size.yml index b719edaf2..c4d58b813 100644 --- a/.github/workflows/size.yml +++ b/.github/workflows/size.yml @@ -11,6 +11,6 @@ jobs: pull-requests: write steps: - name: size-label - uses: "pascalgn/size-label-action@v0.5.4" + uses: "pascalgn/size-label-action@v0.5.5" env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"