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

Add additional catalog indexes for performance #154

Merged
merged 35 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3cfe2be
add additional catalog indexes for performance
wagoodman Jan 24, 2023
2f5d2d0
[wip] link resolution
wagoodman Jan 27, 2023
21001f1
add leaf link resolution on tree responses (defer ancestor link resol…
wagoodman Jan 27, 2023
3583f6b
add filetree search context
wagoodman Jan 30, 2023
58b595c
add tests for new search context object
wagoodman Jan 30, 2023
6b9223f
remove unused tar header fields from file.Metadata struct
wagoodman Jan 30, 2023
47e967a
use singular file type definitions
wagoodman Jan 30, 2023
30c7567
add logging for filetree searches
wagoodman Jan 31, 2023
6495556
add limited support for glob classes and alternatives
wagoodman Jan 31, 2023
d9f6732
add failing test to show that index shortcircuits correct behavior
wagoodman Jan 31, 2023
61da85b
add link resolution via filetree search context
wagoodman Feb 1, 2023
1cf1864
allow index symlink resolution to function through cycles
wagoodman Feb 1, 2023
efce1d4
add tests for filetree.Index
wagoodman Feb 1, 2023
0b18b25
add search by parent basename and fix requirements filtering
wagoodman Feb 1, 2023
b59e489
sort search results
wagoodman Feb 1, 2023
e2c6d5d
change file.Type to int + fix layer 0 squashed search context
wagoodman Feb 2, 2023
5dbc9e9
more cleanup
wagoodman Feb 3, 2023
033d3e4
switch to generic set implementation
wagoodman Feb 3, 2023
d19e1be
update linter
wagoodman Feb 3, 2023
561c286
replace generic set implemetation with plain set (unstable in go1.19)
wagoodman Feb 3, 2023
53005d8
introduce filtree builter and foster usage of reader interfaces
wagoodman Feb 3, 2023
6b109bb
rename content helper functions
wagoodman Feb 3, 2023
a2eecb6
update docs with background
wagoodman Feb 4, 2023
1ec3d77
fix get_xid for cross compilation
wagoodman Feb 5, 2023
33fb3e2
upgrade CI validations workflow
wagoodman Feb 5, 2023
b0fc172
fix snapshot builds
wagoodman Feb 5, 2023
53dbcca
add tests for file.Index.GetByFileType
wagoodman Feb 6, 2023
c5bfa98
rename file.Type and file.Resolution
wagoodman Feb 7, 2023
386c945
ensure that glob results match search facade
wagoodman Feb 7, 2023
307ac9b
replace stringset implementation + move resolution tests
wagoodman Feb 7, 2023
4f28a64
add note about podman dependency for testing
wagoodman Feb 7, 2023
db2e56d
address PR comments
wagoodman Feb 8, 2023
d54c328
remove extra whitespace
wagoodman Feb 8, 2023
3153d53
constrain OS build support
wagoodman Feb 8, 2023
90b1ac4
update/remove TODO comments
wagoodman Feb 8, 2023
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
80 changes: 80 additions & 0 deletions .github/actions/bootstrap/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: "Bootstrap"
description: "Bootstrap all tools and dependencies"
inputs:
go-version:
description: "Go version to install"
required: true
default: "1.19.x"
use-go-cache:
description: "Restore go cache"
required: true
default: "true"
cache-key-prefix:
description: "Prefix all cache keys with this value"
required: true
default: "831180ac25"
build-cache-key-prefix:
description: "Prefix build cache key with this value"
required: true
default: "f8b6d31dea"
bootstrap-apt-packages:
description: "Space delimited list of tools to install via apt"
default: ""

runs:
using: "composite"
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ inputs.go-version }}

- name: Restore tool cache
id: tool-cache
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/.tmp
key: ${{ inputs.cache-key-prefix }}-${{ runner.os }}-tool-${{ hashFiles('Makefile') }}

# note: we need to keep restoring the go mod cache before bootstrapping tools since `go install` is used in
# some installations of project tools.
- name: Restore go module cache
id: go-mod-cache
if: inputs.use-go-cache == 'true'
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
key: ${{ inputs.cache-key-prefix }}-${{ runner.os }}-go-${{ inputs.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ inputs.cache-key-prefix }}-${{ runner.os }}-go-${{ inputs.go-version }}-
- name: (cache-miss) Bootstrap project tools
shell: bash
if: steps.tool-cache.outputs.cache-hit != 'true'
run: make bootstrap-tools

