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

feat: add ability to filter and export markers #27862

Merged
merged 46 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
e7737de
feat: add ability to filter and export markers
fchikwekwe Oct 18, 2023
87ee53c
test: add export tests and export functionality
fchikwekwe Oct 19, 2023
bca314b
test: test log exporter
fchikwekwe Oct 24, 2023
2adc71e
feat: add queue and retry settings
fchikwekwe Oct 26, 2023
3e8ae0e
test: remove log conditions from response testing
fchikwekwe Nov 1, 2023
2d7a06b
test: add bad path log tests
fchikwekwe Nov 2, 2023
78ab791
chore: merge in main'
fchikwekwe Nov 2, 2023
00bcf5d
Merge branch 'main' into feat/hny-marker-exporter
fchikwekwe Nov 2, 2023
aceca83
Merge remote-tracking branch 'contrib/main' into feat/hny-marker-expo…
fchikwekwe Nov 2, 2023
168be30
Merge branch 'feat/hny-marker-exporter' of https://github.com/fchikwe…
fchikwekwe Nov 2, 2023
905c018
doc: update README with new config
fchikwekwe Nov 2, 2023
aee1f38
chore: restore deps from main
fchikwekwe Nov 2, 2023
b018f82
chore: comply with lint
fchikwekwe Nov 2, 2023
35543ee
chore: manually update out of sync deps
fchikwekwe Nov 2, 2023
07aa44d
chore: regen dependabot files
fchikwekwe Nov 2, 2023
dcac5c5
fix: update log tests to properly access config vals
fchikwekwe Nov 2, 2023
c79ee46
Merge branch 'main' into feat/hny-marker-exporter
fchikwekwe Nov 2, 2023
c4baad9
Merge branch 'main' into feat/hny-marker-exporter
fchikwekwe Nov 13, 2023
31e50f3
feat: add honeycombexpoter to otelcontribcol
fchikwekwe Nov 13, 2023
25f6c29
Merge branch 'feat/hny-marker-exporter' of https://github.com/fchikwe…
fchikwekwe Nov 13, 2023
4027d8b
feat: add honeycombexpoter to otelcontribcol
fchikwekwe Nov 13, 2023
92ba5c1
fix: remove test files
fchikwekwe Nov 14, 2023
f8f3d26
fix: run go mod tidy
fchikwekwe Nov 14, 2023
1394bca
fix: update more deps
fchikwekwe Nov 14, 2023
a559255
Merge branch 'main' into feat/hny-marker-exporter
fchikwekwe Nov 14, 2023
9ca87b9
fix: update deps with required versions
fchikwekwe Nov 14, 2023
f387225
Merge branch 'main' into feat/hny-marker-exporter
fchikwekwe Nov 14, 2023
c2f5cae
fix: update config internal
fchikwekwe Nov 14, 2023
dccbdea
fix: run make gotidy
fchikwekwe Nov 14, 2023
f7df24d
fix: add api key to header
fchikwekwe Nov 14, 2023
f37b593
test: add headers to log tests
fchikwekwe Nov 14, 2023
02839ca
Merge branch 'main' into feat/hny-marker-exporter
fchikwekwe Nov 14, 2023
4fdd457
fix: sort imports
fchikwekwe Nov 14, 2023
da47830
Merge branch 'feat/hny-marker-exporter' of https://github.com/fchikwe…
fchikwekwe Nov 14, 2023
3c63558
fix: use comparable strings in lgo test
fchikwekwe Nov 14, 2023
1cdf013
fix: remove whitespace
fchikwekwe Nov 14, 2023
2c336c5
Merge branch 'main' into feat/hny-marker-exporter
fchikwekwe Nov 14, 2023
0d1a09a
doc: added better descriptions to README
fchikwekwe Nov 14, 2023
9072850
Update exporter/honeycombmarkerexporter/README.md
TylerHelmuth Nov 14, 2023
c0f500b
Merge branch 'main' into feat/hny-marker-exporter
TylerHelmuth Nov 15, 2023
d540f49
Apply suggestions from code review
TylerHelmuth Nov 15, 2023
8dabee7
Apply suggestions from code review
TylerHelmuth Nov 15, 2023
1c99e46
Merge branch 'main' into feat/hny-marker-exporter
TylerHelmuth Nov 15, 2023
a8258cc
Update cmd/otelcontribcol/builder-config.yaml
TylerHelmuth Nov 15, 2023
27cc3ad
Merge branch 'main' into feat/hny-marker-exporter
TylerHelmuth Nov 15, 2023
af666ee
Merge branch 'main' into feat/hny-marker-exporter
TylerHelmuth Nov 16, 2023
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
11 changes: 1 addition & 10 deletions exporter/honeycombmarkerexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ The following configuration options are supported:
* `api_key` (Required): This is the API key (also called Write Key) for your Honeycomb account.
* `api_url` (Required): You can set the hostname to send marker data to.
* `markers` (Required): This specifies the exact configuration to create an event marker.
* `type`: Specifies the marker type. Markers with the same type will appear in the same color in Honeycomb. MarkerType or MarkerColor should be set.
* `color`: Specifies the marker color. Will only be used if MarkerType is not set.
* `type`: Specifies the marker type. Markers with the same type will appear in the same color in Honeycomb.
* `messagefield`: This is the attribute that will be used as the message. If necessary the value will be converted to a string.
* `urlfield`: This is the attribute that will be used as the url. If necessary the value will be converted to a string.
* `rules`: This is a list of OTTL rules that determine when to create an event marker.
Expand All @@ -31,12 +30,4 @@ exporters:
- IsMatch(attributes["test"], ".*")
- logconditions:
- body == "test"
- color: "green",
messagefield: "another test message",
urlfield: "https://api.testhost.io",
rules:
- resourceconditions:
- IsMatch(attributes["test"], ".*")
- logconditions:
- body == "test"
```
47 changes: 27 additions & 20 deletions exporter/honeycombmarkerexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ package honeycombmarkerexporter // import "github.com/open-telemetry/opentelemet

import (
"fmt"
"go.opentelemetry.io/collector/exporter/exporterhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/expr"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterottl"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllog"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterottl"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
)

// Config defines configuration for the Honeycomb Marker exporter.
Expand All @@ -24,33 +28,37 @@ type Config struct {

// Markers is the list of markers to create
Markers []Marker `mapstructure:"markers"`

confighttp.HTTPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
exporterhelper.QueueSettings `mapstructure:"sending_queue"`
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
}

type Marker struct {
// Type defines the type of Marker. Markers with the same type appear in Honeycomb with the same color
// Type defines the type of Marker.
Type string `mapstructure:"type"`

// Color is the color of the Marker. Will only be used if the Type does not already exist.
Color string `mapstructure:"color"`

// MessageField is the attribute that will be used as the message.
// MessageKey is the attribute that will be used as the message.
// If necessary the value will be converted to a string.
MessageField string `mapstructure:"message_field"`
MessageKey string `mapstructure:"message_key"`

// URLField is the attribute that will be used as the url.
// URLKey is the attribute that will be used as the url.
// If necessary the value will be converted to a string.
URLField string `mapstructure:"url_field"`
URLKey string `mapstructure:"url_key"`

// Rules are the OTTL rules that determine when a piece of telemetry should be turned into a Marker
Rules Rules `mapstructure:"rules"`

// DatasetSlug is the endpoint that specifies the Honeycomb environment
DatasetSlug string `mapstructure:"datasetslug"`
}

type Rules struct {
// ResourceConditions is the list of ottlresource conditions that determine a match
ResourceConditions []string `mapstructure:"resource_conditions"`

// LogConditions is the list of ottllog conditions that determine a match
LogConditions []string `mapstructure:"log_conditions"`

//
logBoolExpr expr.BoolExpr[ottllog.TransformContext]
}

var defaultCfg = createDefaultConfig().(*Config)
TylerHelmuth marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -66,16 +74,15 @@ func (cfg *Config) Validate() error {

if len(cfg.Markers) != 0 {
for _, m := range cfg.Markers {
if len(m.Rules.ResourceConditions) == 0 && len(m.Rules.LogConditions) == 0 {
return fmt.Errorf("no rules supplied for Marker %v", m)
if m.Type == "" {
return fmt.Errorf("marker must have a type #{m}")
}

_, err := filterottl.NewBoolExprForResource(m.Rules.ResourceConditions, filterottl.StandardResourceFuncs(), ottl.PropagateError, component.TelemetrySettings{Logger: zap.NewNop()})
if err != nil {
return err
if len(m.Rules.LogConditions) == 0 {
return fmt.Errorf("no rules supplied for Marker %v", m)
}

_, err = filterottl.NewBoolExprForLog(m.Rules.LogConditions, filterottl.StandardLogFuncs(), ottl.PropagateError, component.TelemetrySettings{Logger: zap.NewNop()})
_, err := filterottl.NewBoolExprForLog(m.Rules.LogConditions, filterottl.StandardLogFuncs(), ottl.PropagateError, component.TelemetrySettings{Logger: zap.NewNop()})
if err != nil {
return err
}
Expand Down
38 changes: 8 additions & 30 deletions exporter/honeycombmarkerexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package honeycombmarkerexporter

import (
"go.opentelemetry.io/collector/exporter/exporterhelper"
fchikwekwe marked this conversation as resolved.
Show resolved Hide resolved
"path/filepath"
"testing"

Expand All @@ -28,39 +29,16 @@ func TestLoadConfig(t *testing.T) {
{
id: component.NewIDWithName("honeycomb", ""),
expected: &Config{
APIKey: "test-apikey",
APIURL: "https://api.testhost.io",
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
APIKey: "test-apikey",
APIURL: "https://api.testhost.io",
Markers: []Marker{
{
Type: "fooType",
MessageField: "test message",
URLField: "https://api.testhost.io",
Type: "fooType",
MessageKey: "test message",
URLKey: "https://api.testhost.io",
Rules: Rules{
ResourceConditions: []string{
`IsMatch(attributes["test"], ".*")`,
},
LogConditions: []string{
`body == "test"`,
},
},
},
},
},
},
{
id: component.NewIDWithName("honeycomb", "color_no_type"),
expected: &Config{
APIKey: "test-apikey",
APIURL: "https://api.testhost.io",
Markers: []Marker{
{
Color: "green",
MessageField: "test message",
URLField: "https://api.testhost.io",
Rules: Rules{
ResourceConditions: []string{
`IsMatch(attributes["test"], ".*")`,
},
LogConditions: []string{
`body == "test"`,
},
Expand Down
12 changes: 9 additions & 3 deletions exporter/honeycombmarkerexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package honeycombmarkerexporter // import "github.com/open-telemetry/opentelemet

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -36,12 +35,19 @@ func createLogsExporter(
) (exporter.Logs, error) {
cf := cfg.(*Config)

exporter := newLogsExporter(set.Logger, cf)
logsExp, err := newHoneycombLogsExporter(set.TelemetrySettings, cf)
if err != nil {
return nil, err
}

return exporterhelper.NewLogsExporter(
ctx,
set,
cfg,
exporter.exportLogs,
logsExp.exportMarkers,
TylerHelmuth marked this conversation as resolved.
Show resolved Hide resolved
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
exporterhelper.WithRetry(cf.RetrySettings),
exporterhelper.WithQueue(cf.QueueSettings),
exporterhelper.WithStart(logsExp.start),
)
}
14 changes: 14 additions & 0 deletions exporter/honeycombmarkerexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.87.0
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/collector/component v0.87.1-0.20231017160804-ec0725874313
go.opentelemetry.io/collector/config/confighttp v0.87.0
go.opentelemetry.io/collector/config/configopaque v0.87.1-0.20231017160804-ec0725874313
go.opentelemetry.io/collector/confmap v0.87.1-0.20231017160804-ec0725874313
go.opentelemetry.io/collector/exporter v0.87.1-0.20231017160804-ec0725874313
Expand All @@ -18,13 +19,19 @@ require (
github.com/alecthomas/participle/v2 v2.1.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.1 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.0.1 // indirect
Expand All @@ -35,12 +42,19 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.87.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/cors v1.10.1 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/collector v0.87.1-0.20231017160804-ec0725874313 // indirect
go.opentelemetry.io/collector/config/configauth v0.87.0 // indirect
go.opentelemetry.io/collector/config/configcompression v0.87.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.87.1-0.20231017160804-ec0725874313 // indirect
go.opentelemetry.io/collector/config/configtls v0.87.0 // indirect
go.opentelemetry.io/collector/config/internal v0.87.0 // indirect
go.opentelemetry.io/collector/consumer v0.87.1-0.20231017160804-ec0725874313 // indirect
go.opentelemetry.io/collector/extension v0.87.1-0.20231017160804-ec0725874313 // indirect
go.opentelemetry.io/collector/extension/auth v0.87.0 // indirect
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0016.0.20231017160804-ec0725874313 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
Expand Down
28 changes: 28 additions & 0 deletions exporter/honeycombmarkerexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading