-
Notifications
You must be signed in to change notification settings - Fork 66
[Otelsoak] Adds Vercel drain mode for otelsoak #1347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
32fbed2
add vercel otelsoak
gizas eded153
Merge branch 'main' of github.com:elastic/opentelemetry-collector-com…
gizas 373902c
add chlog
gizas 71299c8
add processor to change times
gizas bacc611
remove doc
gizas 5b56899
update pr number
gizas 8bd0d38
fix make common for http
gizas 87cc4e2
fix lint and govlun
gizas db420a9
add files inside build
gizas 80404da
gotidy
gizas 77ae6c8
fix bytes changes
gizas e7cd9e5
Merge branch 'main' into vercel_drain_otelsoak
carsonip 800a25f
Merge branch 'main' of github.com:elastic/opentelemetry-collector-com…
gizas ddccaee
revert make changes
gizas f544b08
Merge branch 'vercel_drain_otelsoak' of github.com:elastic/openteleme…
gizas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| include ../../../Makefile.Common |
This file contains hidden or 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,48 @@ | ||
| # HTTP body exporter | ||
|
|
||
| <!-- 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) | ||
|
|
||
| Use loadgenreceiver embedded Vercel presets (`vercel_logs`, | ||
| `vercel_speed_insights`, `vercel_both`) via `VERCEL_SIGNAL` in | ||
| [`config.vercel.example.yaml`](../../loadgen/cmd/otelsoak/config.vercel.example.yaml). | ||
| Fixtures live under [`receiver/loadgenreceiver/testdata/vercel/`](../../receiver/loadgenreceiver/testdata/vercel/). | ||
This file contains hidden or 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,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 | ||
| } |
This file contains hidden or 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,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" |
This file contains hidden or 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,121 @@ | ||
| // 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" | ||
|
|
||
| "go.opentelemetry.io/collector/component" | ||
| "go.opentelemetry.io/collector/consumer/consumererror" | ||
| "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 { | ||
| buf, empty := encodeLogBodies(ld) | ||
| if empty { | ||
| return nil | ||
| } | ||
|
|
||
| req, err := http.NewRequestWithContext(ctx, http.MethodPost, e.config.Endpoint, bytes.NewReader(buf.Bytes())) | ||
| 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 { | ||
| return nil | ||
| } | ||
|
|
||
| err = fmt.Errorf("POST %s returned status %d", e.config.Endpoint, resp.StatusCode) | ||
| // 5xx and 429 are typically transient; other 4xx (auth, bad request) are not. | ||
| if resp.StatusCode >= 500 || resp.StatusCode == http.StatusTooManyRequests { | ||
| return err | ||
| } | ||
| return consumererror.NewPermanent(err) | ||
| } | ||
|
|
||
| // encodeLogBodies joins each log record body as NDJSON (one JSON text per line, | ||
| // each terminated by '\n', including after the last record). | ||
| func encodeLogBodies(ld plog.Logs) (buf bytes.Buffer, empty bool) { | ||
| 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 | ||
| } | ||
| buf.WriteString(line) | ||
| buf.WriteByte('\n') | ||
| } | ||
| } | ||
| } | ||
| return buf, buf.Len() == 0 | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.