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

Combine benchmarks rebase new #694

Merged
merged 29 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6d1adaf
Update changelog
pskrbasu Nov 25, 2024
25ca4e2
[dep][dash](deps): Bump @headlessui/react in /ui/dashboard (#607)
dependabot[bot] Dec 4, 2024
325bf2b
Upgrade net and crypto to remediate vulnerabilities (#652)
pskrbasu Jan 6, 2025
6907636
Update version
pskrbasu Jan 9, 2025
73d43fc
Add support for Detections and DetectionBenchmarks
MichaelBurgess Nov 5, 2024
14028d1
Add missing changes from integrated-2024 branch
MichaelBurgess Nov 22, 2024
a554a6f
Add DashboardLeafNodeImpl
kaidaguerre Nov 22, 2024
88bb85d
Add NodeAndEdgeProviderImpl
kaidaguerre Nov 22, 2024
24dd233
started
kaidaguerre Nov 22, 2024
8eefabd
working on it
kaidaguerre Nov 22, 2024
6340fab
workin gon it
kaidaguerre Nov 22, 2024
f13b5ff
working on detection rendering
kaidaguerre Nov 25, 2024
8e0e875
oof working on it
kaidaguerre Nov 25, 2024
1750734
getting there
kaidaguerre Nov 26, 2024
d694178
comments
kaidaguerre Jan 16, 2025
6e9ce1e
compiles
kaidaguerre Jan 22, 2025
550d458
compiles, benchmark list does not crash
kaidaguerre Jan 22, 2025
f9cf7d8
tidy, remove unnecessary changes
kaidaguerre Jan 22, 2025
33b83f6
benchmark list and run works again
kaidaguerre Jan 22, 2025
4b135b5
rename ControlBenchmark back to Benchmark
kaidaguerre Jan 22, 2025
ca3b4ca
tidy
kaidaguerre Jan 22, 2025
85c0a1c
update duckdb version
kaidaguerre Jan 22, 2025
17b997e
wip: display detections
graza-io Jan 27, 2025
723ea2e
wip: detection lines fixed width per display column
graza-io Jan 27, 2025
7bceffd
refactor: detection rendering
graza-io Jan 27, 2025
3c49524
Reverted UI folder to tp branch stat
kaidaguerre Jan 27, 2025
c65d781
revert to tp ui files
kaidaguerre Jan 27, 2025
ce949e9
linting
kaidaguerre Jan 28, 2025
854cacd
tidy
kaidaguerre Jan 28, 2025
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
54 changes: 27 additions & 27 deletions .github/workflows/01-powerpipe-pre-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
path: pipe-fittings
ref: tp

# this is required, check golangci-lint-action docs
# this is required, check golangci-lint-action docs
- uses: actions/setup-go@v5
with:
go-version: '1.23'
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
id: prepare-for-downloads
run: |
mkdir ~/artifacts

- name: Download Linux Build Artifacts
uses: actions/download-artifact@v3
if: ${{ matrix.platform == 'ubuntu-latest' }}
Expand All @@ -155,7 +155,7 @@ jobs:
run: |
mkdir ~/build
tar -xf ~/artifacts/linux.tar.gz -C ~/build

- name: Install Steampipe(Darwin)
if: ${{ matrix.platform == 'macos-latest' }}
run: |
Expand All @@ -167,7 +167,7 @@ jobs:
run: |
sudo /bin/sh -c "$(curl -fsSL https://steampipe.io/install/steampipe.sh)"
steampipe -v

- name: Set PATH
run: |
echo "PATH=$PATH:$HOME/build:$GTIHUB_WORKSPACE/powerpipe/tests/acceptance/lib/bats-core/libexec" >> $GITHUB_ENV
Expand Down Expand Up @@ -220,29 +220,29 @@ jobs:
with:
name: build-artifact-linux
path: ./artifacts

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Pull Ubuntu latest Image
run: docker pull ubuntu:latest

- name: Create and Start Ubuntu latest Container
run: |
docker run -d --name ubuntu-24-test -v ${{ github.workspace }}/artifacts:/artifacts -v ${{ github.workspace }}/scripts:/scripts ubuntu:latest tail -f /dev/null

- name: Get runner/container info
run: |
docker exec ubuntu-24-test /scripts/linux_container_info.sh

- name: Install dependencies, create user, and assign necessary permissions
run: |
docker exec ubuntu-24-test /scripts/prepare_ubuntu_container.sh

- name: Run smoke tests
run: |
docker exec -u steampipe ubuntu-24-test /scripts/smoke_test.sh

- name: Stop and Remove Container
run: |
docker stop ubuntu-24-test
Expand All @@ -255,35 +255,35 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download Linux Build Artifact
uses: actions/download-artifact@v3
with:
name: build-artifact-linux
path: ./artifacts

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Pull CentOS Stream 9 image
run: docker pull quay.io/centos/centos:stream9

- name: Create and Start CentOS stream9 Container
run: |
docker run -d --name centos-stream9-test -v ${{ github.workspace }}/artifacts:/artifacts -v ${{ github.workspace }}/scripts:/scripts quay.io/centos/centos:stream9 tail -f /dev/null

- name: Get runner/container info
run: |
docker exec centos-stream9-test /scripts/linux_container_info.sh

- name: Install dependencies, create user, and assign necessary permissions
run: |
docker exec centos-stream9-test /scripts/prepare_centos_container.sh

- name: Run smoke tests
run: |
docker exec -u steampipe centos-stream9-test /scripts/smoke_test.sh

- name: Stop and Remove Container
run: |
docker stop centos-stream9-test
Expand All @@ -302,29 +302,29 @@ jobs:
with:
name: build-artifact-linux
path: ./artifacts

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Pull Amazon Linux 2023 Image
run: docker pull amazonlinux:2023

- name: Create and Start Amazon Linux 2023 Container
run: |
docker run -d --name amazonlinux-2023-test -v ${{ github.workspace }}/artifacts:/artifacts -v ${{ github.workspace }}/scripts:/scripts amazonlinux:2023 tail -f /dev/null

- name: Get runner/container info
run: |
docker exec amazonlinux-2023-test /scripts/linux_container_info.sh

- name: Install dependencies, create user, and assign necessary permissions
run: |
docker exec amazonlinux-2023-test /scripts/prepare_amazonlinux_container.sh

- name: Run smoke tests
run: |
docker exec -u steampipe amazonlinux-2023-test /scripts/smoke_test.sh

- name: Stop and Remove Container
run: |
docker stop amazonlinux-2023-test
Expand All @@ -343,23 +343,23 @@ jobs:
# with:
# name: build-artifact-linux-arm
# path: ./artifacts

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3

# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3
# with:
# platforms: arm64

# - name: Create Buildx Builder
# run: |
# docker buildx create --use --name mybuilder
# docker buildx inspect --bootstrap

# - name: Pull Ubuntu 24 ARM64 Image
# run: docker pull arm64v8/ubuntu:latest

# - name: Create and Start Ubuntu 24 ARM64 Container
# run: |
# docker run -d --name ubuntu-24-arm64-test -v ${{ github.workspace }}/artifacts:/artifacts -v ${{ github.workspace }}/scripts:/scripts arm64v8/ubuntu:latest tail -f /dev/null
Expand All @@ -375,7 +375,7 @@ jobs:
# - name: Run smoke tests
# run: |
# docker exec -u steampipe ubuntu-24-arm64-test /scripts/smoke_test.sh

# - name: Stop and Remove Container
# run: |
# docker stop ubuntu-24-arm64-test
Expand Down
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
## v1.0.1 [2024-11-21]
_Whats new_
- Update uploaded Pipes snapshot URL to include `/powerpipe`. ([#577](https://github.com/turbot/powerpipe/issues/577))

_Bug fixes_
- Fix minor spelling issue in query help output. ([#542](https://github.com/turbot/powerpipe/issues/542))
- Update error message to inform users to run `make dashboard_assets` when dashboard assets are not present. ([#524](https://github.com/turbot/powerpipe/issues/524))
Expand Down
22 changes: 16 additions & 6 deletions internal/cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/turbot/powerpipe/internal/controlexecute"
"github.com/turbot/powerpipe/internal/controlinit"
"github.com/turbot/powerpipe/internal/controlstatus"
"github.com/turbot/powerpipe/internal/dashboardexecute"
"github.com/turbot/powerpipe/internal/display"
localqueryresult "github.com/turbot/powerpipe/internal/queryresult"
"github.com/turbot/powerpipe/internal/resources"
Expand Down Expand Up @@ -158,7 +159,7 @@ func runCheckCmd[T controlinit.CheckTarget](cmd *cobra.Command, args []string) {
initCtx := statushooks.DisableStatusHooks(ctx)

// initialise
initData := controlinit.NewInitData[T](initCtx, cmd, args)
initData := controlinit.NewInitData[T](initCtx, cmd, args...)
if initData.Result.Error != nil {
exitCode = constants.ExitCodeInitializationFailed
error_helpers.ShowError(ctx, initData.Result.Error)
Expand All @@ -173,7 +174,7 @@ func runCheckCmd[T controlinit.CheckTarget](cmd *cobra.Command, args []string) {
if !viper.IsSet(constants.ArgOutput) {
viper.Set(constants.ArgOutput, constants.OutputFormatSnapshot)
}
detectionRunWithInitData[*resources.DetectionBenchmark](cmd, initData.BaseInitData(), args)
detectionRunWithInitData[*resources.DetectionBenchmark](cmd, initData, args)
return
}

Expand All @@ -185,7 +186,7 @@ func runCheckCmd[T controlinit.CheckTarget](cmd *cobra.Command, args []string) {

// now filter the target
// get the execution trees
trees, err := getExecutionTrees[T](ctx, initData)
trees, err := getExecutionTrees(ctx, initData)
error_helpers.FailOnError(err)

// pull out useful properties
Expand Down Expand Up @@ -229,7 +230,7 @@ func runCheckCmd[T controlinit.CheckTarget](cmd *cobra.Command, args []string) {
}

// exportExecutionTree relies on the fact that the given tree is already executed
func exportExecutionTree[T controlinit.CheckTarget](ctx context.Context, namedTree *namedExecutionTree, initData *controlinit.InitData[T], exportArgs []string) error {
func exportExecutionTree(ctx context.Context, namedTree *namedExecutionTree, initData *controlinit.InitData, exportArgs []string) error {
statushooks.Show(ctx)
defer statushooks.Done(ctx)

Expand All @@ -251,7 +252,7 @@ func exportExecutionTree[T controlinit.CheckTarget](ctx context.Context, namedTr
}

// executeTree executes and displays the (table) results of an execution
func executeTree[T controlinit.CheckTarget](ctx context.Context, tree *controlexecute.ExecutionTree, initData *controlinit.InitData[T]) error {
func executeTree(ctx context.Context, tree *controlexecute.ExecutionTree, initData *controlinit.InitData) error {
// create a context with check status hooks
checkCtx, cancel := createCheckContext(ctx)
defer cancel()
Expand Down Expand Up @@ -290,7 +291,7 @@ func publishSnapshot(ctx context.Context, executionTree *controlexecute.Executio
return nil
}

func getExecutionTrees[T controlinit.CheckTarget](ctx context.Context, initData *controlinit.InitData[T]) ([]*namedExecutionTree, error) {
func getExecutionTrees(ctx context.Context, initData *controlinit.InitData) ([]*namedExecutionTree, error) {
var trees []*namedExecutionTree
if error_helpers.IsContextCanceled(ctx) {
return nil, ctx.Err()
Expand Down Expand Up @@ -394,6 +395,15 @@ func displayControlResults(ctx context.Context, executionTree *controlexecute.Ex
return err
}

func displayDetectionResults(ctx context.Context, executionTree *dashboardexecute.DetectionBenchmarkDisplayTree, formatter controldisplay.Formatter) error {
reader, err := formatter.FormatDetection(ctx, executionTree)
if err != nil {
return err
}
_, err = io.Copy(os.Stdout, reader)
return err
}

type namedExecutionTree struct {
tree *controlexecute.ExecutionTree
name string
Expand Down
38 changes: 24 additions & 14 deletions internal/cmd/detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"errors"
"fmt"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/powerpipe/internal/dashboardexecute"
"os"
"strings"

Expand All @@ -17,11 +15,14 @@ import (
"github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/error_helpers"
"github.com/turbot/pipe-fittings/export"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/pipe-fittings/statushooks"
"github.com/turbot/pipe-fittings/workspace"
localcmdconfig "github.com/turbot/powerpipe/internal/cmdconfig"
localconstants "github.com/turbot/powerpipe/internal/constants"
"github.com/turbot/powerpipe/internal/initialisation"
"github.com/turbot/powerpipe/internal/controldisplay"
"github.com/turbot/powerpipe/internal/controlinit"
"github.com/turbot/powerpipe/internal/dashboardexecute"
"github.com/turbot/powerpipe/internal/resources"
"github.com/turbot/steampipe-plugin-sdk/v5/logging"
)
Expand All @@ -32,7 +33,7 @@ type DetectionTarget interface {
}

// variable used to assign the output mode flag
var detectionOutputMode = localconstants.DetectionOutputModeSnapshotShort
var detectionOutputMode = localconstants.CheckOutputModeText

func detectionRunCmd[T DetectionTarget]() *cobra.Command {
typeName := resources.GenericTypeToBlockType[T]()
Expand Down Expand Up @@ -63,9 +64,9 @@ func detectionRunCmd[T DetectionTarget]() *cobra.Command {
AddVarFlag(enumflag.New(&updateStrategy, constants.ArgPull, constants.ModUpdateStrategyIds, enumflag.EnumCaseInsensitive),
constants.ArgPull,
fmt.Sprintf("Update strategy; one of: %s", strings.Join(constants.FlagValues(constants.ModUpdateStrategyIds), ", "))).
AddVarFlag(enumflag.New(&detectionOutputMode, constants.ArgOutput, localconstants.DetectionOutputModeIds, enumflag.EnumCaseInsensitive),
AddVarFlag(enumflag.New(&detectionOutputMode, constants.ArgOutput, localconstants.CheckOutputModeIds, enumflag.EnumCaseInsensitive),
constants.ArgOutput,
fmt.Sprintf("Output format; one of: %s", strings.Join(constants.FlagValues(localconstants.DetectionOutputModeIds), ", "))).
fmt.Sprintf("Output format; one of: %s", strings.Join(constants.FlagValues(localconstants.CheckOutputModeIds), ", "))).
AddBoolFlag(constants.ArgProgress, true, "Display detection execution progress respected when a detection name argument is passed").
AddBoolFlag(constants.ArgSnapshot, false, "Create snapshot in Turbot Pipes with the default (workspace) visibility").
AddBoolFlag(constants.ArgShare, false, "Create snapshot in Turbot Pipes with 'anyone_with_link' visibility").
Expand All @@ -89,8 +90,7 @@ func detectionRun[T DetectionTarget](cmd *cobra.Command, args []string) {

// tactical - to support callint benchmark run and calling either control or dashboard execution flow,
// we must support calling this from the check command, AFTER the initdata has been fetched
func detectionRunWithInitData[T DetectionTarget](cmd *cobra.Command, initData *initialisation.InitData, args []string) {

func detectionRunWithInitData[T DetectionTarget](cmd *cobra.Command, initData *controlinit.InitData, args []string) {
ctx := cmd.Context()

// there can only be a single arg - cobra will validate
Expand Down Expand Up @@ -121,8 +121,15 @@ func detectionRunWithInitData[T DetectionTarget](cmd *cobra.Command, initData *i

statushooks.SetStatus(ctx, "Initializing…")
if initData == nil {
initData = initialisation.NewInitData[T](ctx, cmd, detectionName)
initData = controlinit.NewInitData[T](ctx, cmd, detectionName)
}

if initData.Result.Error != nil {
exitCode = constants.ExitCodeInitializationFailed
error_helpers.ShowError(ctx, initData.Result.Error)
return
}
defer initData.Cleanup(ctx)

if len(viper.GetStringSlice(constants.ArgExport)) > 0 {
err := initData.RegisterExporters(detectionExporters()...)
Expand All @@ -135,10 +142,6 @@ func detectionRunWithInitData[T DetectionTarget](cmd *cobra.Command, initData *i

statushooks.Done(ctx)

// shutdown the service on exit
defer initData.Cleanup(ctx)
error_helpers.FailOnError(initData.Result.Error)

// if there is a usage warning we display it
initData.Result.DisplayMessages()

Expand All @@ -150,8 +153,15 @@ func detectionRunWithInitData[T DetectionTarget](cmd *cobra.Command, initData *i

snap, err := dashboardexecute.GenerateSnapshot(ctx, initData.Workspace, target, inputs)
error_helpers.FailOnError(err)

tree, err := controldisplay.SnapshotToExecutionTree(ctx, snap, initData.Workspace, target)
error_helpers.FailOnError(err)

err = displayDetectionResults(ctx, tree, initData.OutputFormatter)
error_helpers.FailOnError(err)

// display the snapshot result (if needed)
displaySnapshot(snap)
//displaySnapshot(snap)

// upload the snapshot (if needed)
err = publishSnapshotIfNeeded(ctx, snap)
Expand Down
4 changes: 2 additions & 2 deletions internal/cmdconfig/cmd_targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func ResolveTargets[T modconfig.ModTreeItem](cmdArgs []string, w *pworkspace.Pow
// in this case, convert into a query and add to workspace (to allow for simple snapshot generation)
//
// TODO K add unit test
// TODO once we remove DetectionBenvhmarks this should return []T
// TODO once we remove DetectionBechmarks this should return []T
// https://github.com/turbot/powerpipe/issues/609
func resolveSingleTarget[T modconfig.ModTreeItem](cmdArg string, w *pworkspace.PowerpipeWorkspace) ([]modconfig.ModTreeItem, error) {
typeName := resources.GenericTypeToBlockType[T]()
Expand All @@ -59,7 +59,7 @@ func resolveSingleTarget[T modconfig.ModTreeItem](cmdArg string, w *pworkspace.P
if helpers.IsNil(target) {
return nil, fmt.Errorf("'%s.%s' not found in %s (%s)", typeName, cmdArg, w.Mod.Name(), w.Path)
}
// TODO KAI CHECK QUERY ARGS LOGIC HERE
// TODO K CHECK QUERY ARGS LOGIC HERE
//if queryArgs != nil {
// return nil, sperr.New("benchmarks do not support query args")
//}
Expand Down
Loading
Loading