Skip to content

Commit b16dcb2

Browse files
committed
🧹 remove the old min mondoo version handling
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
1 parent 3ee7e3b commit b16dcb2

File tree

9 files changed

+41
-156
lines changed

9 files changed

+41
-156
lines changed

exec/internal/builder.go

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
package internal
55

66
import (
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
9683
func (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-
197141
func (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-
341274
func insertSorted(ss []string, s string) []string {
342275
i := sort.SearchStrings(ss, s)
343276
if i < len(ss) && ss[i] == s {

exec/internal/builder_test.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,8 @@ func TestBuilder(t *testing.T) {
145145
}},
146146
Checksums: map[uint64]string{1: "checksum5", 2: "checksum7"},
147147
},
148-
MinMondooVersion: "9999.9999.9999",
149148
}, nil, nil)
150149

151-
b.WithMondooVersion("100.0.0")
152-
153150
ge, err := b.Build(nil, nil, "assetMrn")
154151
require.NoError(t, err)
155152

@@ -168,11 +165,8 @@ func TestBuilder(t *testing.T) {
168165
hasNode(t, ge, "execution_query/query4", ExecutionQueryNodeType)
169166
hasOutEdges(t, ge, "execution_query/query4", "checksum6")
170167

171-
assert.NotContains(t, ge.nodes, "execution_query/query5")
172-
assert.Nil(t, ge.nodes["checksum5"].data.(*DatapointNodeData).res)
173-
if assert.NotNil(t, ge.nodes["checksum7"].data.(*DatapointNodeData).res) {
174-
assert.Error(t, ge.nodes["checksum7"].data.(*DatapointNodeData).res.Data.Error)
175-
}
168+
hasNode(t, ge, "execution_query/query5", ExecutionQueryNodeType)
169+
hasOutEdges(t, ge, "execution_query/query5", "checksum5", "checksum7")
176170

177171
hasNode(t, ge, "pqep", DatapointNodeType)
178172
hasOutEdges(t, ge, "pqep", CollectionFinisherID)
@@ -194,6 +188,9 @@ func TestBuilder(t *testing.T) {
194188

195189
hasNode(t, ge, "checksum6", DatapointNodeType)
196190
hasOutEdges(t, ge, "checksum6", CollectionFinisherID)
191+
192+
hasNode(t, ge, "checksum7", DatapointNodeType)
193+
hasOutEdges(t, ge, "checksum7", CollectionFinisherID)
197194
}
198195

199196
func hasNode(t *testing.T, ge *GraphExecutor, nodeID NodeID, nodeType NodeType) {

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ require (
5353
github.com/hashicorp/go-hclog v1.6.3
5454
github.com/hashicorp/go-plugin v1.7.0
5555
github.com/hashicorp/go-retryablehttp v0.7.8
56-
github.com/hashicorp/go-version v1.8.0
5756
github.com/hashicorp/vault/api v1.22.0
5857
github.com/hnakamur/go-scp v1.0.2
5958
github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,6 @@ github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b
556556
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
557557
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
558558
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
559-
github.com/hashicorp/go-version v1.8.0 h1:KAkNb1HAiZd1ukkxDFGmokVZe1Xy9HG6NUp+bPle2i4=
560-
github.com/hashicorp/go-version v1.8.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
561559
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
562560
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
563561
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=

mqlc/mqlc.go

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"strconv"
1212
"strings"
1313

14-
"github.com/hashicorp/go-version"
1514
"github.com/lithammer/fuzzysearch/fuzzy"
1615
"github.com/rs/zerolog/log"
1716
"go.mondoo.com/mql/v13"
@@ -960,8 +959,6 @@ func (c *compiler) compileBoundIdentifierWithMqlCtx(id string, binding *variable
960959
return true, types.Nil, errors.New("cannot call resource field with arguments yet")
961960
}
962961

963-
c.Result.MinMondooVersion = getMinMondooVersion(c.Schema, c.Result.MinMondooVersion, resource.Name, id)
964-
965962
// this only happens when we call a field of a bridging resource,
966963
// in which case we don't call the field (since there is nothing to do)
967964
// and instead we call the resource directly:
@@ -1060,8 +1057,6 @@ func (c *compiler) compileResource(id string, calls []*parser.Call) (bool, []*pa
10601057
calls = calls[1:]
10611058
}
10621059

1063-
c.Result.MinMondooVersion = getMinMondooVersion(c.Schema, c.Result.MinMondooVersion, id, "")
1064-
10651060
typ, err := c.addResource(id, resource, call)
10661061
return true, calls, typ, err
10671062
}
@@ -2138,35 +2133,6 @@ func (c *compiler) failIfNoEntrypoints() error {
21382133
return nil
21392134
}
21402135

2141-
func getMinMondooVersion(schema resources.ResourcesSchema, current string, resource string, field string) string {
2142-
info := schema.Lookup(resource)
2143-
if info == nil {
2144-
return current
2145-
}
2146-
2147-
min := info.MinMondooVersion
2148-
if field != "" {
2149-
if finfo, ok := info.Fields[field]; ok && finfo.MinMondooVersion != "" {
2150-
min = finfo.MinMondooVersion
2151-
}
2152-
}
2153-
2154-
if current == "" {
2155-
return min
2156-
} else if min == "" {
2157-
return current
2158-
}
2159-
2160-
vMin, err1 := version.NewVersion(min)
2161-
vCur, err2 := version.NewVersion(current)
2162-
// if the current version requirement is higher than docs, we keep it,
2163-
// otherwise docs wins
2164-
if err1 == nil && err2 == nil && vMin.LessThan(vCur) {
2165-
return current
2166-
}
2167-
return min
2168-
}
2169-
21702136
// CompileAST with a schema into a chunky code
21712137
func CompileAST(ast *parser.AST, props PropsHandler, conf CompilerConfig) (*llx.CodeBundle, error) {
21722138
if conf.Schema == nil {
@@ -2186,11 +2152,10 @@ func CompileAST(ast *parser.AST, props PropsHandler, conf CompilerConfig) (*llx.
21862152
Labels: &llx.Labels{
21872153
Labels: map[string]string{},
21882154
},
2189-
Props: map[string]string{},
2190-
Version: mql.APIVersion(),
2191-
MinMondooVersion: "",
2192-
AutoExpand: map[string]uint64{},
2193-
Vars: map[uint64]string{},
2155+
Props: map[string]string{},
2156+
Version: mql.APIVersion(),
2157+
AutoExpand: map[string]uint64{},
2158+
Vars: map[uint64]string{},
21942159
}
21952160

21962161
c := compiler{

mqlc/mqlc_test.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,18 +1248,6 @@ func TestCompiler_Resource(t *testing.T) {
12481248
})
12491249
}
12501250

1251-
func TestCompiler_Resource_versioning(t *testing.T) {
1252-
compileT(t, "sshd", func(res *llx.CodeBundle) {
1253-
assert.Equal(t, "5.15.0", res.MinMondooVersion)
1254-
})
1255-
}
1256-
1257-
func TestCompiler_Resource_versioning2(t *testing.T) {
1258-
compileT(t, "file.empty", func(res *llx.CodeBundle) {
1259-
assert.Equal(t, "5.18.0", res.MinMondooVersion)
1260-
})
1261-
}
1262-
12631251
func TestCompiler_ResourceWithCall(t *testing.T) {
12641252
compileT(t, "sshd()", func(res *llx.CodeBundle) {
12651253
assertFunction(t, "sshd", nil, res.CodeV2.Blocks[0].Chunks[0])
@@ -1275,7 +1263,6 @@ func TestCompiler_LongResource(t *testing.T) {
12751263
func TestCompiler_ResourceMap(t *testing.T) {
12761264
compileT(t, "sshd.config.params", func(res *llx.CodeBundle) {
12771265
assertFunction(t, "sshd.config", nil, res.CodeV2.Blocks[0].Chunks[0])
1278-
assert.Equal(t, "5.15.0", res.MinMondooVersion)
12791266
assertFunction(t, "params", &llx.Function{
12801267
Type: string(types.Map(types.String, types.String)),
12811268
Binding: (1 << 32) | 1,

providers-sdk/v1/mqlr/lrcore/versions.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ func WriteVersions(path string, versions LrVersions, headerTpl *template.Templat
7272
}
7373

7474
// InjectVersions sets MinProviderVersion on resources and fields in the schema
75-
// based on the versions map. Every field is expected to have an explicit entry;
76-
// fields without one are left empty.
75+
// based on the versions map. Fields whose version matches the parent resource
76+
// are left empty (omitted from JSON via omitempty), since consumers treat an
77+
// unset field version as equal to the resource version.
7778
func InjectVersions(schema *resources.Schema, versions LrVersions) {
7879
// Build a sorted list of resource names (longest first) so we can
7980
// disambiguate field paths like "aws.ec2.instance.tags" where the resource
@@ -86,20 +87,26 @@ func InjectVersions(schema *resources.Schema, versions LrVersions) {
8687
return len(resourceNames[i]) > len(resourceNames[j])
8788
})
8889

90+
// First pass: set resource versions so we can compare against them.
8991
for path, version := range versions {
90-
// First check if path is a resource name directly
9192
if info, ok := schema.Resources[path]; ok {
9293
info.MinProviderVersion = version
93-
continue
9494
}
95+
}
9596

96-
// Otherwise try to split into resource + field using longest-prefix match
97+
// Second pass: set field versions, skipping those that match the resource.
98+
for path, version := range versions {
99+
if _, isResource := schema.Resources[path]; isResource {
100+
continue
101+
}
97102
for _, rName := range resourceNames {
98103
if strings.HasPrefix(path, rName+".") {
99104
fieldName := path[len(rName)+1:]
100105
info := schema.Resources[rName]
101106
if finfo, ok := info.Fields[fieldName]; ok {
102-
finfo.MinProviderVersion = version
107+
if version != info.MinProviderVersion {
108+
finfo.MinProviderVersion = version
109+
}
103110
}
104111
break
105112
}

providers-sdk/v1/mqlr/lrcore/versions_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,11 @@ func TestInjectVersions(t *testing.T) {
116116
InjectVersions(schema, versions)
117117

118118
assert.Equal(t, "9.0.0", schema.Resources["asset"].MinProviderVersion)
119+
// annotations (10.4.0) differs from asset (9.0.0) — set explicitly
119120
assert.Equal(t, "10.4.0", schema.Resources["asset"].Fields["annotations"].MinProviderVersion)
120-
assert.Equal(t, "9.0.0", schema.Resources["asset"].Fields["name"].MinProviderVersion)
121+
// name (9.0.0) matches asset (9.0.0) — left empty (omitted from JSON)
122+
assert.Equal(t, "", schema.Resources["asset"].Fields["name"].MinProviderVersion)
121123
assert.Equal(t, "9.1.1", schema.Resources["asset.eol"].MinProviderVersion)
122-
assert.Equal(t, "9.1.1", schema.Resources["asset.eol"].Fields["date"].MinProviderVersion)
124+
// date (9.1.1) matches asset.eol (9.1.1) — left empty
125+
assert.Equal(t, "", schema.Resources["asset.eol"].Fields["date"].MinProviderVersion)
123126
}

providers-sdk/v1/resources/schema.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ func (s *Schema) Add(other ResourcesSchema) ResourcesSchema {
5151
if v.Name != "" {
5252
existing.Name = v.Name
5353
}
54-
if v.MinMondooVersion != "" {
55-
existing.MinMondooVersion = v.MinMondooVersion
56-
}
5754
if v.Desc != "" {
5855
existing.Desc = v.Desc
5956
}
@@ -81,19 +78,18 @@ func (s *Schema) Add(other ResourcesSchema) ResourcesSchema {
8178
}
8279
} else {
8380
ri := &ResourceInfo{
84-
Id: v.Id,
85-
Name: v.Name,
86-
Fields: make(map[string]*Field, len(v.Fields)),
87-
Init: v.Init,
88-
ListType: v.ListType,
89-
Title: v.Title,
90-
Desc: v.Desc,
91-
Private: v.Private,
92-
IsExtension: v.IsExtension,
93-
MinMondooVersion: v.MinMondooVersion,
94-
Defaults: v.Defaults,
95-
Context: v.Context,
96-
Provider: v.Provider,
81+
Id: v.Id,
82+
Name: v.Name,
83+
Fields: make(map[string]*Field, len(v.Fields)),
84+
Init: v.Init,
85+
ListType: v.ListType,
86+
Title: v.Title,
87+
Desc: v.Desc,
88+
Private: v.Private,
89+
IsExtension: v.IsExtension,
90+
Defaults: v.Defaults,
91+
Context: v.Context,
92+
Provider: v.Provider,
9793
}
9894
for k, v := range v.Fields {
9995
ri.Fields[k] = v

0 commit comments

Comments
 (0)