Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script to check branches produce the same results #590

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions branch_comparison/diff_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from jsondiff import diff
import json

f = open("branch_comparison/scenarios.json", "r")
SCENARIOS = json.load(f)

if __name__ == "__main__":

for index, scenario in enumerate(SCENARIOS):
master_file = open(f"branch_comparison/results/master_{index}.json", "r")
master_results = json.load(master_file)

async_file = open(f"branch_comparison/results/async_{index}.json", "r")
async_results = json.load(async_file)

d = diff(master_results, async_results)

if d:
print(f"{scenario}: {d}")
43 changes: 43 additions & 0 deletions branch_comparison/generate_async_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from httpx import AsyncClient
import asyncio
import json
from spectacles.client import LookerClient
from spectacles.runner import Runner
import os

f = open("branch_comparison/scenarios.json", "r")
SCENARIOS = json.load(f)


async def get_async_results(
base_url, client_id, client_secret, project_name, validation_args
):

async_client = AsyncClient()

looker_client = LookerClient(
async_client=async_client,
base_url=base_url,
client_id=client_id,
client_secret=client_secret,
)

runner = Runner(looker_client, project_name, remote_reset=True)

async_results = await runner.validate_sql(**validation_args)

return async_results


if __name__ == "__main__":

base_url = "https://spectacles.looker.com"
client_id = os.getenv("LOOKER_CLIENT_ID")
client_secret = os.getenv("LOOKER_CLIENT_SECRET")

for index, scenario in enumerate(SCENARIOS):
results = asyncio.run(
get_async_results(base_url, client_id, client_secret, **scenario)
)
with open(f"branch_comparison/results/async_{index}.json", "w") as f:
json.dump(results, f)
40 changes: 40 additions & 0 deletions branch_comparison/generate_master_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from spectacles.client import LookerClient
from spectacles.runner import Runner
import json
import os

f = open("branch_comparison/scenarios.json", "r")
SCENARIOS = json.load(f)


def get_master_results(
base_url, client_id, client_secret, project_name, validation_args
):

looker_client = LookerClient(
base_url=base_url,
client_id=client_id,
client_secret=client_secret,
)

runner = Runner(
looker_client,
project_name,
remote_reset=True,
)

master_results = runner.validate_sql(**validation_args)

return master_results


if __name__ == "__main__":

base_url = "https://spectacles.looker.com"
client_id = os.getenv("LOOKER_CLIENT_ID")
client_secret = os.getenv("LOOKER_CLIENT_SECRET")

for index, scenario in enumerate(SCENARIOS):
results = get_master_results(base_url, client_id, client_secret, **scenario)
with open(f"branch_comparison/results/master_{index}.json", "w") as f:
json.dump(results, f)
13 changes: 13 additions & 0 deletions branch_comparison/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

source venv/bin/activate

rm branch_comparison/results/*

git checkout master
python3 branch_comparison/generate_master_results.py

git checkout feature/async
python3 branch_comparison/generate_async_results.py

python3 branch_comparison/diff_results.py
105 changes: 105 additions & 0 deletions branch_comparison/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
[
{
"project_name": "looker-demo",
"validation_args": {
"fail_fast": false
}
},
{
"project_name": "looker-demo",
"validation_args": {
"ref": "async-errors",
"fail_fast": false
}
},
{
"project_name": "looker-demo",
"validation_args": {
"ref": "async-errors",
"filters": [
"ecomm/dim_products"
],
"fail_fast": false
}
},
{
"project_name": "looker-demo",
"validation_args": {
"ref": "async-errors",
"filters": [
"*/*"
],
"fail_fast": false
}
},
{
"project_name": "looker-demo",
"validation_args": {
"ref": "async-errors",
"fail_fast": true
}
},
{
"project_name": "looker-demo",
"validation_args": {
"ref": "async-errors",
"incremental": true,
"fail_fast": false
}
},
{
"project_name": "looker-demo",
"validation_args": {
"ref": "async-incremental-fix",
"incremental": true,
"fail_fast": false
}
},
{
"project_name": "looker-demo",
"validation_args": {
"ref": "async-incremental-fix",
"incremental": true,
"target": "async-errors",
"fail_fast": false
}
},
{
"project_name": "looker-demo",
"validation_args": {
"ref": "async-new-explore",
"incremental": true,
"fail_fast": false
}
},
{
"project_name": "looker-demo",
"validation_args": {
"ref": "async-new-explore",
"fail_fast": false
}
},
{
"project_name": "looker-demo",
"validation_args": {
"ref": "async-incremental-changes",
"incremental": true,
"target": "async-errors",
"fail_fast": false
}
},
{
"project_name": "looker-demo",
"validation_args": {
"ref": "async-does-not-exist",
"fail_fast": false
}
},
{
"project_name": "spectacles",
"validation_args": {
"ref": "charter-demo-3",
"fail_fast": false
}
}
]