Skip to content
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

[exporter/honeycombmarker] Fix default url and dataset_slug #29309

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 27 additions & 0 deletions .chloggen/honeycombmarker-fix-url-bug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: honeycombmarkerexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix default api_url and dataset_slug

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [29309]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
31 changes: 15 additions & 16 deletions exporter/honeycombmarkerexporter/README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
@@ -0,0 +1,18 @@
# Honeycomb Marker Exporter

This exporter allows creating markers, via the Honeycomb Markers API, based on the look of incoming telemetry.
This exporter allows creating [markers](https://docs.honeycomb.io/working-with-your-data/markers/), via the [Honeycomb Markers API](https://docs.honeycomb.io/api/tag/Markers#operation/createMarker), based on the look of incoming telemetry.

The following configuration options are supported:

* `api_key` (Required): This is the API key for your Honeycomb account.
* `api_url` (Required): This sets the hostname to send marker data to.
* `api_url` (Optional): This sets the hostname to send marker data to. If not set, will default to `https://api.honeycomb.io/`
* `markers` (Required): This is a list of configurations to create an event marker.
* `type` (Required): Specifies the marker type.
* `message_key`: This attribute will be used as the message. It describes the event marker. If necessary the value will be converted to a string.
* `url_key`: This attribute will be used as the url. It can be accessed through the event marker in Honeycomb. If necessary the value will be converted to a string.
* `rules` (Required): This is a list of OTTL rules that determine when to create an event marker.
* `log_conditions` (Required): A list of ottllog conditions that determine a match
Example:
* `type` (Required): Specifies the marker type.
* `dataset_slug` (Optional): The dataset in which to create the marker. If not set, will default to `__all__`.
* `message_key` (Optional): This attribute will be used as the message. It describes the event marker. If necessary the value will be converted to a string.
* `url_key` (Optional): This attribute will be used as the url. It can be accessed through the event marker in Honeycomb. If necessary the value will be converted to a string.
* `rules` (Required): This is a list of [OTTL](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl) rules that determine when to create an event marker.
TylerHelmuth marked this conversation as resolved.
Show resolved Hide resolved
* `log_conditions` (Required): A list of [OTTL log](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottllog) conditions that determine a match. The marker will be created if **ANY** condition matches.

Example:
```yaml
exporters:
honeycombmarker:
api_key: "environment-api-key"
api_url: "https://api.honeycomb.io"
api_key: {{env:HONEYCOMB_API_KEY}}
markers:
- type: "marker-type"
message_key: "marker-message"
url_key: "marker-url"
dataset_slug: "__all__"
# Creates a new marker anytime the exporter sees a k8s event with a reason of Backoff
- type: k8s-backoff-events
rules:
- log_conditions:
- body == "test"
```
- IsMap(body) and IsMap(body["object"] and body["object"]["reason"] == "Backoff"
```
4 changes: 0 additions & 4 deletions exporter/honeycombmarkerexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ func (cfg *Config) Validate() error {
return fmt.Errorf("marker must have a type %v", m)
}

if m.DatasetSlug == "" {
return fmt.Errorf("marker must have a dataset slug %v", m)
}

if len(m.Rules.LogConditions) == 0 {
return fmt.Errorf("marker must have rules %v", m)
}
Expand Down
22 changes: 18 additions & 4 deletions exporter/honeycombmarkerexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ func TestLoadConfig(t *testing.T) {
}{
{
id: component.NewIDWithName(metadata.Type, ""),
expected: &Config{
APIKey: "test-apikey",
APIURL: "https://api.honeycomb.io",
Markers: []Marker{
{
Type: "fooType",
Rules: Rules{
LogConditions: []string{
`body == "test"`,
},
},
},
},
},
},
{
id: component.NewIDWithName(metadata.Type, "all_fields"),
expected: &Config{
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
Expand All @@ -43,7 +60,7 @@ func TestLoadConfig(t *testing.T) {
`body == "test"`,
},
},
DatasetSlug: "__all__",
DatasetSlug: "testing",
},
},
},
Expand All @@ -60,9 +77,6 @@ func TestLoadConfig(t *testing.T) {
{
id: component.NewIDWithName(metadata.Type, "no_markers_supplied"),
},
{
id: component.NewIDWithName(metadata.Type, "no_dataset_slug"),
},
}

for _, tt := range tests {
Expand Down
4 changes: 1 addition & 3 deletions exporter/honeycombmarkerexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ func NewFactory() exporter.Factory {

func createDefaultConfig() component.Config {
return &Config{
APIKey: "",
APIURL: "api.honeycomb.io:443",
Markers: []Marker{},
APIURL: "https://api.honeycomb.io",
}
}

Expand Down
12 changes: 11 additions & 1 deletion exporter/honeycombmarkerexporter/logs_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"io"
"net/http"
"strings"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/plog"
Expand All @@ -19,6 +20,10 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllog"
)

const (
defaultDatasetSlug = "__all__"
)

type honeycombLogsExporter struct {
set component.TelemetrySettings
markers []Marker
Expand Down Expand Up @@ -95,7 +100,12 @@ func (e *honeycombLogsExporter) sendMarker(ctx context.Context, marker Marker, l
return err
}

url := fmt.Sprintf("%s/1/markers/%s", e.config.APIURL, marker.DatasetSlug)
datasetSlug := marker.DatasetSlug
if datasetSlug == "" {
datasetSlug = defaultDatasetSlug
}

url := fmt.Sprintf("%s/1/markers/%s", strings.TrimRight(e.config.APIURL, "/"), marker.DatasetSlug)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(request))
if err != nil {
return err
Expand Down
9 changes: 8 additions & 1 deletion exporter/honeycombmarkerexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
honeycombmarker:
api_key: "test-apikey"
markers:
- type: "fooType"
rules:
log_conditions:
- body == "test"
honeycombmarker/all_fields:
api_key: "test-apikey"
api_url: "https://api.testhost.io"
sending_queue:
Expand All @@ -16,7 +23,7 @@ honeycombmarker:
- type: "fooType"
message_key: "test message"
url_key: "https://api.testhost.io"
dataset_slug: "__all__"
dataset_slug: "testing"
rules:
log_conditions:
- body == "test"
Expand Down
Loading