Skip to content

Commit 52465c8

Browse files
TylerHelmuthRoryCrispin
authored andcommitted
[exporter/honeycombmarker] Fix default url and dataset_slug (open-telemetry#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
1 parent f2f5f34 commit 52465c8

File tree

8 files changed

+105
-30
lines changed

8 files changed

+105
-30
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: honeycombmarkerexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix default api_url and dataset_slug
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [29309]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
@@ -0,0 +1,18 @@
22
# Honeycomb Marker Exporter
33

4-
This exporter allows creating markers, via the Honeycomb Markers API, based on the look of incoming telemetry.
4+
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.
55

66
The following configuration options are supported:
77

88
* `api_key` (Required): This is the API key for your Honeycomb account.
9-
* `api_url` (Required): This sets the hostname to send marker data to.
9+
* `api_url` (Optional): This sets the hostname to send marker data to. If not set, will default to `https://api.honeycomb.io/`
1010
* `markers` (Required): This is a list of configurations to create an event marker.
11-
* `type` (Required): Specifies the marker type.
12-
* `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.
13-
* `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.
14-
* `rules` (Required): This is a list of OTTL rules that determine when to create an event marker.
15-
* `log_conditions` (Required): A list of ottllog conditions that determine a match
16-
Example:
11+
* `type` (Required): Specifies the marker type.
12+
* `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.
13+
* `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.
14+
* `dataset_slug` (Optional): The dataset in which to create the marker. If not set, will default to `__all__`.
15+
* `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.
16+
* `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.
1717

18+
Example:
1819
```yaml
1920
exporters:
2021
honeycombmarker:
21-
api_key: "environment-api-key"
22-
api_url: "https://api.honeycomb.io"
22+
api_key: {{env:HONEYCOMB_API_KEY}}
2323
markers:
24-
- type: "marker-type"
25-
message_key: "marker-message"
26-
url_key: "marker-url"
27-
dataset_slug: "__all__"
24+
# Creates a new marker anytime the exporter sees a k8s event with a reason of Backoff
25+
- type: k8s-backoff-events
2826
rules:
2927
- log_conditions:
30-
- body == "test"
31-
```
28+
- IsMap(body) and IsMap(body["object"] and body["object"]["reason"] == "Backoff"
29+
```
30+

exporter/honeycombmarkerexporter/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ func (cfg *Config) Validate() error {
7373
return fmt.Errorf("marker must have a type %v", m)
7474
}
7575

76-
if m.DatasetSlug == "" {
77-
return fmt.Errorf("marker must have a dataset slug %v", m)
78-
}
79-
8076
if len(m.Rules.LogConditions) == 0 {
8177
return fmt.Errorf("marker must have rules %v", m)
8278
}

exporter/honeycombmarkerexporter/config_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ func TestLoadConfig(t *testing.T) {
2828
}{
2929
{
3030
id: component.NewIDWithName(metadata.Type, ""),
31+
expected: &Config{
32+
APIKey: "test-apikey",
33+
APIURL: "https://api.honeycomb.io",
34+
Markers: []Marker{
35+
{
36+
Type: "fooType",
37+
Rules: Rules{
38+
LogConditions: []string{
39+
`body == "test"`,
40+
},
41+
},
42+
},
43+
},
44+
},
45+
},
46+
{
47+
id: component.NewIDWithName(metadata.Type, "all_fields"),
3148
expected: &Config{
3249
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
3350
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
@@ -43,7 +60,7 @@ func TestLoadConfig(t *testing.T) {
4360
`body == "test"`,
4461
},
4562
},
46-
DatasetSlug: "__all__",
63+
DatasetSlug: "testing",
4764
},
4865
},
4966
},
@@ -60,9 +77,6 @@ func TestLoadConfig(t *testing.T) {
6077
{
6178
id: component.NewIDWithName(metadata.Type, "no_markers_supplied"),
6279
},
63-
{
64-
id: component.NewIDWithName(metadata.Type, "no_dataset_slug"),
65-
},
6680
}
6781

6882
for _, tt := range tests {

exporter/honeycombmarkerexporter/factory.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ func NewFactory() exporter.Factory {
2323

2424
func createDefaultConfig() component.Config {
2525
return &Config{
26-
APIKey: "",
27-
APIURL: "api.honeycomb.io:443",
28-
Markers: []Marker{},
26+
APIURL: "https://api.honeycomb.io",
2927
}
3028
}
3129

exporter/honeycombmarkerexporter/logs_exporter.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"io"
1212
"net/http"
13+
"strings"
1314

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

23+
const (
24+
defaultDatasetSlug = "__all__"
25+
)
26+
2227
type honeycombLogsExporter struct {
2328
set component.TelemetrySettings
2429
markers []Marker
@@ -95,7 +100,12 @@ func (e *honeycombLogsExporter) sendMarker(ctx context.Context, marker Marker, l
95100
return err
96101
}
97102

98-
url := fmt.Sprintf("%s/1/markers/%s", e.config.APIURL, marker.DatasetSlug)
103+
datasetSlug := marker.DatasetSlug
104+
if datasetSlug == "" {
105+
datasetSlug = defaultDatasetSlug
106+
}
107+
108+
url := fmt.Sprintf("%s/1/markers/%s", strings.TrimRight(e.config.APIURL, "/"), datasetSlug)
99109
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(request))
100110
if err != nil {
101111
return err

exporter/honeycombmarkerexporter/logs_exporter_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func TestExportMarkers(t *testing.T) {
2222
name string
2323
config Config
2424
attributeMap map[string]string
25+
expectedURL string
2526
}{
2627
{
2728
name: "all fields",
@@ -46,6 +47,7 @@ func TestExportMarkers(t *testing.T) {
4647
"url": "https://api.testhost.io",
4748
"type": "test-type",
4849
},
50+
expectedURL: "/1/markers/test-dataset",
4951
},
5052
{
5153
name: "no message key",
@@ -68,6 +70,7 @@ func TestExportMarkers(t *testing.T) {
6870
"url": "https://api.testhost.io",
6971
"type": "test-type",
7072
},
73+
expectedURL: "/1/markers/test-dataset",
7174
},
7275
{
7376
name: "no url",
@@ -90,6 +93,27 @@ func TestExportMarkers(t *testing.T) {
9093
"message": "this is a test message",
9194
"type": "test-type",
9295
},
96+
expectedURL: "/1/markers/test-dataset",
97+
},
98+
{
99+
name: "no dataset_slug",
100+
config: Config{
101+
APIKey: "test-apikey",
102+
Markers: []Marker{
103+
{
104+
Type: "test-type",
105+
Rules: Rules{
106+
LogConditions: []string{
107+
`body == "test"`,
108+
},
109+
},
110+
},
111+
},
112+
},
113+
attributeMap: map[string]string{
114+
"type": "test-type",
115+
},
116+
expectedURL: "/1/markers/__all__",
93117
},
94118
}
95119

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

111135
apiKey := req.Header.Get("X-Honeycomb-Team")
112136
assert.Equal(t, apiKey, string(tt.config.APIKey))

exporter/honeycombmarkerexporter/testdata/config.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
honeycombmarker:
2+
api_key: "test-apikey"
3+
markers:
4+
- type: "fooType"
5+
rules:
6+
log_conditions:
7+
- body == "test"
8+
honeycombmarker/all_fields:
29
api_key: "test-apikey"
310
api_url: "https://api.testhost.io"
411
sending_queue:
@@ -16,7 +23,7 @@ honeycombmarker:
1623
- type: "fooType"
1724
message_key: "test message"
1825
url_key: "https://api.testhost.io"
19-
dataset_slug: "__all__"
26+
dataset_slug: "testing"
2027
rules:
2128
log_conditions:
2229
- body == "test"

0 commit comments

Comments
 (0)