-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable DNS name resolver by default (#1032)
* Disable name resolver by default * Fine-grained DNS selection * defaulting to k8s name resolution only
- Loading branch information
Showing
24 changed files
with
179 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package maps | ||
|
||
// Bits wraps an unsigned integer that can be used as a bit map | ||
type Bits uint | ||
|
||
type builderOpts[T any] struct { | ||
transform []func(T) T | ||
} | ||
|
||
// BuilderOpt allows defining option for building Bits map in the MappedBits method | ||
type BuilderOpt[T any] func(*builderOpts[T]) | ||
|
||
// WithTransform will apply the provided transformer function to the passed key values | ||
// in the MappedBits constructor function | ||
func WithTransform[T any](transformFunc func(T) T) BuilderOpt[T] { | ||
return func(o *builderOpts[T]) { | ||
o.transform = append(o.transform, transformFunc) | ||
} | ||
} | ||
|
||
// MappedBits builds a Bits map from a set of values (e.g. strings) that are mapped in the form | ||
// value --> corresponding Bits value | ||
// in the "maps" constructor argument | ||
func MappedBits[T comparable](values []T, maps map[T]Bits, opts ...BuilderOpt[T]) Bits { | ||
bo := builderOpts[T]{} | ||
for _, opt := range opts { | ||
opt(&bo) | ||
} | ||
|
||
b := Bits(0) | ||
for _, value := range values { | ||
for _, t := range bo.transform { | ||
value = t(value) | ||
} | ||
if val, ok := maps[value]; ok { | ||
b |= val | ||
} | ||
} | ||
return b | ||
} | ||
|
||
// Has returns true if the map contains all the value Bits passed as argument | ||
func (i Bits) Has(value Bits) bool { | ||
return i&value == value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package maps | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type key int | ||
|
||
var mapper = map[key]Bits{1: 0b0001, 2: 0b0010, 3: 0b0100, 4: 0b1000} | ||
|
||
func TestBits_Full(t *testing.T) { | ||
bits := MappedBits([]key{1, 2, 3, 4}, mapper) | ||
assert.True(t, bits.Has(0b0001)) | ||
assert.True(t, bits.Has(0b0010)) | ||
assert.True(t, bits.Has(0b0100)) | ||
assert.True(t, bits.Has(0b1000)) | ||
} | ||
|
||
func TestBits_Empty(t *testing.T) { | ||
bits := MappedBits(nil, mapper) | ||
assert.False(t, bits.Has(0b0001)) | ||
assert.False(t, bits.Has(0b0010)) | ||
assert.False(t, bits.Has(0b0100)) | ||
assert.False(t, bits.Has(0b1000)) | ||
} | ||
|
||
func TestBits_Transform(t *testing.T) { | ||
bits := MappedBits([]key{10, 30, 8910}, mapper, | ||
WithTransform(func(k key) key { return k / 10 })) | ||
assert.True(t, bits.Has(0b0001)) | ||
assert.False(t, bits.Has(0b0010)) | ||
assert.True(t, bits.Has(0b0100)) | ||
assert.False(t, bits.Has(0b1000)) | ||
assert.False(t, bits.Has(0xb10000)) // key non-existing i the mappers | ||
} |
2 changes: 1 addition & 1 deletion
2
pkg/internal/helpers/maps.go → pkg/internal/helpers/maps/maps.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
pkg/internal/helpers/maps_test.go → pkg/internal/helpers/maps/maps_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package helpers | ||
package maps | ||
|
||
import ( | ||
"slices" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
package kube | ||
|
||
import "strings" | ||
import ( | ||
"strings" | ||
|
||
type informerType int | ||
"github.com/grafana/beyla/pkg/internal/helpers/maps" | ||
) | ||
|
||
const ( | ||
InformerService = informerType(1 << iota) | ||
InformerService = maps.Bits(1 << iota) | ||
InformerReplicaSet | ||
InformerNode | ||
) | ||
|
||
func informerTypes(str []string) informerType { | ||
it := informerType(0) | ||
for _, s := range str { | ||
switch strings.ToLower(s) { | ||
case "service", "services": | ||
it |= InformerService | ||
case "replicaset", "replicasets": | ||
it |= InformerReplicaSet | ||
case "node", "nodes": | ||
it |= InformerNode | ||
} | ||
} | ||
return it | ||
} | ||
|
||
func (i informerType) Has(it informerType) bool { | ||
return i&it != 0 | ||
func informerTypes(str []string) maps.Bits { | ||
return maps.MappedBits( | ||
str, | ||
map[string]maps.Bits{ | ||
"service": InformerService, | ||
"services": InformerService, | ||
"replicaset": InformerReplicaSet, | ||
"replicasets": InformerReplicaSet, | ||
"node": InformerNode, | ||
"nodes": InformerNode, | ||
}, | ||
maps.WithTransform(strings.ToLower), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.