Skip to content

Commit

Permalink
Merge pull request #1516 from pulumi/tg/add-perf-test
Browse files Browse the repository at this point in the history
add performance test including policy packs
  • Loading branch information
tgummerer authored Nov 13, 2023
2 parents eb90668 + 1042d8b commit 36a45b4
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 2 deletions.
2 changes: 2 additions & 0 deletions misc/benchmarks/policy-pack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/
/node_modules/
2 changes: 2 additions & 0 deletions misc/benchmarks/policy-pack/PulumiPolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
runtime: nodejs
description: A minimal Policy Pack for AWS using TypeScript.
18 changes: 18 additions & 0 deletions misc/benchmarks/policy-pack/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as aws from "@pulumi/aws";
import { PolicyPack, validateResourceOfType } from "@pulumi/policy";

new PolicyPack("aws-typescript", {
policies: [{
name: "s3-no-public-read",
description: "Prohibits setting the publicRead or publicReadWrite permission on AWS S3 buckets.",
enforcementLevel: "mandatory",
validateResource: validateResourceOfType(aws.s3.Bucket, (bucket, args, reportViolation) => {

if (bucket.acl === "public-read" || bucket.acl === "public-read-write") {
reportViolation(
"You cannot set public-read or public-read-write on an S3 bucket. " +
"Read more about ACLs here: https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html");
}
}),
}],
});
12 changes: 12 additions & 0 deletions misc/benchmarks/policy-pack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "aws-typescript",
"version": "0.0.1",
"dependencies": {
"@pulumi/aws": "^4.0.0",
"@pulumi/pulumi": "^3.0.0",
"@pulumi/policy": "^1.3.0"
},
"devDependencies": {
"@types/node": "^10.0.0"
}
}
21 changes: 21 additions & 0 deletions misc/benchmarks/policy-pack/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"outDir": "bin",
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"sourceMap": false,
"stripInternal": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true,
},
"files": [
"index.ts"
]
}
28 changes: 26 additions & 2 deletions misc/test/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"log"
"os"
"os/exec"
"path"
"testing"
"time"
Expand Down Expand Up @@ -115,6 +116,29 @@ func TestAccAwsPyS3Folder(t *testing.T) {
programTestAsBenchmark(t, benchmark, test)
}

func TestPolicyPacks(t *testing.T) {
policyPack := path.Join(getCwd(t), "..", "benchmarks", "policy-slow")

// Install the dependencies for the policy pack first
npmInstallCmd := exec.Command("npm", "install")
npmInstallCmd.Dir = policyPack
err := npmInstallCmd.Run()
assert.NoError(t, err)

benchmark := bench("aws-py-s3-folder", "aws", "go", "go")
opts := integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "..", "..", benchmark.Name),
UpdateCommandlineFlags: []string{fmt.Sprintf("--policy-pack=%s", policyPack)},
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
assertHTTPResult(t, "http://"+stack.Outputs["website_url"].(string), nil, func(body string) bool {
return assert.Contains(t, body, "Hello, Pulumi!")
})
},
}
test := getAWSBase(t).With(opts)
programTestAsBenchmark(t, benchmark, test)
}

type manyResourcesConfig struct {
folder string
bench traces.Benchmark
Expand Down Expand Up @@ -181,8 +205,8 @@ func TestManyResources(t *testing.T) {
func programTestAsBenchmark(
t *testing.T,
bench traces.Benchmark,
test integration.ProgramTestOptions) {

test integration.ProgramTestOptions,
) {
// Run preview only to make sure all needed plugins are
// downloaded so that these downloads do not skew
// measurements.
Expand Down

0 comments on commit 36a45b4

Please sign in to comment.