Skip to content

Commit

Permalink
Bugfix: Reformat YAML VQL reformating code. (Velocidex#3836)
Browse files Browse the repository at this point in the history
  • Loading branch information
scudette authored Oct 16, 2024
1 parent c061da1 commit 3f62b22
Show file tree
Hide file tree
Showing 9 changed files with 765 additions and 601 deletions.
33 changes: 28 additions & 5 deletions bin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"runtime/pprof"
"runtime/trace"
"time"

"github.com/AlecAivazis/survey/v2"
kingpin "github.com/alecthomas/kingpin/v2"
Expand Down Expand Up @@ -69,6 +70,10 @@ var (
profile_flag = app.Flag(
"profile", "Write profiling information to this file.").String()

profile_duration = app.Flag(
"profile_duration", "Generate a profile file for each period in seconds.").
Int64()

trace_flag = app.Flag(
"trace", "Write trace information to this file.").String()

Expand Down Expand Up @@ -204,13 +209,31 @@ func main() {
}

if *profile_flag != "" {
f2, err := os.Create(*profile_flag)
kingpin.FatalIfError(err, "Profile file.")
if *profile_duration > 0 {
go func() {
for i := 0; ; i++ {
filename := fmt.Sprintf("%s_%d.profile", *profile_flag, i)
fmt.Printf("Writing profile at %v", filename)
f2, err := os.Create(filename)
if err != nil {
return
}

pprof.StartCPUProfile(f2)
time.Sleep(time.Duration(*profile_duration) * time.Second)
pprof.StopCPUProfile()
f2.Close()
}
}()

err = pprof.StartCPUProfile(f2)
kingpin.FatalIfError(err, "Profile file.")
defer pprof.StopCPUProfile()
} else {
f2, err := os.Create(*profile_flag)
kingpin.FatalIfError(err, "Profile file.")

err = pprof.StartCPUProfile(f2)
kingpin.FatalIfError(err, "Profile file.")
defer pprof.StopCPUProfile()
}
}

for _, command_handler := range command_handlers {
Expand Down
1,045 changes: 529 additions & 516 deletions config/proto/config.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions config/proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,9 @@ message DatastoreConfig {
int64 memcache_datastore_max_item_size = 11;
int64 memcache_datastore_max_dir_size = 12;

// Remote datastore is used by the minion (default 1000 sec)
int64 remote_datastore_rpc_deadline = 18;

// Experimental - do not set in configs yet!
string minion_implementation = 7;
string master_implementation = 8;
Expand Down
31 changes: 19 additions & 12 deletions datastore/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@ import (
var (
remote_mu sync.Mutex
remote_datastopre_imp = NewRemoteDataStore(context.Background())
RPC_TIMEOUT = 100 // Seconds
RPC_BACKOFF = 10.0
RPC_RETRY = 10
timeoutError = errors.New("Timeout")
timeoutError = errors.New("gRPC Timeout in Remote datastore")
)

func RPCTimeout(config_obj *config_proto.Config) time.Duration {
if config_obj.Datastore == nil ||
config_obj.Datastore.RemoteDatastoreRpcDeadline == 0 {
return time.Duration(100 * time.Second)
}
return time.Duration(config_obj.Datastore.RemoteDatastoreRpcDeadline) * time.Second
}

func Retry(ctx context.Context,
config_obj *config_proto.Config, cb func() error) error {
var err error
Expand Down Expand Up @@ -93,8 +100,8 @@ func (self *RemoteDataStore) _GetSubject(

defer Instrument("read", "RemoteDataStore", urn)()

ctx, cancel := context.WithTimeout(context.Background(),
time.Duration(RPC_TIMEOUT)*time.Second)
ctx, cancel := context.WithTimeoutCause(
context.Background(), RPCTimeout(config_obj), timeoutError)
defer cancel()

// Make the call as the superuser
Expand Down Expand Up @@ -190,8 +197,8 @@ func (self *RemoteDataStore) _SetSubjectWithCompletion(
return err
}

ctx, cancel := context.WithTimeout(context.Background(),
time.Duration(RPC_TIMEOUT)*time.Second)
ctx, cancel := context.WithTimeoutCause(
context.Background(), RPCTimeout(config_obj), timeoutError)
defer cancel()

// Make the call as the superuser
Expand Down Expand Up @@ -229,8 +236,8 @@ func (self *RemoteDataStore) _DeleteSubjectWithCompletion(

defer Instrument("delete", "RemoteDataStore", urn)()

ctx, cancel := context.WithTimeout(context.Background(),
time.Duration(RPC_TIMEOUT)*time.Second)
ctx, cancel := context.WithTimeoutCause(
context.Background(), RPCTimeout(config_obj), timeoutError)
defer cancel()

conn, closer, err := grpc_client.Factory.GetAPIClient(
Expand Down Expand Up @@ -270,8 +277,8 @@ func (self *RemoteDataStore) _DeleteSubject(

defer Instrument("delete", "RemoteDataStore", urn)()

ctx, cancel := context.WithTimeout(context.Background(),
time.Duration(RPC_TIMEOUT)*time.Second)
ctx, cancel := context.WithTimeoutCause(
context.Background(), RPCTimeout(config_obj), timeoutError)
defer cancel()

conn, closer, err := grpc_client.Factory.GetAPIClient(
Expand Down Expand Up @@ -314,8 +321,8 @@ func (self *RemoteDataStore) _ListChildren(

defer Instrument("list", "RemoteDataStore", urn)()

ctx, cancel := context.WithTimeout(context.Background(),
time.Duration(RPC_TIMEOUT)*time.Second)
ctx, cancel := context.WithTimeoutCause(
context.Background(), RPCTimeout(config_obj), timeoutError)
defer cancel()

conn, closer, err := grpc_client.Factory.GetAPIClient(
Expand Down
4 changes: 2 additions & 2 deletions gui/velociraptor/src/components/events/event-table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ class EventTableLabelGroup extends React.Component {
</Card.Text>
{ !_.isEmpty(current_artifacts) &&
<><h2>{T("Label")} { current_label.label}</h2>
<Table>
<thead><tr>
<Table className="paged-table">
<thead><tr className="paged-table-header">
<th>
{T("Artifact Collected")}
</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,17 +589,18 @@ export default class NotebookCellRenderer extends React.Component {

return <>
<Dropdown.Menu>
{ _.map(suggestions, x=>{
{ _.map(suggestions, (x, i)=>{
return <Dropdown.Item
key={x.name}
key={i}

onClick={()=>{
this.props.addCell(
this.state.cell.cell_id,
x.type,
x.input,
x.env);
}}
title="{x.name}">
title={x.name}>
{x.name}
</Dropdown.Item>;
})}
Expand Down Expand Up @@ -835,7 +836,7 @@ export default class NotebookCellRenderer extends React.Component {

<Dropdown
title={T("Suggestion")}
drop="right"
drop="end"
variant="default-outline">
<Dropdown.Toggle
className="dropdown-item"
Expand Down
28 changes: 14 additions & 14 deletions services/repository/fixtures/TestReformat.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
"name: Foo",
"sources:",
"- query: |",
" SELECT A,",
" B,",
" C",
" FROM info(arg1=Foobar, arg2=\"XXXXX\")",
" SELECT A,",
" B,",
" C",
" FROM info(arg1=Foobar, arg2=\"XXXXX\")",
"",
"- query: |-",
" SELECT A,",
" B,",
" C",
" FROM info()",
" SELECT A,",
" B,",
" C",
" FROM info()",
"",
"- description: Foo bar",
""
Expand All @@ -24,16 +24,16 @@
"sources:",
"- query: SELECT * FROM info()",
"- query: |",
" SELECT A",
" FROM scope()",
" SELECT A",
" FROM scope()",
""
],
"export reformatted": [
"",
"name: Exported",
"export: |",
" SELECT *",
" FROM scope()",
" SELECT *",
" FROM scope()",
""
],
"preconditions": [
Expand All @@ -42,8 +42,8 @@
"precondition: SELECT * FROM info()",
"sources:",
"- precondition: |",
" SELECT *",
" FROM info()",
" SELECT *",
" FROM info()",
""
]
}
Loading

0 comments on commit 3f62b22

Please sign in to comment.