Skip to content

Commit

Permalink
Update to Credo 1.7.9. (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
conradwt authored Nov 4, 2024
1 parent 6aaed13 commit 5390a55
Show file tree
Hide file tree
Showing 20 changed files with 358 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defmodule ZeroPhoenix.Mixfile do
{:absinthe, "~> 1.7.8"},
{:absinthe_plug, "~> 1.5.8"},
{:cors_plug, "~> 3.0.3"},
{:credo, "~> 1.7.8", only: [:dev, :test], runtime: false},
{:credo, "~> 1.7.9", only: [:dev, :test], runtime: false},
{:mix_test_watch, "~> 1.1.2", only: [:dev, :test], runtime: false},
{:ecto_psql_extras, "~> 0.7.15"}
]
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"cowboy": {:hex, :cowboy, "2.10.0", "ff9ffeff91dae4ae270dd975642997afe2a1179d94b1887863e43f681a203e26", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "3afdccb7183cc6f143cb14d3cf51fa00e53db9ec80cdcd525482f5e99bc41d6b"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
"cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"},
"credo": {:hex, :credo, "1.7.8", "9722ba1681e973025908d542ec3d95db5f9c549251ba5b028e251ad8c24ab8c5", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "cb9e87cc64f152f3ed1c6e325e7b894dea8f5ef2e41123bd864e3cd5ceb44968"},
"credo": {:hex, :credo, "1.7.9", "07bb31907746ae2b5e569197c9e16c0d75c8578a22f01bee63f212047efb2647", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "f87c11c34ba579f7c5044f02b2a807e1ed2fa5fdbb24dc7eb4ad59c1904887f3"},
"dataloader": {:hex, :dataloader, "1.0.10", "a42f07641b1a0572e0b21a2a5ae1be11da486a6790f3d0d14512d96ff3e3bbe9", [:mix], [{:ecto, ">= 3.4.3 and < 4.0.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:telemetry, "~> 1.0 or ~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "54cd70cec09addf4b2ace14cc186a283a149fd4d3ec5475b155951bf33cd963f"},
"db_connection": {:hex, :db_connection, "2.7.0", "b99faa9291bb09892c7da373bb82cba59aefa9b36300f6145c5f201c7adf48ec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "dcf08f31b2701f857dfc787fbad78223d61a32204f217f15e881dd93e4bdd3ff"},
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
Expand Down
165 changes: 165 additions & 0 deletions performance/01-load-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import { check, sleep } from 'k6';
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';

const http = new Httpx({
baseURL: 'http://localhost:4000',
headers: {
'Content-Type': 'application/json',
},
});

const pauseMin = 2;
const pauseMax = 6;

export const options = {
discardResponseBodies: true,
ext: {
loadimpact: {
projectID: 3651337,
name: 'Zero to GraphQL Using Elixir',
distribution: {
'amazon:us:ashburn': { loadZone: 'amazon:us:ashburn', percent: 100 }
},
apm: [],
},
},
thresholds: {
// load_generator_memory_used_percent: [{ threshold: 'value<=80', abortOnFail: true }],
// load_generator_cpu_percent: [{ threshold: 'value<=80', abortOnFail: true }],
http_req_failed: [{ threshold: 'rate<0.01', abortOnFail: true }], // http errors should be less than 1%, otherwise abort the test
http_req_duration: ['p(95) <= 100'], // 95% of the requests must complete in 100ms.
http_req_duration: ['p(99) <= 100'], // 99% of the requests must complete in 100ms.
},
scenarios: {
getPersonByID: {
executor: 'ramping-vus',
// gracefulStop: '30s',
startVUs: 0,
stages: [
{ duration: '1m', target: 20 }, // ramp up
{ duration: '1m30s', target: 20 }, // stable
{ duration: '1m', target: 0 }, // ramp down to 0 users
],
// gracefulRampDown: '30s',
gracefulRampDown: '0s',
exec: 'getPersonByID',
},
getPeople: {
executor: 'ramping-vus',
// gracefulStop: '30s',
startVUs: 0,
stages: [
{ duration: '1m', target: 20 }, // ramp up
{ duration: '1m30s', target: 20 }, // stable
{ duration: '1m', target: 0 }, // ramp down to 0 users
],
// gracefulRampDown: '30s',
gracefulRampDown: '0s',
exec: 'getPeople',
},
},
}

// Scenario: getPersonByID (executor: ramping-vus)

export function getPersonByID() {
// Get Person By ID
_getPersonByID(randomIntBetween(1, 4))

// Add random delay
sleep(randomIntBetween(pauseMin, pauseMax))
}

export async function _getPersonByID(id) {
const query = `
query GetPersonByID($id: ID!) {
person(id: $id) {
firstName
lastName
username
email
friends {
firstName
lastName
username
email
}
}
}
`;

const response = await http.asyncPost(
'/graphql',
JSON.stringify({
query: query,
variables: {
id: id
}
},
{
tags: {
name: 'getPersonByID'
}
})
)

// check that response is 200
check(response, {
"status was 200": (r) => r.status === 200
})
}

// Scenario: getPeople (executor: ramping-vus)

export function getPeople() {
// Get People
_getPeople()

// Add random delay
sleep(randomIntBetween(pauseMin, pauseMax))
}

export async function _getPeople() {
const query = `
query GetPeople {
people {
id
firstName
lastName
username
email
friends {
id
firstName
lastName
username
email
}
}
}
`;

const response = await http.asyncPost(
'/graphql',
JSON.stringify({
query: query
},
{
tags: {
name: 'getPeople'
}
})
)

// check that response is 200
check(response, {
"status was 200": (r) => r.status === 200
})
}

export async function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
165 changes: 165 additions & 0 deletions performance/02-stress-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import { check, sleep } from 'k6';
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';
import { SharedArray } from 'k6/data';

var hostname = __ENV.hostname;
if (hostname == null) hostname = 'localhost:4000';

export const options = {
discardResponseBodies: true,
ext: {
loadimpact: {
projectID: 3651337,
name: 'Zero to GraphQL Using Elixir',
distribution: {
'amazon:us:ashburn': { loadZone: 'amazon:us:ashburn', percent: 100 }
},
apm: [],
},
},
thresholds: {
// load_generator_memory_used_percent: [{ threshold: 'value<=80', abortOnFail: true }],
// load_generator_cpu_percent: [{ threshold: 'value<=80', abortOnFail: true }],
http_req_duration: ['p(95)<=100'], // 95% of the requests must complete
http_req_duration: ['p(99)<=100'], // 99% of the requests must complete
},
scenarios: {
getPersonByID: {
executor: 'shared-iterations',
gracefulStop: '30s',
stages: [
{ duration: '1m', target: 200 }, // ramp up
{ duration: '5m', target: 200 }, // stable
{ duration: '1m', target: 800 }, // ramp up
{ duration: '5m', target: 800 }, // stable
{ duration: '1m', target: 1000 }, // ramp up
{ duration: '5m', target: 1000 }, // stable
{ duration: '5m', target: 0 }, // ramp down to 0 users
],
gracefulRampDown: '30s',
exec: 'getPersonByID',
},
getPeople: {
executor: 'shared-iterations',
gracefulStop: '30s',
stages: [
{ duration: '1m', target: 200 }, // ramp up
{ duration: '5m', target: 200 }, // stable
{ duration: '1m', target: 800 }, // ramp up
{ duration: '5m', target: 800 }, // stable
{ duration: '1m', target: 1000 }, // ramp up
{ duration: '5m', target: 1000 }, // stable
{ duration: '5m', target: 0 }, // ramp down to 0 users
],
gracefulRampDown: '30s',
exec: 'getPeople',
},
},
}


// Scenario: getPersonByID (executor: ramping-vus)

export function getPersonByID() {
// Get Person By ID
getPersonByID(randomIntBetween(1, 4))

// Add random delay
sleep(randomIntBetween(pauseMin, pauseMax))
}

export async function getPersonByID(id) {
const query = gql`
query GetPersonByID($id: ID!) {
person(id: $id) {
firstName
lastName
username
email
friends {
firstName
lastName
username
email
}
}
}
`;

http.addHeader('Content-Type', 'application/json')

const response = await http.asyncPost(
'http://localhost:4000/graphql',
JSON.stringify({
query: query,
variables: {
id: id
}
},
{
tags: {
name: 'getPersonByID'
}
})
)

check(response, {
"status was 200": (r) => r.status === 200
})
}

// Scenario: getPeople (executor: ramping-vus)

export function getPeople() {
// Get People
getPeople()

// Add random delay
sleep(randomIntBetween(pauseMin, pauseMax))
}

export async function getPeople() {
const query = gql`
query GetPeople {
people {
id
firstName
lastName
username
email
friends {
id
firstName
lastName
username
email
}
}
}
`;

http.addHeader('Content-Type', 'application/json')

const response = await http.asyncPost(
'http://localhost:4000/graphql',
JSON.stringify({
query: query
},
{
tags: {
name: 'getPeople'
}
})
)

check(response, {
"status was 200": (r) => r.status === 200
})
}

export async function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added performance/02-stress-test/stress-test.js.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions performance/03-spike-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { sleep, check } from 'k6';
import { SharedArray } from 'k6/data';

var hostname = __ENV.hostname;
if (hostname == null) hostname = 'localhost:5157';

export const options = {
stages: [
{ duration: '30s', target: 2000 }, // ramp up
{ duration: '2m', target: 2000 }, // stable
{ duration: '30s', target: 0 }, // ramp-down to 0 users
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions performance/04-soak-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { sleep, check } from 'k6';
import { SharedArray } from 'k6/data';

var hostname = __ENV.hostname;
if (hostname == null) hostname = 'localhost:5157';

export const options = {
stages: [
{ duration: '5m', target: 200 }, // ramp up
{ duration: '8h', target: 200 }, // stable
{ duration: '5m', target: 0 }, // ramp-down to 0 users
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5390a55

Please sign in to comment.