Skip to content

Commit

Permalink
WIP feat: get endpoint (#2789)
Browse files Browse the repository at this point in the history
* chore(docs): Adding App Insights Configuration Page (#2820)

* chore(docs): Adding App Insights Configuration Page

* fixing typo

* fix(frontend): Fixing Resizable Panels UI bugs (#2827)

* fix(tests): add analyzer resource to cli e2e table (#2826)

* chore(docs): Azure App Insights Recipes (#2821)

* chore(docs): Adding App Insights Configuration Page

* chore(docs): Adding App Insights Recipes

* chore(docs): Adding App Insights Recipes

* chore(docs): fixing typo

* adding recipe links

* adding recipe links

* fixing typo

* chore(frotend): Test Definition Name Input (#2830)

* chore(frotend): Updating Panel Splitter w/ Tooltip (#2828)

* chore(frotend): Updating Panel Splitter w/ Tooltip

* Updating theme color

* removing unnecessary flag

* undo change

* fix(frontend): fix missing font-face (#2833)

* feat(cli): refactor list formatter for better resource manager support (#2829)

* feat(frontend): add independent trace vs test data (#2815)

* feat(cli): refactor Get formatter for better resource manager support (#2831)

* feat(cli): dynamic list of available resources (#2832)

* feat(cli): refactor Delete to new resource manager client (#2836)

* feat(cli): update export command with new resourcemanager client (#2838)

* Standardize old resources to to use list method with SQL Injection protection and stardardize PollingProfile file (#2839)

* wip: update list on demo and environment to use the same standards as tests and transactions

* Fixing provisioning test

* Update provisioning test

* feature(frontend): Contact Us Modal (#2835)

* feature(frontend): Contact Us Modal

* feature(frontend): Contact Us Modal

* feat(cli): update apply command with new resourcemanager client (#2841)

* feat(frontend): trace vs test data for timeline and attribute list (#2837)

* feat: new tests openapi spec (#2658)

update get tests endpoint to use resource manager

* fix: move transactions to it's own module (#2664)

* fix: move transactions to the transactions folder

* remove alias to transactions module

* feat: test models + list tests endpoint (#2681)

* add test, run, and trigger objects

* feat: move test and run structs into the test package

* list tests

* add old format attributes again

* fix mapping

* compatibility mode

* fix server prefix integration test

* force server unit tests to run

* fix tracetest test

* trigger CI

* Apply suggestions from code review

Co-authored-by: Sebastian Choren <schoren@users.noreply.github.com>

* fix build

* version test specs

* update test names

* use sqlutils

* dont specify branch target in pull_request

* fix list test

---------

Co-authored-by: Sebastian Choren <schoren@users.noreply.github.com>

* 2659 cli improvements migrate tests to resource manager architecture get tests frontend (#2702)

chore(frontend): updating FE to support GET /tests endpoint changes

* feat: test list augmented response (#2732)

add augmented list

* fix(server): fix trigger json encoding versioning and test (#2795)

* feat: test models + list tests endpoint (#2681)

* add test, run, and trigger objects

* feat: move test and run structs into the test package

* list tests

* add old format attributes again

* fix mapping

* compatibility mode

* fix server prefix integration test

* force server unit tests to run

* fix tracetest test

* trigger CI

* Apply suggestions from code review

Co-authored-by: Sebastian Choren <schoren@users.noreply.github.com>

* fix build

* version test specs

* update test names

* use sqlutils

* dont specify branch target in pull_request

* fix list test

---------

Co-authored-by: Sebastian Choren <schoren@users.noreply.github.com>

* GET endpoint

* fix rebase

* add create method and fix tests

* add rest of methods

* Changing test structure and fixing method by method

* Update tests

* Fixing test errors for Delete

* Adding gRPC tests

* Adding tests for traceid trigger

* migrate rest of endpoints and fix compilation errors

* fix all unit and integration tests

* Improving tests

* fix building errors

---------

Co-authored-by: Oscar Reyes <oscar-rreyes1@hotmail.com>
Co-authored-by: Jorge Padilla <jorge.esteban.padilla@gmail.com>
Co-authored-by: Sebastian Choren <schoren@users.noreply.github.com>
Co-authored-by: Daniel Baptista Dias <danielbdias@users.noreply.github.com>
Co-authored-by: Daniel Dias <danielbpdias@gmail.com>
  • Loading branch information
6 people committed Jul 3, 2023
1 parent 40af921 commit 730578a
Show file tree
Hide file tree
Showing 339 changed files with 8,000 additions and 6,864 deletions.
5 changes: 2 additions & 3 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -352,19 +352,18 @@ paths:
/tests/{testId}:
get:
tags:
- api
- resource-api
parameters:
- $ref: "./parameters.yaml#/components/parameters/testId"
summary: "get test"
description: "get test"
operationId: getTest
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: "./tests.yaml#/components/schemas/Test"
$ref: "./tests.yaml#/components/schemas/TestResource"
500:
description: "problem with getting a test"
put:
Expand Down
15 changes: 8 additions & 7 deletions cli/actions/export_test_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ func (a exportTestAction) getDefinitionFromServer(ctx context.Context, args Expo
}

func (a exportTestAction) getTestFromServer(ctx context.Context, testID string) (openapi.Test, error) {
req := a.client.ApiApi.GetTest(ctx, testID)
openapiTest, _, err := a.client.ApiApi.GetTestExecute(req)
if err != nil {
return openapi.Test{}, fmt.Errorf("could not execute getTest request: %w", err)
}

return *openapiTest, nil
// req := a.client.ApiApi.GetTest(ctx, testID)
// openapiTest, _, err := a.client.ApiApi.GetTestExecute(req)
// if err != nil {
// return openapi.Test{}, fmt.Errorf("could not execute getTest request: %w", err)
// }

// return *openapiTest, nil
return openapi.Test{}, nil
}
45 changes: 22 additions & 23 deletions cli/actions/list_tests_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package actions

import (
"context"
"fmt"

"github.com/kubeshop/tracetest/cli/config"
"github.com/kubeshop/tracetest/cli/formatters"
"github.com/kubeshop/tracetest/cli/openapi"
"go.uber.org/zap"
)
Expand All @@ -25,32 +23,33 @@ func NewListTestsAction(config config.Config, logger *zap.Logger, client *openap
}

func (a listTestsAction) Run(ctx context.Context, args ListTestConfig) error {
tests, err := a.executeRequest(ctx)
if err != nil {
return err
}
// tests, err := a.executeRequest(ctx)
// if err != nil {
// return err
// }

formatter := formatters.TestsList(a.config)
formattedOutput := formatter.Format(tests)
fmt.Println(formattedOutput)
// formatter := formatters.TestsList(a.config)
// formattedOutput := formatter.Format(tests)
// fmt.Println(formattedOutput)

// return nil
return nil
}

func (a listTestsAction) executeRequest(ctx context.Context) ([]openapi.Test, error) {
request := a.client.ApiApi.GetTests(ctx)
tests, response, err := a.client.ApiApi.GetTestsExecute(request)
if err != nil {
return []openapi.Test{}, fmt.Errorf("could not get tests: %w", err)
}
// func (a listTestsAction) executeRequest(ctx context.Context) ([]openapi.Test, error) {
// request := a.client.ApiApi.GetTests(ctx)
// tests, response, err := a.client.ApiApi.GetTestsExecute(request)
// if err != nil {
// return []openapi.Test{}, fmt.Errorf("could not get tests: %w", err)
// }

if response.StatusCode != 200 {
return []openapi.Test{}, fmt.Errorf("get tests request failed. Expected 200, got %d", response.StatusCode)
}
// if response.StatusCode != 200 {
// return []openapi.Test{}, fmt.Errorf("get tests request failed. Expected 200, got %d", response.StatusCode)
// }

if tests == nil {
return []openapi.Test{}, nil
}
// if tests == nil {
// return []openapi.Test{}, nil
// }

return tests, nil
}
// return tests, nil
// }
17 changes: 9 additions & 8 deletions cli/actions/run_test_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,15 @@ func (a runTestAction) getTransaction(ctx context.Context, id string) (openapi.T
}

func (a runTestAction) getTest(ctx context.Context, id string) (openapi.Test, error) {
test, _, err := a.client.ApiApi.
GetTest(ctx, id).
Execute()
if err != nil {
return openapi.Test{}, fmt.Errorf("could not execute request: %w", err)
}

return *test, nil
// test, _, err := a.client.ApiApi.
// GetTest(ctx, id).
// Execute()
// if err != nil {
// return openapi.Test{}, fmt.Errorf("could not execute request: %w", err)
// }

// return *test, nil
return openapi.Test{}, nil
}

func (a runTestAction) testRun(ctx context.Context, test openapi.Test, runID int32, params runDefParams) error {
Expand Down
25 changes: 7 additions & 18 deletions cli/cmd/apply_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,35 @@ package cmd

import (
"context"
"fmt"
"strings"

"github.com/kubeshop/tracetest/cli/actions"
"github.com/kubeshop/tracetest/cli/formatters"
"github.com/kubeshop/tracetest/cli/parameters"
"github.com/kubeshop/tracetest/cli/pkg/resourcemanager"
"github.com/spf13/cobra"
)

var applyParams = &parameters.ApplyParams{}

var applyCmd = &cobra.Command{
GroupID: cmdGroupResources.ID,
Use: fmt.Sprintf("apply %s", strings.Join(parameters.ValidResources, "|")),
Use: "apply " + resourceList(),
Short: "Apply resources",
Long: "Apply (create/update) resources to your Tracetest server",
PreRun: setupCommand(),
Run: WithResourceMiddleware(func(_ *cobra.Command, args []string) (string, error) {
resourceType := args[0]
resourceType := resourceParams.ResourceName
ctx := context.Background()

resourceActions, err := resourceRegistry.Get(resourceType)

resourceClient, err := resources.Get(resourceType)
if err != nil {
return "", err
}

applyArgs := actions.ApplyArgs{
File: applyParams.DefinitionFile,
}

resource, _, err := resourceActions.Apply(ctx, applyArgs)
resultFormat, err := resourcemanager.Formats.GetWithFallback(output, "yaml")
if err != nil {
return "", err
}

resourceFormatter := resourceActions.Formatter()
formatter := formatters.BuildFormatter(output, formatters.YAML, resourceFormatter)

result, err := formatter.Format(resource)
result, err := resourceClient.Apply(ctx, applyParams.DefinitionFile, resultFormat)
if err != nil {
return "", err
}
Expand All @@ -52,6 +41,6 @@ var applyCmd = &cobra.Command{
}

func init() {
applyCmd.Flags().StringVarP(&applyParams.DefinitionFile, "file", "f", "", "file path with name where to export the resource")
applyCmd.Flags().StringVarP(&applyParams.DefinitionFile, "file", "f", "", "path to the definition file")
rootCmd.AddCommand(applyCmd)
}
156 changes: 153 additions & 3 deletions cli/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ package cmd
import (
"context"
"fmt"
"net/http"
"os"
"strings"
"time"

"github.com/Jeffail/gabs/v2"
"github.com/kubeshop/tracetest/cli/actions"
"github.com/kubeshop/tracetest/cli/analytics"
"github.com/kubeshop/tracetest/cli/config"
"github.com/kubeshop/tracetest/cli/formatters"
"github.com/kubeshop/tracetest/cli/parameters"
"github.com/kubeshop/tracetest/cli/pkg/resourcemanager"
"github.com/kubeshop/tracetest/cli/utils"
"github.com/spf13/cobra"
"go.uber.org/zap"
Expand Down Expand Up @@ -44,6 +49,140 @@ func SkipVersionMismatchCheck() setupOption {
}
}

var httpClient = &resourcemanager.HTTPClient{}
var resources = resourcemanager.NewRegistry().
Register(
resourcemanager.NewClient(
httpClient,
"config", "configs",
resourcemanager.WithTableConfig(resourcemanager.TableConfig{
Cells: []resourcemanager.TableCellConfig{
{Header: "ID", Path: "spec.id"},
{Header: "NAME", Path: "spec.name"},
{Header: "ANALYTICS ENABLED", Path: "spec.analyticsEnabled"},
},
}),
),
).
Register(
resourcemanager.NewClient(
httpClient,
"analyzer", "analyzers",
resourcemanager.WithTableConfig(resourcemanager.TableConfig{
Cells: []resourcemanager.TableCellConfig{
{Header: "ID", Path: "spec.id"},
{Header: "NAME", Path: "spec.name"},
{Header: "ENABLED", Path: "spec.enabled"},
{Header: "MINIMUM SCORE", Path: "spec.minimumScore"},
},
}),
),
).
Register(
resourcemanager.NewClient(
httpClient,
"pollingprofile", "pollingprofiles",
resourcemanager.WithTableConfig(resourcemanager.TableConfig{
Cells: []resourcemanager.TableCellConfig{
{Header: "ID", Path: "spec.id"},
{Header: "NAME", Path: "spec.name"},
{Header: "STRATEGY", Path: "spec.strategy"},
},
}),
),
).
Register(
resourcemanager.NewClient(
httpClient,
"demo", "demos",
resourcemanager.WithTableConfig(resourcemanager.TableConfig{
Cells: []resourcemanager.TableCellConfig{
{Header: "ID", Path: "spec.id"},
{Header: "NAME", Path: "spec.name"},
{Header: "TYPE", Path: "spec.type"},
{Header: "ENABLED", Path: "spec.enabled"},
},
}),
),
).
Register(
resourcemanager.NewClient(
httpClient,
"datastore", "datastores",
resourcemanager.WithTableConfig(resourcemanager.TableConfig{
Cells: []resourcemanager.TableCellConfig{
{Header: "ID", Path: "spec.id"},
{Header: "NAME", Path: "spec.name"},
{Header: "DEFAULT", Path: "spec.default"},
},
ItemModifier: func(item *gabs.Container) error {
isDefault := item.Path("spec.default").Data().(bool)
if !isDefault {
item.SetP("", "spec.default")
} else {
item.SetP("*", "spec.default")
}
return nil
},
}),
resourcemanager.WithDeleteEnabled("DataStore removed. Defaulting back to no-tracing mode"),
),
).
Register(
resourcemanager.NewClient(
httpClient,
"environment", "environments",
resourcemanager.WithTableConfig(resourcemanager.TableConfig{
Cells: []resourcemanager.TableCellConfig{
{Header: "ID", Path: "spec.id"},
{Header: "NAME", Path: "spec.name"},
{Header: "DESCRIPTION", Path: "spec.description"},
},
}),
),
).
Register(
resourcemanager.NewClient(
httpClient,
"transaction", "transactions",
resourcemanager.WithTableConfig(resourcemanager.TableConfig{
Cells: []resourcemanager.TableCellConfig{
{Header: "ID", Path: "spec.id"},
{Header: "NAME", Path: "spec.name"},
{Header: "VERSION", Path: "spec.version"},
{Header: "STEPS", Path: "spec.summary.steps"},
{Header: "RUNS", Path: "spec.summary.runs"},
{Header: "LAST RUN TIME", Path: "spec.summary.lastRun.time"},
{Header: "LAST RUN SUCCESSES", Path: "spec.summary.lastRun.passes"},
{Header: "LAST RUN FAILURES", Path: "spec.summary.lastRun.fails"},
},
ItemModifier: func(item *gabs.Container) error {
// set spec.summary.steps to the number of steps in the transaction
item.SetP(len(item.Path("spec.steps").Children()), "spec.summary.steps")

// if lastRun.time is not empty, show it in a nicer format
lastRunTime := item.Path("spec.summary.lastRun.time").Data().(string)
if lastRunTime != "" {
date, err := time.Parse(time.RFC3339, lastRunTime)
if err != nil {
return fmt.Errorf("failed to parse last run time: %s", err)
}
if date.IsZero() {
item.SetP("", "spec.summary.lastRun.time")
} else {
item.SetP(date.Format(time.DateTime), "spec.summary.lastRun.time")
}
}
return nil
},
}),
),
)

func resourceList() string {
return strings.Join(resources.List(), "|")
}

func setupCommand(options ...setupOption) func(cmd *cobra.Command, args []string) {
config := setupConfig{
shouldValidateConfig: true,
Expand All @@ -60,10 +199,20 @@ func setupCommand(options ...setupOption) func(cmd *cobra.Command, args []string
overrideConfig()
setupVersion()

baseOptions := []actions.ResourceArgsOption{actions.WithLogger(cliLogger), actions.WithConfig(cliConfig)}
extraHeaders := http.Header{}
extraHeaders.Set("x-client-id", analytics.ClientID())
extraHeaders.Set("x-source", "cli")

// TODO: remove this client from here when we migrate tests to the resource manager
openapiClient := utils.GetAPIClient(cliConfig)
// To avoid a ciruclar reference initialization when setting up the registry and its resources,
// we create the resources with a pointer to an unconfigured HTTPClient.
// When each command is run, this function is run in the PreRun stage, before any of the actual `Run` code is executed
// We take this chance to configure the HTTPClient with the correct URL and headers.
// To make this configuration propagate to all the resources, we need to replace the pointer to the HTTPClient.
// For more details, see https://github.com/kubeshop/tracetest/pull/2832#discussion_r1245616804
hc := resourcemanager.NewHTTPClient(cliConfig.URL(), extraHeaders)
*httpClient = *hc

baseOptions := []actions.ResourceArgsOption{actions.WithLogger(cliLogger), actions.WithConfig(cliConfig)}

configOptions := append(
baseOptions,
Expand Down Expand Up @@ -113,6 +262,7 @@ func setupCommand(options ...setupOption) func(cmd *cobra.Command, args []string
environmentActions := actions.NewEnvironmentsActions(environmentOptions...)
resourceRegistry.Register(environmentActions)

openapiClient := utils.GetAPIClient(cliConfig)
transactionOptions := append(
baseOptions,
actions.WithClient(utils.GetResourceAPIClient("transactions", cliConfig)),
Expand Down
Loading

0 comments on commit 730578a

Please sign in to comment.