Skip to content

Commit

Permalink
Merge branch 'grafana:main' into helm-chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Khushi Jain authored Feb 23, 2024
2 parents d26d692 + cc085a6 commit 9f56afe
Show file tree
Hide file tree
Showing 27 changed files with 73 additions and 37 deletions.
4 changes: 1 addition & 3 deletions bpf/go_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ static __always_inline void server_trace_parent(void *goroutine_addr, tp_info_t
static __always_inline u8 client_trace_parent(void *goroutine_addr, tp_info_t *tp_i, void *req_header) {
// Get traceparent from the Request.Header
u8 found_trace_id = 0;
u8 trace_id_exists = 0;

// May get overriden when decoding existing traceparent or finding a server span, but otherwise we set sample ON
tp_i->flags = 1;
Expand All @@ -164,7 +163,6 @@ static __always_inline u8 client_trace_parent(void *goroutine_addr, tp_info_t *t
void *traceparent_ptr = extract_traceparent_from_req_headers(req_header);
if (traceparent_ptr != NULL) {
unsigned char buf[TP_MAX_VAL_LENGTH];
trace_id_exists = 1;
long res = bpf_probe_read(buf, sizeof(buf), traceparent_ptr);
if (res < 0) {
bpf_dbg_printk("can't copy traceparent header");
Expand Down Expand Up @@ -194,7 +192,7 @@ static __always_inline u8 client_trace_parent(void *goroutine_addr, tp_info_t *t
urand_bytes(tp_i->span_id, SPAN_ID_SIZE_BYTES);
}

return trace_id_exists;
return found_trace_id;
}


Expand Down
1 change: 1 addition & 0 deletions bpf/go_grpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ int uprobe_server_handleStream_return(struct pt_regs *ctx) {
done:
bpf_map_delete_elem(&ongoing_grpc_server_requests, &goroutine_addr);
bpf_map_delete_elem(&ongoing_grpc_request_status, &goroutine_addr);
bpf_map_delete_elem(&go_trace_map, &goroutine_addr);

return 0;
}
Expand Down
7 changes: 4 additions & 3 deletions bpf/go_nethttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ static __always_inline int writeHeaderHelper(struct pt_regs *ctx, u64 req_offset

done:
bpf_map_delete_elem(&ongoing_http_server_requests, &goroutine_addr);
bpf_map_delete_elem(&go_trace_map, &goroutine_addr);
return 0;
}

Expand Down Expand Up @@ -278,15 +279,15 @@ static __always_inline void roundTripStartHelper(struct pt_regs *ctx) {
bpf_map_update_elem(&ongoing_http_client_requests_data, &goroutine_addr, &trace, BPF_ANY);

#ifndef NO_HEADER_PROPAGATION
if (!existing_tp) {
//if (!existing_tp) {
void *headers_ptr = 0;
bpf_probe_read(&headers_ptr, sizeof(headers_ptr), (void*)(req + req_header_ptr_pos));
bpf_dbg_printk("goroutine_addr %lx, req ptr %llx, headers_ptr %llx", goroutine_addr, req, headers_ptr);

if (headers_ptr) {
bpf_map_update_elem(&header_req_map, &headers_ptr, &goroutine_addr, BPF_ANY);
}
}
//}
#endif
}

Expand Down Expand Up @@ -542,7 +543,7 @@ int uprobe_http2FramerWriteHeaders_returns(struct pt_regs *ctx) {
bpf_probe_read(&n, sizeof(n), (void *)(w_ptr + 40));
bpf_probe_read(&cap, sizeof(cap), (void *)(w_ptr + 24));

bpf_dbg_printk("Found f_info, this is the place to write to w = %llx, buf=%llx, n=%d, size=%d", w_ptr, buf_arr, n, cap);
bpf_dbg_printk("Found f_info, this is the place to write to w = %llx, buf=%llx, n=%lld, size=%lld", w_ptr, buf_arr, n, cap);
if (buf_arr && n < (cap - HTTP2_ENCODED_HEADER_LEN)) {
uint8_t tp_str[TP_MAX_VAL_LENGTH];

Expand Down
25 changes: 18 additions & 7 deletions docs/sources/configure/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,17 @@ It is disabled by default to avoid cardinality explosion.
The `buckets` object allows overriding the bucket boundaries of diverse histograms. See
[Overriding histogram buckets](#overriding-histogram-buckets) section for more details.

| YAML | Environment variable | Type | Default |
|-------------------------|------------------------------------------------------------|----------|-----------------------------|
| `histogram_aggregation` | `OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION` | `string` | `explicit_bucket_histogram` |

Specifies the default aggregation to use for histogram instruments.

Accepted values are:

* `explicit_bucket_histogram` (default): use [Explicit Bucket Histogram Aggregation](https://opentelemetry.io/docs/specs/otel/metrics/sdk/#explicit-bucket-histogram-aggregation).
* `base2_exponential_bucket_histogram`: use [Base2 Exponential Bucket Histogram Aggregation](https://opentelemetry.io/docs/specs/otel/metrics/sdk/#base2-exponential-bucket-histogram-aggregation).

### Overriding histogram buckets

For both OpenTelemetry and Prometheus metrics exporters, you can override the histogram bucket
Expand Down Expand Up @@ -800,14 +811,14 @@ conventions recommend a different set of bucket boundaries.
### Use native histograms and exponential histograms
For Prometheus [native histograms](https://prometheus.io/docs/concepts/metric_types/#histogram) are enabled if you have the `native-histograms` feature enabled.
For OpenTelemetry you can use [exponential histograms](https://opentelemetry.io/docs/specs/otel/metrics/data-model/#exponentialhistogram) for the predefined histograms instead of defining the buckets manually.
| YAML | Environment variable | Type | Default |
| ---------- | ------------------------------------------------------------------------- | ---- | ------- |
| `use_exponential_histograms` | `BEYLA_OTEL_USE_EXPONENTIAL_HISTOGRAMS` | `boolean` | `false` |
For Prometheus, [native histograms](https://prometheus.io/docs/concepts/metric_types/#histogram) are enabled if you
[enable the `native-histograms` feature in your Prometheus collector](https://prometheus.io/docs/prometheus/latest/feature_flags/#native-histograms).
For OpenTelemetry you can use [exponential histograms](https://opentelemetry.io/docs/specs/otel/metrics/data-model/#exponentialhistogram)
for the predefined histograms instead of defining the buckets manually. You need to set up the standard
[OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION](https://opentelemetry.io/docs/specs/otel/metrics/sdk_exporters/otlp/#additional-configuration)
environment variable. See the `histogram_aggregation` section in the [OTEL metrics exporter](#otel-metrics-exporter) section
for more information.
## OTEL traces exporter
Expand Down
11 changes: 6 additions & 5 deletions pkg/beyla/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ var defaultConfig = Config{
},
},
Metrics: otel.MetricsConfig{
Protocol: otel.ProtocolUnset,
MetricsProtocol: otel.ProtocolUnset,
Interval: 5 * time.Second,
Buckets: otel.DefaultBuckets,
ReportersCacheLen: ReporterLRUSize,
Protocol: otel.ProtocolUnset,
MetricsProtocol: otel.ProtocolUnset,
Interval: 5 * time.Second,
Buckets: otel.DefaultBuckets,
ReportersCacheLen: ReporterLRUSize,
HistogramAggregation: otel.AggregationExplicit,
},
Traces: otel.TracesConfig{
Protocol: otel.ProtocolUnset,
Expand Down
2 changes: 2 additions & 0 deletions pkg/beyla/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ otel_metrics_export:
endpoint: localhost:3030
buckets:
duration_histogram: [0, 1, 2]
histogram_aggregation: base2_exponential_bucket_histogram
prometheus_export:
buckets:
request_size_histogram: [0, 10, 20, 22]
Expand Down Expand Up @@ -104,6 +105,7 @@ network:
DurationHistogram: []float64{0, 1, 2},
RequestSizeHistogram: otel.DefaultBuckets.RequestSizeHistogram,
},
HistogramAggregation: "base2_exponential_bucket_histogram",
},
Traces: otel.TracesConfig{
Protocol: otel.ProtocolUnset,
Expand Down
Binary file modified pkg/internal/ebpf/grpc/bpf_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_debug_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_debug_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_tp_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_tp_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_tp_debug_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_tp_debug_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/nethttp/bpf_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/nethttp/bpf_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/nethttp/bpf_debug_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/nethttp/bpf_debug_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/nethttp/bpf_tp_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/nethttp/bpf_tp_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/nethttp/bpf_tp_debug_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/nethttp/bpf_tp_debug_bpfel_x86.o
Binary file not shown.
39 changes: 29 additions & 10 deletions pkg/internal/export/otel/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const (

UsualPortGRPC = "4317"
UsualPortHTTP = "4318"

AggregationExplicit = "explicit_bucket_histogram"
AggregationExponential = "base2_exponential_bucket_histogram"
)

type MetricsConfig struct {
Expand All @@ -59,8 +62,8 @@ type MetricsConfig struct {
ReportTarget bool `yaml:"report_target" env:"BEYLA_METRICS_REPORT_TARGET"`
ReportPeerInfo bool `yaml:"report_peer" env:"BEYLA_METRICS_REPORT_PEER"`

Buckets Buckets `yaml:"buckets"`
UseExponentialHistograms bool `yaml:"use_exponential_histograms" env:"BEYLA_OTEL_USE_EXPONENTIAL_HISTOGRAMS"`
Buckets Buckets `yaml:"buckets"`
HistogramAggregation string `yaml:"histogram_aggregation" env:"OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION"`

ReportersCacheLen int `yaml:"reporters_cache_len" env:"BEYLA_METRICS_REPORT_CACHE_LEN"`

Expand Down Expand Up @@ -171,21 +174,23 @@ func newMetricsReporter(ctx context.Context, cfg *MetricsConfig, ctxInfo *global
}

func (mr *MetricsReporter) newMetricSet(service svc.ID) (*Metrics, error) {
mlog().Debug("creating new Metrics reporter", "service", service)
mlog := mlog().With("service", service)
mlog.Debug("creating new Metrics reporter")
useExponentialHistograms := isExponentialAggregation(mr.cfg, mlog)
resources := otelResource(service)
m := Metrics{
ctx: mr.ctx,
provider: metric.NewMeterProvider(
metric.WithResource(resources),
metric.WithReader(metric.NewPeriodicReader(mr.exporter,
metric.WithInterval(mr.cfg.Interval))),
metric.WithView(otelHistogramConfig(HTTPServerDuration, mr.cfg.Buckets.DurationHistogram, mr.cfg.UseExponentialHistograms)),
metric.WithView(otelHistogramConfig(HTTPClientDuration, mr.cfg.Buckets.DurationHistogram, mr.cfg.UseExponentialHistograms)),
metric.WithView(otelHistogramConfig(RPCServerDuration, mr.cfg.Buckets.DurationHistogram, mr.cfg.UseExponentialHistograms)),
metric.WithView(otelHistogramConfig(RPCClientDuration, mr.cfg.Buckets.DurationHistogram, mr.cfg.UseExponentialHistograms)),
metric.WithView(otelHistogramConfig(SQLClientDuration, mr.cfg.Buckets.DurationHistogram, mr.cfg.UseExponentialHistograms)),
metric.WithView(otelHistogramConfig(HTTPServerRequestSize, mr.cfg.Buckets.RequestSizeHistogram, mr.cfg.UseExponentialHistograms)),
metric.WithView(otelHistogramConfig(HTTPClientRequestSize, mr.cfg.Buckets.RequestSizeHistogram, mr.cfg.UseExponentialHistograms)),
metric.WithView(otelHistogramConfig(HTTPServerDuration, mr.cfg.Buckets.DurationHistogram, useExponentialHistograms)),
metric.WithView(otelHistogramConfig(HTTPClientDuration, mr.cfg.Buckets.DurationHistogram, useExponentialHistograms)),
metric.WithView(otelHistogramConfig(RPCServerDuration, mr.cfg.Buckets.DurationHistogram, useExponentialHistograms)),
metric.WithView(otelHistogramConfig(RPCClientDuration, mr.cfg.Buckets.DurationHistogram, useExponentialHistograms)),
metric.WithView(otelHistogramConfig(SQLClientDuration, mr.cfg.Buckets.DurationHistogram, useExponentialHistograms)),
metric.WithView(otelHistogramConfig(HTTPServerRequestSize, mr.cfg.Buckets.RequestSizeHistogram, useExponentialHistograms)),
metric.WithView(otelHistogramConfig(HTTPClientRequestSize, mr.cfg.Buckets.RequestSizeHistogram, useExponentialHistograms)),
),
}
// time units for HTTP and GRPC durations are in seconds, according to the OTEL specification:
Expand Down Expand Up @@ -224,6 +229,20 @@ func (mr *MetricsReporter) newMetricSet(service svc.ID) (*Metrics, error) {
return &m, nil
}

func isExponentialAggregation(mc *MetricsConfig, mlog *slog.Logger) bool {
switch mc.HistogramAggregation {
case AggregationExponential:
return true
case AggregationExplicit:
// do nothing
default:
mlog.Warn("invalid value for histogram aggregation. Accepted values are: "+
AggregationExponential+", "+AggregationExplicit+" (default). Using default",
"value", mc.HistogramAggregation)
}
return false
}

// TODO: restore as private
func InstantiateMetricsExporter(ctx context.Context, cfg *MetricsConfig, log *slog.Logger) (metric.Exporter, error) {
var err error
Expand Down
18 changes: 9 additions & 9 deletions pkg/internal/goexec/offsets.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"target": {
"versions": {
"oldest": "1.40.0",
"newest": "1.61.1"
"newest": "1.62.0"
},
"offsets": [
{
Expand All @@ -132,7 +132,7 @@
"s": {
"versions": {
"oldest": "1.40.0",
"newest": "1.61.1"
"newest": "1.62.0"
},
"offsets": [
{
Expand All @@ -146,7 +146,7 @@
"ctx": {
"versions": {
"oldest": "1.40.0",
"newest": "1.61.1"
"newest": "1.62.0"
},
"offsets": [
{
Expand All @@ -158,7 +158,7 @@
"method": {
"versions": {
"oldest": "1.40.0",
"newest": "1.61.1"
"newest": "1.62.0"
},
"offsets": [
{
Expand All @@ -170,7 +170,7 @@
"st": {
"versions": {
"oldest": "1.40.0",
"newest": "1.61.1"
"newest": "1.62.0"
},
"offsets": [
{
Expand All @@ -184,7 +184,7 @@
"nextID": {
"versions": {
"oldest": "1.40.0",
"newest": "1.61.1"
"newest": "1.62.0"
},
"offsets": [
{
Expand Down Expand Up @@ -226,7 +226,7 @@
"peer": {
"versions": {
"oldest": "1.60.0",
"newest": "1.61.1"
"newest": "1.62.0"
},
"offsets": [
{
Expand All @@ -252,7 +252,7 @@
"Addr": {
"versions": {
"oldest": "1.60.0",
"newest": "1.61.1"
"newest": "1.62.0"
},
"offsets": [
{
Expand All @@ -264,7 +264,7 @@
"LocalAddr": {
"versions": {
"oldest": "1.60.0",
"newest": "1.61.1"
"newest": "1.62.0"
},
"offsets": [
{
Expand Down
1 change: 1 addition & 0 deletions pkg/internal/netolly/ebpf/net_bpfel_arm64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/internal/netolly/ebpf/net_bpfel_x86.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/integration/suites_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func TestSuite_OldestGoVersion(t *testing.T) {
}

func TestSuite_UnsupportedGoVersion(t *testing.T) {
t.Skip("seems flaky, we need to look into this")
compose, err := docker.ComposeSuite("docker-compose-1.16.yml", path.Join(pathOutput, "test-suite-unsupported-go.log"))
require.NoError(t, err)
require.NoError(t, compose.Up())
Expand Down

0 comments on commit 9f56afe

Please sign in to comment.