Skip to content

Commit

Permalink
better loging
Browse files Browse the repository at this point in the history
  • Loading branch information
dudo committed Nov 29, 2023
1 parent 69e853a commit aa79456
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,32 @@ import (
"io"
"log"
"os"
"time"

"px.dev/pxapi"
"px.dev/pxapi/errdefs"
"px.dev/pxapi/types"
)

func main() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

// Create a Pixie client with local standalonePEM listening address
ctx := context.Background()
client, err := pxapi.NewClient(
ctx,
pxapi.WithDirectAddr("127.0.0.1:12345"),
pxapi.WithDirectCredsInsecure(),
)
if err != nil {
panic(err)
log.Fatalf("Failed to create Pixie client: %v", err)
}

// Create a connection to the host.
hostID := "localhost"
vz, err := client.NewVizierClient(ctx, hostID)
if err != nil {
panic(err)
log.Fatalf("Failed to create Vizier client: %v", err)
}

// Create TableMuxer to accept results table.
Expand All @@ -38,32 +41,32 @@ func main() {
// Read PxL script from file
content, err := os.ReadFile("./config/config.pxl")
if err != nil {
panic(err)
log.Fatalf("Failed to read PxL script: %v", err)
}
pxl := string(content)

// Execute the PxL script and get the resultSet
resultSet, err := vz.ExecuteScript(ctx, pxl, tm)
if err != nil {
panic(err)
log.Fatalf("Failed to execute script: %v", err)
}
defer resultSet.Close()

// Loop to receive the PxL script results.
for {
err := resultSet.Stream()
if err != nil {
if err == io.EOF {
if err == io.EOF || err == context.Canceled {
// End of stream
break
}
if errdefs.IsCompilationError(err) {
log.Printf("Error compiling stream: %s", err.Error())
log.Printf("Compilation error: %v", err)
break
}
// Handle other kinds of runtime errors

log.Printf("Error streaming: %+v", err)
log.Printf("Stream error: %v", err)
}
}
}
Expand Down

0 comments on commit aa79456

Please sign in to comment.