44package internal
55
66import (
7- "fmt"
87 "math"
98 "sort"
109 "time"
1110
12- vrs "github.com/hashicorp/go-version"
13- "github.com/rs/zerolog/log"
14- "go.mondoo.com/mql/v13"
1511 "go.mondoo.com/mql/v13/llx"
1612 "go.mondoo.com/mql/v13/providers-sdk/v1/resources"
1713)
@@ -37,9 +33,6 @@ type GraphBuilder struct {
3733 // progressReporter is a configured interface to receive progress
3834 // updates
3935 progressReporter ProgressReporter
40- // mondooVersion is the version of mondoo. This is generally sourced
41- // from the binary, but is configurable to make testing easier
42- mondooVersion string
4336 // queryTimeout is the amount of time to wait for the underlying lumi
4437 // runtime to send all the expected datapoints.
4538 queryTimeout time.Duration
@@ -52,7 +45,6 @@ func NewBuilder() *GraphBuilder {
5245 collectDatapointChecksums : []string {},
5346 datapointType : map [string ]string {},
5447 progressReporter : NoopProgressReporter {},
55- mondooVersion : mql .GetCoreVersion (),
5648 queryTimeout : 5 * time .Minute ,
5749 }
5850}
@@ -87,12 +79,7 @@ func (b *GraphBuilder) WithProgressReporter(r ProgressReporter) {
8779 b .progressReporter = r
8880}
8981
90- // WithMondooVersion sets the version of mondoo
91- func (b * GraphBuilder ) WithMondooVersion (mondooVersion string ) {
92- b .mondooVersion = mondooVersion
93- }
94-
95- // WithMondooVersion sets the version of mondoo
82+ // WithQueryTimeout sets the query timeout for the graph executor
9683func (b * GraphBuilder ) WithQueryTimeout (timeout time.Duration ) {
9784 b .queryTimeout = timeout
9885}
@@ -125,24 +112,8 @@ func (b *GraphBuilder) Build(schema resources.ResourcesSchema, runtime llx.Runti
125112 },
126113 }
127114
128- unrunnableQueries := []query {}
129-
130- var mondooVersion * vrs.Version
131- if b .mondooVersion != "" && b .mondooVersion != "unstable" {
132- var err error
133- mondooVersion , err = vrs .NewVersion (b .mondooVersion )
134- if err != nil {
135- log .Warn ().Err (err ).Str ("version" , b .mondooVersion ).Msg ("unable to parse mondoo version" )
136- }
137- }
138-
139115 for queryID , q := range queries {
140- canRun := checkVersion (q .codeBundle , mondooVersion )
141- if canRun {
142- ge .addExecutionQueryNode (queryID , q , q .resolvedProperties , b .datapointType )
143- } else {
144- unrunnableQueries = append (unrunnableQueries , q )
145- }
116+ ge .addExecutionQueryNode (queryID , q , q .resolvedProperties , b .datapointType )
146117 }
147118
148119 datapointsToCollect := make ([]string , len (b .collectDatapointChecksums ))
@@ -152,8 +123,6 @@ func (b *GraphBuilder) Build(schema resources.ResourcesSchema, runtime llx.Runti
152123 ge .addEdge (NodeID (datapointChecksum ), DatapointCollectorID )
153124 }
154125
155- ge .handleUnrunnableQueries (unrunnableQueries )
156-
157126 ge .createFinisherNode (b .progressReporter )
158127
159128 for nodeID := range ge .nodes {
@@ -169,31 +138,6 @@ func (b *GraphBuilder) Build(schema resources.ResourcesSchema, runtime llx.Runti
169138 return ge , nil
170139}
171140
172- // handleUnrunnableQueries takes the queries for which the running version does
173- // to meet the minimum version requirement and marks the datapoints as error.
174- // This is only done for datapoints which will not be reported by a runnable query
175- func (ge * GraphExecutor ) handleUnrunnableQueries (unrunnableQueries []query ) {
176- for _ , q := range unrunnableQueries {
177- for _ , checksum := range CodepointChecksums (q .codeBundle ) {
178- if _ , ok := ge .nodes [NodeID (checksum )]; ok {
179- // If the datapoint will be reported by another query, skip
180- // handling it
181- continue
182- }
183-
184- ge .addDatapointNode (
185- checksum ,
186- nil ,
187- & llx.RawResult {
188- CodeID : checksum ,
189- Data : & llx.RawData {
190- Error : fmt .Errorf ("unable to run query, at least mql version %s required" , q .codeBundle .MinMondooVersion ),
191- },
192- })
193- }
194- }
195- }
196-
197141func (ge * GraphExecutor ) addEdge (from NodeID , to NodeID ) {
198142 ge .edges [from ] = insertSorted (ge .edges [from ], to )
199143}
@@ -327,17 +271,6 @@ func prioritizeNode(nodes map[NodeID]*Node, edges map[NodeID][]NodeID, priorityM
327271 return myDepth
328272}
329273
330- func checkVersion (codeBundle * llx.CodeBundle , curMin * vrs.Version ) bool {
331- if curMin != nil && codeBundle .MinMondooVersion != "" {
332- requiredVer := codeBundle .MinMondooVersion
333- reqMin , err := vrs .NewVersion (requiredVer )
334- if err == nil && curMin .LessThan (reqMin ) {
335- return false
336- }
337- }
338- return true
339- }
340-
341274func insertSorted (ss []string , s string ) []string {
342275 i := sort .SearchStrings (ss , s )
343276 if i < len (ss ) && ss [i ] == s {
0 commit comments