- name: Restore go build cache
id: go-cache
if: inputs.use-go-cache == 'true'
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
key: ${{ inputs.cache-key-prefix }}-${{ inputs.build-cache-key-prefix }}-${{ runner.os }}-go-${{ inputs.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ inputs.cache-key-prefix }}-${{ inputs.build-cache-key-prefix }}-${{ runner.os }}-go-${{ inputs.go-version }}-
- name: (cache-miss) Bootstrap go dependencies
shell: bash
if: steps.go-mod-cache.outputs.cache-hit != 'true' && inputs.use-go-cache == 'true'
run: make bootstrap-go

- name: Bootstrap CI dependencies
shell: bash
run: make ci-bootstrap

- name: Install apt packages
if: inputs.bootstrap-apt-packages != ''
shell: bash
run: |
DEBIAN_FRONTEND=noninteractive sudo apt update && sudo -E apt install -y ${{ inputs.bootstrap-apt-packages }}
82 changes: 82 additions & 0 deletions .github/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash
set -uo pipefail

SNAPSHOT_DIR=$1

# Based on https://gist.github.com/eduncan911/68775dba9d3c028181e4 and https://gist.github.com/makeworld-the-better-one/e1bb127979ae4195f43aaa3ad46b1097
# but improved to use the `go` command so it never goes out of date.

type setopt >/dev/null 2>&1

contains() {
# Source: https://stackoverflow.com/a/8063398/7361270
[[ $1 =~ (^|[[:space:]])$2($|[[:space:]]) ]]
}

mkdir -p "${SNAPSHOT_DIR}"

BUILD_TARGET=./examples
OUTPUT=${SNAPSHOT_DIR}/stereoscope-example
FAILURES=""

# You can set your own flags on the command line
FLAGS=${FLAGS:-"-ldflags=\"-s -w\""}

# A list of OSes and architectures to not build for, space-separated
# It can be set from the command line when the script is called.
NOT_ALLOWED_OS=${NOT_ALLOWED_OS:-"js android ios solaris illumos aix dragonfly plan9 freebsd openbsd netbsd"}
NOT_ALLOWED_ARCH=${NOT_ALLOWED_ARCH:-"riscv64 mips mips64 mips64le ppc64 ppc64le s390x wasm"}


# Get all targets
while IFS= read -r target; do
GOOS=${target%/*}
GOARCH=${target#*/}
BIN_FILENAME="${OUTPUT}-${GOOS}-${GOARCH}"

if contains "$NOT_ALLOWED_OS" "$GOOS" ; then
continue
fi

if contains "$NOT_ALLOWED_ARCH" "$GOARCH" ; then
continue
fi

# Check for arm and set arm version
if [[ $GOARCH == "arm" ]]; then
# Set what arm versions each platform supports
if [[ $GOOS == "darwin" ]]; then
arms="7"
elif [[ $GOOS == "windows" ]]; then
# This is a guess, it's not clear what Windows supports from the docs
# But I was able to build all these on my machine
arms="5 6 7"
elif [[ $GOOS == *"bsd" ]]; then
arms="6 7"
else
# Linux goes here
arms="5 6 7"
fi

# Now do the arm build
for GOARM in $arms; do
BIN_FILENAME="${OUTPUT}-${GOOS}-${GOARCH}${GOARM}"
if [[ "${GOOS}" == "windows" ]]; then BIN_FILENAME="${BIN_FILENAME}.exe"; fi
CMD="GOARM=${GOARM} GOOS=${GOOS} GOARCH=${GOARCH} go build $FLAGS -o ${BIN_FILENAME} ${BUILD_TARGET}"
echo "${CMD}"
eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}${GOARM}"
done
else
# Build non-arm here
if [[ "${GOOS}" == "windows" ]]; then BIN_FILENAME="${BIN_FILENAME}.exe"; fi
CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build $FLAGS -o ${BIN_FILENAME} ${BUILD_TARGET}"
echo "${CMD}"
eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}"
spiffcs marked this conversation as resolved.
Show resolved Hide resolved
fi
done <<< "$(go tool dist list)"

