-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove network.allowed_attributes and use attributes.allow.<metric name>
- Loading branch information
Showing
21 changed files
with
382 additions
and
237 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,17 +220,18 @@ Beyla only includes a subset of the available attributes to avoid leading to | |
a [cardinality explosion](/blog/2022/02/15/what-are-cardinality-spikes-and-why-do-they-matter/) in | ||
the metrics storage, especially if some attributes like `src.address` or `dst.address` capture the IP addresses of the external traffic. | ||
|
||
The `allowed_attributes` YAML subsection under `network` (or the `BEYLA_NETWORK_ALLOWED_ATTRIBUTES` environment variable) | ||
lets to select the attributes to report: | ||
The `attributes.allow` YAML subsection allows to select the attributes to report: | ||
Check warning on line 223 in docs/sources/network/quickstart.md GitHub Actions / vale
|
||
|
||
```yaml | ||
network: | ||
enable: true | ||
allowed_attributes: | ||
- k8s.src.owner.name | ||
- k8s.src.namespace | ||
- k8s.dst.owner.name | ||
- k8s.dst.namespace | ||
attributes: | ||
allow: | ||
beyla.network.flow.bytes: | ||
- k8s.src.owner.name | ||
- k8s.src.namespace | ||
- k8s.dst.owner.name | ||
- k8s.dst.namespace | ||
``` | ||
|
||
The previous example would aggregate the `beyla.network.flow.bytes` value by source and destination Kubernetes owner | ||
|
@@ -245,7 +246,7 @@ The `cidrs` YAML subsection in `network` (or the `BEYLA_NETWORK_CIDRS` environme | |
subnets in [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing), in both IPv4 and IPv6 format. | ||
|
||
The existence of the `cidrs` section leaves the `src.address` and `dst.address` fields untouched, | ||
and adds the `src.cidr` and `dst.cidr` attributes. Don't forget to add them to the `allowed_attributes` | ||
and adds the `src.cidr` and `dst.cidr` attributes. Don't forget to add them to the `attributes.allow` | ||
section: | ||
|
||
```yaml | ||
|
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,83 @@ | ||
package attr | ||
|
||
import ( | ||
"strings" | ||
|
||
"golang.org/x/exp/maps" | ||
|
||
"github.com/grafana/beyla/pkg/internal/metricname" | ||
) | ||
|
||
const globalKey = "global" | ||
|
||
// AllowedAttributesDefinition specifies which attributes are allowed for each metric. | ||
// The key is the name of the metric (either in Prometheus or OpenTelemetry format) | ||
// The value is the enumeration of allowed attributes | ||
type AllowedAttributesDefinition map[metricname.Normal][]string | ||
|
||
var defaultAllowedAttributes = AllowedAttributesDefinition{ | ||
metricname.NormalBeylaNetworkFlows: []string{ | ||
"k8s.src.owner.name", | ||
"k8s.src.namespace", | ||
"k8s.dst.owner.name", | ||
"k8s.dst.namespace", | ||
"k8s.cluster.name", | ||
}, | ||
} | ||
|
||
// Normalize the user-provided input (error-prone, allowing multiple formats) for unified access | ||
// from the code: | ||
// - Convert underscores (prom-like) to dots (OTEL-like) | ||
// - Remove metric suffixes such as .sum, .total, .bucket, etc... | ||
// Only normalize the metric names, as the attribute names are already normalized in the | ||
// PrometheusGetters and OpenTelemetryGetters function | ||
func (aad AllowedAttributesDefinition) Normalize() { | ||
if aad == nil { | ||
return | ||
} | ||
normalized := map[metricname.Normal][]string{} | ||
for metricName, allowedAttrs := range aad { | ||
normalized[normalizeMetric(metricName)] = allowedAttrs | ||
} | ||
maps.Clear(aad) | ||
maps.Copy(aad, normalized) | ||
} | ||
|
||
func normalizeMetric(name metricname.Normal) metricname.Normal { | ||
nameStr := strings.ReplaceAll(string(name), "_", ".") | ||
for _, suffix := range []string{".bucket", ".sum", ".count", ".total"} { | ||
if strings.HasSuffix(nameStr, suffix) { | ||
nameStr = nameStr[:len(nameStr)-len(suffix)] | ||
break | ||
} | ||
} | ||
return metricname.Normal(nameStr) | ||
} | ||
|
||
// For a given metric name, returns the allowed attributes from the following sources | ||
// - If the "global" section is provided, returns its defined list of attribute names. | ||
// - If the metric name section is provided, returns its defined list of attribute names. | ||
// - If both the "global" and metric name sections are provided, merges both and returns | ||
// a deduplicated list of attributes. | ||
// - If none of the above exists, returns the value from the defaultAllowedAttributes, if any. | ||
func (aad AllowedAttributesDefinition) For(metricName metricname.Normal) []string { | ||
var deduped map[string]struct{} | ||
if aad != nil { | ||
deduped = map[string]struct{}{} | ||
for _, attr := range aad[globalKey] { | ||
deduped[attr] = struct{}{} | ||
} | ||
for _, attr := range aad[metricName] { | ||
deduped[attr] = struct{}{} | ||
} | ||
} | ||
// if no attributes are defined for a given metric, let's return the default attributes | ||
if len(deduped) == 0 { | ||
return defaultAllowedAttributes[metricName] | ||
} | ||
allowed := make([]string, 0, len(deduped)) | ||
for attr := range deduped { | ||
allowed = append(allowed, attr) | ||
} | ||
return allowed | ||
} |
Oops, something went wrong.