Skip to content

Commit

Permalink
Move scripts utils out of the cli package
Browse files Browse the repository at this point in the history
Summary:
The CLI script bundle manager is used outside of the CLI code, so lets
move it to a top level utils.

Test Plan: Everything still builds and tests all pass.

Reviewers: zasgar

Reviewed By: zasgar

Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>

Differential Revision: https://phab.corp.pixielabs.ai/D12326

GitOrigin-RevId: 9afedda98a4566296806f16fb07afd514edb7b5e
  • Loading branch information
vihangm authored and copybaranaut committed Oct 3, 2022
1 parent 501df04 commit d9f55b6
Show file tree
Hide file tree
Showing 34 changed files with 41 additions and 47 deletions.
6 changes: 3 additions & 3 deletions .fossa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,10 @@ analyze:
type: go
target: px.dev/pixie/src/pixie_cli/pkg/pxconfig
path: src/pixie_cli/pkg/pxconfig
- name: px.dev/pixie/src/pixie_cli/pkg/script
- name: px.dev/pixie/src/utils/script
type: go
target: px.dev/pixie/src/pixie_cli/pkg/script
path: src/pixie_cli/pkg/script
target: px.dev/pixie/src/utils/script
path: src/utils/script
- name: px.dev/pixie/src/pixie_cli/pkg/sentryhook
type: go
target: px.dev/pixie/src/pixie_cli/pkg/sentryhook
Expand Down
2 changes: 1 addition & 1 deletion src/carnot/goplanner/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ go_test(
"//src/carnot/planpb:plan_pl_go_proto",
"//src/carnot/udfspb:udfs_pl_go_proto",
"//src/common/base/statuspb:status_pl_go_proto",
"//src/pixie_cli/pkg/script",
"//src/pixie_cli/pkg/vizier",
"//src/shared/scriptspb:scripts_pl_go_proto",
"//src/table_store/schemapb:schema_pl_go_proto",
"//src/utils",
"//src/utils/script",
"//src/vizier/funcs/go",
"//src/vizier/services/query_broker/controllers",
"@com_github_gofrs_uuid//:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion src/carnot/goplanner/logical_planner_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import (
"px.dev/pixie/src/carnot/planner/plannerpb"
"px.dev/pixie/src/carnot/udfspb"
"px.dev/pixie/src/common/base/statuspb"
"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/pixie_cli/pkg/vizier"
"px.dev/pixie/src/table_store/schemapb"
"px.dev/pixie/src/utils"
"px.dev/pixie/src/utils/script"
funcs "px.dev/pixie/src/vizier/funcs/go"
"px.dev/pixie/src/vizier/services/query_broker/controllers"
)
Expand Down
2 changes: 1 addition & 1 deletion src/carnot/plandebugger/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ go_library(
"//src/carnot/queryresultspb:query_results_pl_go_proto",
"//src/carnot/udfspb:udfs_pl_go_proto",
"//src/common/base/statuspb:status_pl_go_proto",
"//src/pixie_cli/pkg/script",
"//src/pixie_cli/pkg/vizier",
"//src/utils",
"//src/utils/script",
"//src/vizier/funcs/go",
"//src/vizier/services/query_broker/controllers",
"@com_github_gofrs_uuid//:uuid",
Expand Down
2 changes: 1 addition & 1 deletion src/carnot/plandebugger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import (
"px.dev/pixie/src/carnot/queryresultspb"
"px.dev/pixie/src/carnot/udfspb"
"px.dev/pixie/src/common/base/statuspb"
"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/pixie_cli/pkg/vizier"
"px.dev/pixie/src/utils"
"px.dev/pixie/src/utils/script"
funcs "px.dev/pixie/src/vizier/funcs/go"
"px.dev/pixie/src/vizier/services/query_broker/controllers"
)
Expand Down
2 changes: 1 addition & 1 deletion src/cloud/api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ go_library(
"//src/cloud/shared/esutils",
"//src/cloud/shared/idprovider",
"//src/cloud/shared/vzshard",
"//src/pixie_cli/pkg/script",
"//src/shared/services",
"//src/shared/services/env",
"//src/shared/services/handler",
"//src/shared/services/healthz",
"//src/shared/services/msgbus",
"//src/shared/services/server",
"//src/utils/script",
"@com_github_gorilla_handlers//:handlers",
"@com_github_sirupsen_logrus//:logrus",
"@com_github_spf13_pflag//:pflag",
Expand Down
2 changes: 1 addition & 1 deletion src/cloud/api/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ import (
"px.dev/pixie/src/cloud/shared/esutils"
"px.dev/pixie/src/cloud/shared/idprovider"
"px.dev/pixie/src/cloud/shared/vzshard"
"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/shared/services"
svcEnv "px.dev/pixie/src/shared/services/env"
"px.dev/pixie/src/shared/services/handler"
"px.dev/pixie/src/shared/services/healthz"
"px.dev/pixie/src/shared/services/msgbus"
"px.dev/pixie/src/shared/services/server"
"px.dev/pixie/src/utils/script"
)

const defaultBundleFile = "https://storage.googleapis.com/pixie-prod-artifacts/script-bundles/bundle-core.json"
Expand Down
2 changes: 1 addition & 1 deletion src/cloud/autocomplete/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ go_library(
"//src/cloud/autocomplete/ebnf",
"//src/cloud/indexer/md",
"//src/cloud/profile/profilepb:service_pl_go_proto",
"//src/pixie_cli/pkg/script",
"//src/utils/script",
"@com_github_gofrs_uuid//:uuid",
"@com_github_olivere_elastic_v7//:elastic",
"@com_github_sahilm_fuzzy//:fuzzy",
Expand Down
2 changes: 1 addition & 1 deletion src/cloud/autocomplete/suggester.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"px.dev/pixie/src/api/proto/vispb"
"px.dev/pixie/src/cloud/indexer/md"
"px.dev/pixie/src/cloud/profile/profilepb"
"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/utils/script"
)

// ElasticSuggester provides suggestions based on the given index in Elastic.
Expand Down
2 changes: 1 addition & 1 deletion src/e2e_test/vizier/exectime/cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ go_library(
importpath = "px.dev/pixie/src/e2e_test/vizier/exectime/cmd",
visibility = ["//visibility:public"],
deps = [
"//src/pixie_cli/pkg/script",
"//src/pixie_cli/pkg/vizier",
"//src/utils/script",
"@com_github_fatih_color//:color",
"@com_github_gofrs_uuid//:uuid",
"@com_github_olekukonko_tablewriter//:tablewriter",
Expand Down
4 changes: 2 additions & 2 deletions src/e2e_test/vizier/exectime/cmd/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/pixie_cli/pkg/vizier"
"px.dev/pixie/src/utils/script"
)

var disallowedScripts = map[string]bool{
Expand Down Expand Up @@ -203,7 +203,7 @@ func (d *BytesDistribution) Stddev() float64 {
}

func createBundleReader(bundleFile string) (*script.BundleManager, error) {
br, err := script.NewBundleManager([]string{bundleFile})
br, err := script.NewBundleManagerWithOrg([]string{bundleFile}, "", "")
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion src/pixie_cli/pkg/cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ go_library(
"//src/pixie_cli/pkg/live",
"//src/pixie_cli/pkg/pxanalytics",
"//src/pixie_cli/pkg/pxconfig",
"//src/pixie_cli/pkg/script",
"//src/pixie_cli/pkg/update",
"//src/pixie_cli/pkg/utils",
"//src/pixie_cli/pkg/vizier",
"//src/shared/goversion",
"//src/shared/services/utils",
"//src/utils",
"//src/utils/script",
"//src/utils/shared/artifacts",
"//src/utils/shared/certs",
"//src/utils/shared/k8s",
Expand Down
2 changes: 1 addition & 1 deletion src/pixie_cli/pkg/cmd/create_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/utils/script"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion src/pixie_cli/pkg/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ import (
"px.dev/pixie/src/pixie_cli/pkg/components"
"px.dev/pixie/src/pixie_cli/pkg/pxanalytics"
"px.dev/pixie/src/pixie_cli/pkg/pxconfig"
"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/pixie_cli/pkg/utils"
"px.dev/pixie/src/pixie_cli/pkg/vizier"
utils2 "px.dev/pixie/src/utils"
"px.dev/pixie/src/utils/script"
"px.dev/pixie/src/utils/shared/artifacts"
"px.dev/pixie/src/utils/shared/k8s"
yamlsutils "px.dev/pixie/src/utils/shared/yamls"
Expand Down
2 changes: 1 addition & 1 deletion src/pixie_cli/pkg/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import (
"github.com/spf13/viper"

"px.dev/pixie/src/pixie_cli/pkg/components"
"px.dev/pixie/src/pixie_cli/pkg/script"
cliUtils "px.dev/pixie/src/pixie_cli/pkg/utils"
"px.dev/pixie/src/pixie_cli/pkg/vizier"
"px.dev/pixie/src/utils"
"px.dev/pixie/src/utils/script"
"px.dev/pixie/src/utils/shared/k8s"
)

Expand Down
2 changes: 1 addition & 1 deletion src/pixie_cli/pkg/cmd/live.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (

"px.dev/pixie/src/api/proto/cloudpb"
"px.dev/pixie/src/pixie_cli/pkg/live"
"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/pixie_cli/pkg/utils"
"px.dev/pixie/src/pixie_cli/pkg/vizier"
"px.dev/pixie/src/utils/script"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion src/pixie_cli/pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (
"github.com/spf13/viper"

"px.dev/pixie/src/cloud/api/ptproxy"
"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/pixie_cli/pkg/utils"
"px.dev/pixie/src/pixie_cli/pkg/vizier"
"px.dev/pixie/src/utils/script"
)

func init() {
Expand Down
7 changes: 5 additions & 2 deletions src/pixie_cli/pkg/cmd/script_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"

"px.dev/pixie/src/pixie_cli/pkg/auth"
"px.dev/pixie/src/pixie_cli/pkg/components"
"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/utils/script"
)

const defaultBundleFile = "https://storage.googleapis.com/pixie-prod-artifacts/script-bundles/bundle-core.json"
Expand All @@ -51,7 +52,9 @@ func createBundleReader() (*script.BundleManager, error) {
if bundleFile == "" {
bundleFile = defaultBundleFile
}
br, err := script.NewBundleManager([]string{bundleFile, ossBundleFile})

authInfo := auth.MustLoadDefaultCredentials()
br, err := script.NewBundleManagerWithOrg([]string{bundleFile, ossBundleFile}, authInfo.OrgID, authInfo.OrgName)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion src/pixie_cli/pkg/live/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ go_library(
"//src/api/proto/vizierpb:vizier_pl_go_proto",
"//src/pixie_cli/pkg/auth",
"//src/pixie_cli/pkg/components",
"//src/pixie_cli/pkg/script",
"//src/pixie_cli/pkg/utils",
"//src/pixie_cli/pkg/vizier",
"//src/utils/script",
"@com_github_alecthomas_chroma//quick",
"@com_github_alecthomas_participle//:participle",
"@com_github_alecthomas_participle//lexer",
Expand Down
2 changes: 1 addition & 1 deletion src/pixie_cli/pkg/live/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/sahilm/fuzzy"

"px.dev/pixie/src/api/proto/cloudpb"
"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/utils/script"
)

// Very rudimentary tokenizer. Not going to be fully robust, but it should be fine for our purposes.
Expand Down
2 changes: 1 addition & 1 deletion src/pixie_cli/pkg/live/live.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import (
"px.dev/pixie/src/api/proto/cloudpb"
"px.dev/pixie/src/api/proto/vizierpb"
"px.dev/pixie/src/pixie_cli/pkg/components"
"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/pixie_cli/pkg/utils"
"px.dev/pixie/src/pixie_cli/pkg/vizier"
"px.dev/pixie/src/utils/script"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion src/pixie_cli/pkg/live/new_autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"px.dev/pixie/src/api/proto/cloudpb"
"px.dev/pixie/src/pixie_cli/pkg/auth"
"px.dev/pixie/src/pixie_cli/pkg/components"
"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/utils/script"
)

// AutocompleteModal is a modal for autocomplete.
Expand Down
2 changes: 1 addition & 1 deletion src/pixie_cli/pkg/vizier/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ go_library(
"//src/pixie_cli/pkg/components",
"//src/pixie_cli/pkg/pxanalytics",
"//src/pixie_cli/pkg/pxconfig",
"//src/pixie_cli/pkg/script",
"//src/pixie_cli/pkg/utils",
"//src/shared/services",
"//src/utils",
"//src/utils/script",
"//src/utils/shared/k8s",
"@com_github_fatih_color//:color",
"@com_github_gofrs_uuid//:uuid",
Expand Down
2 changes: 1 addition & 1 deletion src/pixie_cli/pkg/vizier/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ import (
"px.dev/pixie/src/api/proto/vispb"
"px.dev/pixie/src/api/proto/vizierpb"
"px.dev/pixie/src/pixie_cli/pkg/auth"
"px.dev/pixie/src/pixie_cli/pkg/script"
cliUtils "px.dev/pixie/src/pixie_cli/pkg/utils"
"px.dev/pixie/src/shared/services"
"px.dev/pixie/src/utils"
"px.dev/pixie/src/utils/script"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion src/pixie_cli/pkg/vizier/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import (
"px.dev/pixie/src/api/proto/vizierpb"
"px.dev/pixie/src/pixie_cli/pkg/pxanalytics"
"px.dev/pixie/src/pixie_cli/pkg/pxconfig"
"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/pixie_cli/pkg/utils"
"px.dev/pixie/src/utils/script"
)

type taskWrapper struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ go_library(
"script.go",
"well_known.go",
],
importpath = "px.dev/pixie/src/pixie_cli/pkg/script",
importpath = "px.dev/pixie/src/utils/script",
visibility = ["//src:__subpackages__"],
deps = [
"//src/api/proto/vispb:vis_pl_go_proto",
"//src/pixie_cli/pkg/auth",
"//src/pixie_cli/pkg/utils",
"@com_github_bmatcuk_doublestar//:doublestar",
"@com_github_gogo_protobuf//jsonpb",
"@com_github_sirupsen_logrus//:logrus",
"@com_github_spf13_viper//:viper",
"@in_gopkg_yaml_v2//:yaml_v2",
],
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ import (
"strings"
"sync"

"px.dev/pixie/src/pixie_cli/pkg/auth"
"px.dev/pixie/src/pixie_cli/pkg/utils"
log "github.com/sirupsen/logrus"
)

// BundleManager reads a script bundle.
Expand Down Expand Up @@ -81,15 +80,15 @@ func NewBundleManagerWithOrg(bundleFiles []string, orgID, orgName string) (*Bund
if isValidURL(bundleFile) {
resp, err := http.Get(bundleFile)
if err != nil {
utils.WithError(err).Error("Error checking bundle file URL")
log.WithError(err).Error("Error checking bundle file URL")
return
}
defer resp.Body.Close()
r = resp.Body
} else {
f, err := os.Open(bundleFile)
if err != nil {
utils.WithError(err).Error("Error reading bundle file")
log.WithError(err).Error("Error reading bundle file")
return
}
defer f.Close()
Expand All @@ -99,7 +98,7 @@ func NewBundleManagerWithOrg(bundleFiles []string, orgID, orgName string) (*Bund
var b bundle
err := json.NewDecoder(r).Decode(&b)
if err != nil {
utils.WithError(err).Error("Error decoding bundle file")
log.WithError(err).Error("Error decoding bundle file")
return
}

Expand Down Expand Up @@ -142,21 +141,14 @@ func NewBundleManagerWithOrg(bundleFiles []string, orgID, orgName string) (*Bund
}, nil
}

// NewBundleManager reads the json bundle and initializes the bundle reader.
func NewBundleManager(bundleFiles []string) (*BundleManager, error) {
// TODO(zasgar): Refactor user login state, etc.
authInfo := auth.MustLoadDefaultCredentials()
return NewBundleManagerWithOrg(bundleFiles, authInfo.OrgID, authInfo.OrgName)
}

// GetScripts returns metadata about available scripts.
func (b BundleManager) GetScripts() []*ExecutableScript {
s := make([]*ExecutableScript, 0)
i := 0
for k, val := range b.scripts {
pixieScript, err := pixieScriptToExecutableScript(k, val)
if err != nil {
utils.WithError(err).Error("Failed to parse script, skipping...")
log.WithError(err).Error("Failed to parse script, skipping...")
continue
}
s = append(s, pixieScript)
Expand Down Expand Up @@ -193,7 +185,7 @@ func (b BundleManager) GetScript(scriptName string) (*ExecutableScript, error) {
func (b BundleManager) MustGetScript(scriptName string) *ExecutableScript {
es, err := b.GetScript(scriptName)
if err != nil {
utils.WithError(err).Fatal("Failed to get script")
log.WithError(err).Fatal("Failed to get script")
}
return es
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"px.dev/pixie/src/pixie_cli/pkg/script"
"px.dev/pixie/src/utils/script"
)

func setupTest() *script.FlagSet {
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit d9f55b6

Please sign in to comment.