if [[ "${FAILURES}" != "" ]]; then
echo ""
echo "build failed for: ${FAILURES}"
exit 1
fi
36 changes: 36 additions & 0 deletions .github/scripts/coverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3
import subprocess
import sys
import shlex


class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'


if len(sys.argv) < 3:
print("Usage: coverage.py [threshold] [go-coverage-report]")
sys.exit(1)


threshold = float(sys.argv[1])
report = sys.argv[2]


args = shlex.split(f"go tool cover -func {report}")
p = subprocess.run(args, capture_output=True, text=True)

percent_coverage = float(p.stdout.splitlines()[-1].split()[-1].replace("%", ""))
print(f"{bcolors.BOLD}Coverage: {percent_coverage}%{bcolors.ENDC}")

if percent_coverage < threshold:
print(f"{bcolors.BOLD}{bcolors.FAIL}Coverage below threshold of {threshold}%{bcolors.ENDC}")
sys.exit(1)
30 changes: 30 additions & 0 deletions .github/scripts/go-mod-tidy-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -eu

ORIGINAL_STATE_DIR=$(mktemp -d "TEMP-original-state-XXXXXXXXX")
TIDY_STATE_DIR=$(mktemp -d "TEMP-tidy-state-XXXXXXXXX")

trap "cp -p ${ORIGINAL_STATE_DIR}/* ./ && git update-index -q --refresh && rm -fR ${ORIGINAL_STATE_DIR} ${TIDY_STATE_DIR}" EXIT
wagoodman marked this conversation as resolved.
Show resolved Hide resolved

# capturing original state of files...
cp go.mod go.sum "${ORIGINAL_STATE_DIR}"

# capturing state of go.mod and go.sum after running go mod tidy...
go mod tidy
cp go.mod go.sum "${TIDY_STATE_DIR}"

set +e

# detect difference between the git HEAD state and the go mod tidy state
DIFF_MOD=$(diff -u "${ORIGINAL_STATE_DIR}/go.mod" "${TIDY_STATE_DIR}/go.mod")
DIFF_SUM=$(diff -u "${ORIGINAL_STATE_DIR}/go.sum" "${TIDY_STATE_DIR}/go.sum")

if [[ -n "${DIFF_MOD}" || -n "${DIFF_SUM}" ]]; then
echo "go.mod diff:"
echo "${DIFF_MOD}"
echo "go.sum diff:"
echo "${DIFF_SUM}"
echo ""
printf "FAILED! go.mod and/or go.sum are NOT tidy; please run 'go mod tidy'.\n\n"
exit 1
fi
58 changes: 58 additions & 0 deletions .github/workflows/benchmark-testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: "Benchmark testing"
spiffcs marked this conversation as resolved.
Show resolved Hide resolved

on:
workflow_dispatch:
pull_request:

jobs:

Benchmark-Test:
name: "Benchmark tests"
runs-on: ubuntu-20.04
# note: we want benchmarks to run on pull_request events in order to publish results to a sticky comment, and
# we also want to run on push such that merges to main are recorded to the cache. For this reason we don't filter
# the job by event.
steps:
- uses: actions/checkout@v3

- name: Bootstrap environment
uses: ./.github/actions/bootstrap

- name: Restore base benchmark result
uses: actions/cache@v3
with:
path: test/results/benchmark-main.txt
# use base sha for PR or new commit hash for main push in benchmark result key
key: ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}

- name: Run benchmark tests
id: benchmark
run: |
REF_NAME=${GITHUB_REF##*/} make benchmark
OUTPUT=$(make show-benchstat)
OUTPUT="${OUTPUT//'%'/'%25'}" # URL encode all '%' characters
OUTPUT="${OUTPUT//$'\n'/'%0A'}" # URL encode all '\n' characters
OUTPUT="${OUTPUT//$'\r'/'%0D'}" # URL encode all '\r' characters
echo "::set-output name=result::$OUTPUT"
- uses: actions/upload-artifact@v3
with:
name: benchmark-test-results
path: test/results/**/*

- name: Update PR benchmark results comment
uses: marocchino/sticky-pull-request-comment@v2
continue-on-error: true
with:
header: benchmark
message: |
### Benchmark Test Results
<details>
<summary>Benchmark results from the latest changes vs base branch</summary>
```
${{ steps.benchmark.outputs.result }}
```
</details>
Loading