Skip to content

Commit

Permalink
[exporter/honeycombmarker] Fix default url and dataset_slug (open-tel…
Browse files Browse the repository at this point in the history
…emetry#29309)

**Description:** 
Fixes an issue with an incorrect default url. Also fixes issue where
dataset slug was required.

**Link to tracking Issue:** <Issue number if applicable>
Related to
open-telemetry#27666

**Testing:** <Describe what testing was performed and which tests were
added.>
Added new tests and tested manually.

**Documentation:** <Describe the documentation added.>
 Updated up README
  • Loading branch information
TylerHelmuth authored and RoryCrispin committed Nov 24, 2023
1 parent f2f5f34 commit 52465c8
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 30 deletions.
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.
* `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.
* `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.
* `dataset_slug` (Optional): The dataset in which to create the marker. If not set, will default to `__all__`.
* `message_key` (Optional): The key of the attribute whose value will be used as the marker's message. If necessary the value will be converted to a string.
* `url_key` (Optional): The key of the attribute whose value will be used as the marker's url. If necessary the value will be converted to a string.

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, "/"), datasetSlug)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(request))
if err != nil {
return err
Expand Down
26 changes: 25 additions & 1 deletion exporter/honeycombmarkerexporter/logs_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestExportMarkers(t *testing.T) {
name string
config Config
attributeMap map[string]string
expectedURL string
}{
{
name: "all fields",
Expand All @@ -46,6 +47,7 @@ func TestExportMarkers(t *testing.T) {
"url": "https://api.testhost.io",
"type": "test-type",
},
expectedURL: "/1/markers/test-dataset",
},
{
name: "no message key",
Expand All @@ -68,6 +70,7 @@ func TestExportMarkers(t *testing.T) {
"url": "https://api.testhost.io",
"type": "test-type",
},
expectedURL: "/1/markers/test-dataset",
},
{
name: "no url",
Expand All @@ -90,6 +93,27 @@ func TestExportMarkers(t *testing.T) {
"message": "this is a test message",
"type": "test-type",
},
expectedURL: "/1/markers/test-dataset",
},
{
name: "no dataset_slug",
config: Config{
APIKey: "test-apikey",
Markers: []Marker{
{
Type: "test-type",
Rules: Rules{
LogConditions: []string{
`body == "test"`,
},
},
},
},
},
attributeMap: map[string]string{
"type": "test-type",
},
expectedURL: "/1/markers/__all__",
},
}

Expand All @@ -106,7 +130,7 @@ func TestExportMarkers(t *testing.T) {
for attr := range tt.attributeMap {
assert.Equal(t, decodedBody[attr], tt.attributeMap[attr])
}
assert.Contains(t, req.URL.Path, tt.config.Markers[0].DatasetSlug)
assert.Contains(t, req.URL.Path, tt.expectedURL)

apiKey := req.Header.Get("X-Honeycomb-Team")
assert.Equal(t, apiKey, string(tt.config.APIKey))
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

0 comments on commit 52465c8

Please sign in to comment.