Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ INTEGRATION_MODS := $(shell $(FIND_INTEGRATION_TEST_MODS) | xargs $(TO_MOD_DIR)

GROUP ?= all
FOR_GROUP_TARGET=for-$(GROUP)-target
GOTOOLCHAIN ?= go1.25.7+auto
# Modules such as processor/elasticapmprocessor require go >= 1.26.
GOTOOLCHAIN ?= go1.26.5+auto

.DEFAULT_GOAL := all

Expand Down Expand Up @@ -92,7 +93,16 @@ remove-toolchain:
# Build a collector based on the Elastic components (generate Elastic collector)
.PHONY: genelasticcol
genelasticcol:
GOTOOLCHAIN=${GOTOOLCHAIN} GOOS=${TARGET_GOOS} GOARCH=${TARGET_GOARCH} $(BUILDER) --config ./distributions/elastic-components/manifest.yaml
@set +e; \
Comment thread
carsonip marked this conversation as resolved.
Outdated
GOTOOLCHAIN=${GOTOOLCHAIN} GOOS=${TARGET_GOOS} GOARCH=${TARGET_GOARCH} $(BUILDER) \
--config ./distributions/elastic-components/manifest.yaml --skip-compilation=true; \
status=$$?; \
set -e; \
if [ ! -f ./_build/go.mod ]; then exit $${status:-1}; fi; \
cd ./_build && GOTOOLCHAIN=${GOTOOLCHAIN} $(GOCMD) mod tidy; \
cd ..; \
GOTOOLCHAIN=${GOTOOLCHAIN} GOOS=${TARGET_GOOS} GOARCH=${TARGET_GOARCH} $(BUILDER) \
--config ./distributions/elastic-components/manifest.yaml --skip-get-modules=true

# Validate that the Elastic components collector can run with the example configuration.
.PHONY: elasticcol-validate
Expand All @@ -119,12 +129,39 @@ builddocker:
.PHONY: otelsoak-validate
otelsoak-validate: genelasticcol
ELASTIC_APM_SERVER_URL=http://localhost:8200 ELASTIC_APM_API_KEY=foobar ./loadgen/cmd/otelsoak/otelsoak validate --config ./loadgen/cmd/otelsoak/config.example.yaml
ELASTIC_SERVER_URL=http://localhost:8200 ELASTIC_APM_API_KEY=foobar ./loadgen/cmd/otelsoak/otelsoak validate --config ./loadgen/cmd/otelsoak/config.vercel.example.yaml

# Run otelsoak
.PHONY: otelsoak-run
otelsoak-run: genelasticcol
./loadgen/cmd/otelsoak/otelsoak --config ./loadgen/cmd/otelsoak/config.example.yaml $(ARGS)

# Run otelsoak against a Vercel Managed Inputs drain endpoint (HTTP NDJSON via httpexporter).
# Optional: VERCEL_SIGNAL=logs|speed_insights|both (default logs).
# For both, cats logs.jsonl + speed_insights.jsonl into a temp file at run time.
VERCEL_SIGNAL ?= logs
VERCEL_TESTDATA := loadgen/cmd/otelsoak/testdata/vercel
.PHONY: otelsoak-run-vercel
otelsoak-run-vercel: genelasticcol
@case "$(VERCEL_SIGNAL)" in \
logs|speed_insights) \
./loadgen/cmd/otelsoak/otelsoak --config ./loadgen/cmd/otelsoak/config.vercel.example.yaml $(ARGS); \
;; \
both) \
tmp=$$(mktemp); \
cat $(VERCEL_TESTDATA)/logs.jsonl $(VERCEL_TESTDATA)/speed_insights.jsonl > $$tmp; \
Comment thread
gizas marked this conversation as resolved.
Outdated
./loadgen/cmd/otelsoak/otelsoak --config ./loadgen/cmd/otelsoak/config.vercel.example.yaml \
--set receivers.loadgen.logs.jsonl_file=$$tmp $(ARGS); \
status=$$?; \
rm -f $$tmp; \
exit $$status; \
;; \
*) \
echo "VERCEL_SIGNAL must be logs, speed_insights, or both (got: $(VERCEL_SIGNAL))" >&2; \
exit 1; \
;; \
esac


# Clones the upstream opentelemetry-collector repository in a temporal .release
# directory. If the directory already exists,
Expand Down
2 changes: 2 additions & 0 deletions distributions/elastic-components/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ exporters:
- gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.157.0
- gomod: go.opentelemetry.io/collector/exporter/otlpexporter v0.157.0
- gomod: go.opentelemetry.io/collector/exporter/otlphttpexporter v0.157.0
- gomod: github.com/elastic/opentelemetry-collector-components/internal/exporter/httpexporter v0.1.0

