-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Naive rate limit test with Artillery
- Loading branch information
Showing
3 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
config: | ||
target: 'https://us-central1-pub-verse-app.cloudfunctions.net/nodejs-moderator-function' | ||
phases: | ||
- duration: 120 # Set the duration of the test in seconds | ||
arrivalRate: 300 # Set the number of new connections per second check OpenAI Moderation limit of the account we use to ensure this is correct | ||
name: "Initial Load Test" | ||
defaults: | ||
headers: | ||
Authorization: "bearer GCLOUD_IDENTITY_TOKEN" | ||
Content-Type: "application/json" | ||
ce-id: "1234567890" | ||
ce-specversion: "1.0" | ||
ce-type: "google.cloud.pubsub.topic.v1.messagePublished" | ||
ce-time: "2020-08-08T00:11:44.895529672Z" | ||
ce-source: "//pubsub.googleapis.com/projects/pub-verse-app/topics/nostr-events" | ||
|
||
scenarios: | ||
- flow: | ||
- post: | ||
url: '/' | ||
json: | ||
message: | ||
data: "eyJjb250ZW50IjoiSSB3YW50IHRvIGtpbGwgeW91IEpvaG4gRG9lIGFuZCBmdWNrIHlvdXIgY29ycHNlIiwiY3JlYXRlZF9hdCI6MTY5NjQzNzM2OSwiaWQiOiJjZGIxM2MzZGUyYTBmODM4ZTdhZDkzZjNkODcxOWM3MjIwNzA2MTFkNWU1Y2Q4NjBkNTEwNGNiMjFiZDNlNjBiIiwia2luZCI6MSwicHVia2V5IjoiZTlmMzZlNzM4ZTZjMDczMDY4ZjA3YjE4NTFiNDA2ZmU1NzM1NDk1MDdkZGMzYzJjMDA3YjkwOGVlMjNiYmQ1MiIsInNpZyI6ImUyOWRiNWUzZTI1NzViMmIzYzVjMTQ4ZDA2Y2VhZDg1MmRmNTVlNmIwMDQwNTE4NDVkZmUzZmE1MmU0MzM4NTY0NTViNDA5YzU5MGY1NDNlMDk0ZWY3ZTc5NmFlODliOWE5NjI4NGE0YzdhYmJiOWJiMWM0Mjk5NjYwMTdmNWFlIiwidGFncyI6W119Cg==" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { execSync } from 'child_process'; | ||
import { | ||
readFileSync, | ||
writeFileSync, | ||
mkdtempSync, | ||
unlinkSync, | ||
rmdirSync, | ||
} from 'fs'; | ||
import { join } from 'path'; | ||
import { tmpdir } from 'os'; | ||
|
||
// Get the identity token | ||
const token = execSync('gcloud auth print-identity-token', { | ||
encoding: 'utf8', | ||
}).trim(); | ||
|
||
// Read the template file | ||
const template = readFileSync('artillery-config.yaml', 'utf8'); | ||
|
||
// Replace YOUR_TOKEN_HERE with the actual token | ||
const config = template.replace('GCLOUD_IDENTITY_TOKEN', token); | ||
|
||
// Create a temporary directory | ||
const tmpDir = mkdtempSync(join(tmpdir(), 'artillery-')); | ||
|
||
// Write the updated config to a temporary config.yml file in the temporary directory | ||
const tmpConfigPath = join(tmpDir, 'config.yml'); | ||
writeFileSync(tmpConfigPath, config); | ||
|
||
try { | ||
// Run Artillery with the updated config | ||
execSync(`artillery run ${tmpConfigPath}`, { stdio: 'inherit' }); | ||
} finally { | ||
// Remove the temporary directory and config file | ||
unlinkSync(tmpConfigPath); | ||
rmdirSync(tmpDir); | ||
} |