providers:
- gomod: go.opentelemetry.io/collector/confmap/provider/envprovider v1.63.0
Expand Down Expand Up @@ -94,5 +95,6 @@ replaces:
- github.com/elastic/opentelemetry-collector-components/receiver/integrationreceiver => ../receiver/integrationreceiver
- github.com/elastic/opentelemetry-collector-components/receiver/entityanalyticsreceiver => ../receiver/entityanalyticsreceiver
- github.com/elastic/opentelemetry-collector-components/receiver/akamaisiemreceiver => ../receiver/akamaisiemreceiver
- github.com/elastic/opentelemetry-collector-components/internal/exporter/httpexporter => ../internal/exporter/httpexporter
- github.com/elastic/opentelemetry-collector-components/processor/elastictraceprocessor => ../processor/elastictraceprocessor
- github.com/elastic/opentelemetry-collector-components/internal/elasticattr => ../internal/elasticattr
1 change: 1 addition & 0 deletions internal/exporter/httpexporter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../Makefile.Common
47 changes: 47 additions & 0 deletions internal/exporter/httpexporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# HTTP body exporter
Comment thread
carsonip marked this conversation as resolved.

<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [development]: logs |
| Distributions | [] |

[development]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#development
<!-- end autogenerated section -->

The HTTP body exporter POSTs log record bodies as the raw HTTP request body.
Bodies are joined with newlines (NDJSON-friendly). It does **not** send OTLP.

This is intended for load generation against Managed Input drain endpoints
(for example Vercel) when used with [`loadgenreceiver`](../../receiver/loadgenreceiver) both in otelsoak / otelbench.

## Configuration

```yaml
exporters:
http:
endpoint: https://example.ingest.us-central1.gcp.qa.elastic.cloud/inputs/vercel/_default_
headers:
- name: Authorization
value: "ApiKey ${env:ELASTIC_APM_API_KEY}"
tls:
insecure_skip_verify: true
timeout: 60s
```

| Field | Description |
| --- | --- |
| `endpoint` | Full URL to POST (required). |
| `headers` | Extra HTTP headers (e.g. `Authorization`). |
| `tls` | Standard collector TLS client settings. |
| `timeout` | HTTP client timeout (default `30s`). |
| `retry_on_failure` | Standard exporter retry settings. |
| `sending_queue` | Standard exporter queue settings. |

`Content-Type` defaults to `application/json` when not set in `headers`.

## Sample otelsoak pipeline (Vercel drain)

Put each drain NDJSON line in a loadgen OTLP-JSONL log body (see
`loadgen/cmd/otelsoak/testdata/vercel/`). Select logs, speed-insights, or both
with `VERCEL_SIGNAL` in [`config.vercel.example.yaml`](../../loadgen/cmd/otelsoak/config.vercel.example.yaml).
58 changes: 58 additions & 0 deletions internal/exporter/httpexporter/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package httpexporter // import "github.com/elastic/opentelemetry-collector-components/internal/exporter/httpexporter"

import (
"errors"
"fmt"
"net/url"

"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configoptional"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter/exporterhelper"
)

// Config configures the HTTP body exporter.
type Config struct {
// ClientConfig holds standard HTTP client settings (endpoint, headers, TLS, timeout).
confighttp.ClientConfig `mapstructure:",squash"`

// RetryConfig defines retry configuration for failed exports.
RetryConfig configretry.BackOffConfig `mapstructure:"retry_on_failure"`

// QueueConfig defines optional sending queue settings.
QueueConfig configoptional.Optional[exporterhelper.QueueBatchConfig] `mapstructure:"sending_queue"`
}

func (cfg *Config) Validate() error {
if cfg.Endpoint == "" {
return errors.New("endpoint is required")
}
u, err := url.Parse(cfg.Endpoint)
if err != nil {
return fmt.Errorf("endpoint must be a valid URL: %w", err)
}
if u.Scheme != "http" && u.Scheme != "https" {
return fmt.Errorf("endpoint scheme must be http or https, got %q", u.Scheme)
}
if u.Host == "" {
return errors.New("endpoint must include a host")
}
return nil
}
23 changes: 23 additions & 0 deletions internal/exporter/httpexporter/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//go:generate mdatagen metadata.yaml

// Package httpexporter posts log record bodies as an HTTP request body.
// It is intended for load generation against raw HTTP ingest endpoints
// such as Managed Input drains (e.g. Vercel NDJSON), not OTLP.
package httpexporter // import "github.com/elastic/opentelemetry-collector-components/internal/exporter/httpexporter"
117 changes: 117 additions & 0 deletions internal/exporter/httpexporter/exporter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package httpexporter // import "github.com/elastic/opentelemetry-collector-components/internal/exporter/httpexporter"

import (
"bytes"
"context"
"fmt"
"io"
"net/http"
"strings"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/pdata/plog"
"go.uber.org/zap"
)

const defaultContentType = "application/json"

type httpExporter struct {
config *Config
logger *zap.Logger
settings component.TelemetrySettings
httpClient *http.Client
}

func newExporter(cfg *Config, set exporter.Settings) (*httpExporter, error) {
if err := cfg.Validate(); err != nil {
return nil, err
}
return &httpExporter{
config: cfg,
logger: set.Logger,
settings: set.TelemetrySettings,
}, nil
}

func (e *httpExporter) start(ctx context.Context, host component.Host) error {
client, err := e.config.ToClient(ctx, host.GetExtensions(), e.settings)
if err != nil {
return fmt.Errorf("failed to create HTTP client: %w", err)
}
e.httpClient = client
return nil
}

func (e *httpExporter) pushLogs(ctx context.Context, ld plog.Logs) error {
body := encodeLogBodies(ld)
if len(body) == 0 {
return nil
}

req, err := http.NewRequestWithContext(ctx, http.MethodPost, e.config.Endpoint, bytes.NewReader(body))
if err != nil {
return fmt.Errorf("failed to create request: %w", err)
}

if req.Header.Get("Content-Type") == "" {
req.Header.Set("Content-Type", defaultContentType)
}

resp, err := e.httpClient.Do(req)
if err != nil {
return fmt.Errorf("failed to POST to %s: %w", e.config.Endpoint, err)
}
defer func() {
// Drain body so connections can be reused.
_, _ = io.Copy(io.Discard, resp.Body)
if err := resp.Body.Close(); err != nil {
e.logger.Warn("failed to close response body", zap.Error(err))
}
}()

if resp.StatusCode < 200 || resp.StatusCode >= 300 {
Comment thread
gizas marked this conversation as resolved.
Outdated
return fmt.Errorf("POST %s returned status %d", e.config.Endpoint, resp.StatusCode)
}
return nil
}

// encodeLogBodies joins each log record body as a line (NDJSON-friendly).
func encodeLogBodies(ld plog.Logs) []byte {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: return (buf bytes.Buffer, empty bool)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var b strings.Builder

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: better perf from bytes.Buffer?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goos: linux
goarch: amd64
pkg: github.com/elastic/opentelemetry-collector-components/internal/exporter/httpexporter
cpu: AMD Ryzen 7 PRO 8840HS w/ Radeon 780M Graphics 
                      │ /tmp/old.txt │             /tmp/new.txt             │
                      │    sec/op    │    sec/op     vs base                │
Encode/001_records-16   67.75n ± 16%   74.90n ± 32%  +10.57% (p=0.037 n=10)
Encode/010_records-16   742.3n ± 10%   744.8n ±  9%        ~ (p=0.811 n=10)
Encode/100_records-16   9.397µ ±  8%   4.742µ ±  5%  -49.55% (p=0.000 n=10)
geomean                 778.9n         641.9n        -17.59%

                      │ /tmp/old.txt │             /tmp/new.txt             │
                      │     B/op     │     B/op      vs base                │
Encode/001_records-16     192.0 ± 0%     144.0 ± 0%  -25.00% (p=0.000 n=10)
Encode/010_records-16   3.469Ki ± 0%   2.953Ki ± 0%  -14.86% (p=0.000 n=10)
Encode/100_records-16   54.09Ki ± 0%   23.95Ki ± 0%  -55.72% (p=0.000 n=10)
geomean                 3.277Ki        2.151Ki       -34.37%

                      │ /tmp/old.txt │             /tmp/new.txt             │
                      │  allocs/op   │ allocs/op   vs base                  │
Encode/001_records-16     2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=10) ¹
Encode/010_records-16     6.000 ± 0%   6.000 ± 0%        ~ (p=1.000 n=10) ¹
Encode/100_records-16    13.000 ± 0%   9.000 ± 0%  -30.77% (p=0.000 n=10)
geomean                   5.383        4.762       -11.54%
¹ all samples are equal

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix bytes changes
changed to use bytes.Buffer

rls := ld.ResourceLogs()
for i := 0; i < rls.Len(); i++ {
sls := rls.At(i).ScopeLogs()
for j := 0; j < sls.Len(); j++ {
records := sls.At(j).LogRecords()
for k := 0; k < records.Len(); k++ {
line := records.At(k).Body().AsString()
if line == "" {
continue
}
if b.Len() > 0 {
b.WriteByte('\n')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • q: does actual vercel have trailing newlines? Either way, in ndjson spec empty lines should be ignored. We can skip the Len() > 0 check and write \n immediately after WriteString
  • Do we have a test in our receiver that checks our handling of empty lines?

@gizas gizas Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No dont see anything. It works because we have the json.Decoder

func newVercelJSONDecoder(reader io.Reader) *json.Decoder {

}
b.WriteString(line)
}
}
}
return []byte(b.String())
}
Loading
Loading