Skip to content

Commit

Permalink
rename variables and update description
Browse files Browse the repository at this point in the history
  • Loading branch information
splunkericl committed Apr 18, 2023
1 parent 21919d6 commit d6b2071
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 40 deletions.
4 changes: 2 additions & 2 deletions exporter/splunkhecexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ The following configuration options can also be configured:
- `otel_to_hec_fields/severity_text` (default = `otel.log.severity.text`): Specifies the name of the field to map the severity text field of log events.
- `otel_to_hec_fields/severity_number` (default = `otel.log.severity.number`): Specifies the name of the field to map the severity number field of log events.
- `otel_to_hec_fields/name` (default = `"otel.log.name`): Specifies the name of the field to map the name field of log events.
- `hec_heartbeat/interval` (no default): Specifies the interval of sending hec heartbeat to the destination. If not specified, heartbeat is not enabled.
- `heartbeat/interval` (no default): Specifies the interval of sending hec heartbeat to the destination. If not specified, heartbeat is not enabled.
- `telemetry/enabled` (default: false): Specifies whether to enable telemetry inside splunk hec exporter.
- `telemetry/override_metrics_names` (default: empty map): Specifies the metrics name to overrides in splunk hec exporter.
- `telemetry/extra_attributes` (default: empty map): Specifies the extra metrics attributes in splunk hec exporter.
Expand Down Expand Up @@ -119,7 +119,7 @@ exporters:
splunk_app_name: "OpenTelemetry-Collector Splunk Exporter"
# Application version is used to track telemetry information for Splunk App's using HEC by App version.
splunk_app_version: "v0.0.1"
hec_heartbeat:
heartbeat:
interval: 30s
telemetry:
enabled: true
Expand Down
2 changes: 1 addition & 1 deletion exporter/splunkhecexporter/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ func TestAllowedLogDataTypes(t *testing.T) {

func Test_heartbeat_success(t *testing.T) {
config := NewFactory().CreateDefaultConfig().(*Config)
config.HecHeartbeat = HecHeartbeat{
config.Heartbeat = HecHeartbeat{
Interval: 10 * time.Millisecond,
}

Expand Down
8 changes: 4 additions & 4 deletions exporter/splunkhecexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ type Config struct {
// UseMultiMetricFormat combines metric events to save space during ingestion.
UseMultiMetricFormat bool `mapstructure:"use_multi_metric_format"`

// HecHeartbeat is the configuration to enable heartbeat
HecHeartbeat HecHeartbeat `mapstructure:"hec_heartbeat"`
// Heartbeat is the configuration to enable heartbeat
Heartbeat HecHeartbeat `mapstructure:"heartbeat"`

// HecTelemetry is the configuration for splunk hec exporter telemetry
HecTelemetry HecTelemetry `mapstructure:"telemetry"`
// Telemetry is the configuration for splunk hec exporter telemetry
Telemetry HecTelemetry `mapstructure:"telemetry"`
}

func (cfg *Config) getURL() (out *url.URL, err error) {
Expand Down
4 changes: 2 additions & 2 deletions exporter/splunkhecexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ func TestLoadConfig(t *testing.T) {
},
HealthPath: "/services/collector/health",
HecHealthCheckEnabled: false,
HecHeartbeat: HecHeartbeat{
Heartbeat: HecHeartbeat{
Interval: 30 * time.Second,
},
HecTelemetry: HecTelemetry{
Telemetry: HecTelemetry{
Enabled: true,
OverrideMetricsNames: map[string]string{
"otelcol_exporter_splunkhec_heartbeat_sent": "app_heartbeats_success_total",
Expand Down
2 changes: 1 addition & 1 deletion exporter/splunkhecexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func createDefaultConfig() component.Config {
HealthPath: splunk.DefaultHealthPath,
HecHealthCheckEnabled: false,
ExportRaw: false,
HecTelemetry: HecTelemetry{
Telemetry: HecTelemetry{
Enabled: false,
OverrideMetricsNames: map[string]string{},
ExtraAttributes: map[string]string{},
Expand Down
1 change: 0 additions & 1 deletion exporter/splunkhecexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func TestCreateMetricsExporter(t *testing.T) {
params := exportertest.NewNopCreateSettings()
_, err := createMetricsExporter(context.Background(), params, cfg)
assert.NoError(t, err)
assert.NoError(t, err)
}

func TestCreateTracesExporter(t *testing.T) {
Expand Down
50 changes: 25 additions & 25 deletions exporter/splunkhecexporter/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (
)

const (
metricsPrefix = "otelcol_exporter_splunkhec_heartbeat"
defaultHBSentMetricsName = metricsPrefix + "_sent"
defaultHBFailedMetricsName = metricsPrefix + "_failed"
metricsPrefix = "otelcol_exporter_splunkhec_"
defaultHBSentMetricsName = metricsPrefix + "heartbeat_sent"
defaultHBFailedMetricsName = metricsPrefix + "heartbeat_failed"
)

type heartbeater struct {
Expand All @@ -55,16 +55,16 @@ func getMetricsName(overrides map[string]string, metricName string) string {
}

func newHeartbeater(config *Config, pushLogFn func(ctx context.Context, ld plog.Logs) error) *heartbeater {
interval := config.HecHeartbeat.Interval
interval := config.Heartbeat.Interval
if interval == 0 {
return nil
}

var heartbeatSentTotal, heartbeatFailedTotal *stats.Int64Measure
var heartbeatSent, heartbeatFailed *stats.Int64Measure
var tagMutators []tag.Mutator
if config.HecTelemetry.Enabled {
overrides := config.HecTelemetry.OverrideMetricsNames
extraAttributes := config.HecTelemetry.ExtraAttributes
if config.Telemetry.Enabled {
overrides := config.Telemetry.OverrideMetricsNames
extraAttributes := config.Telemetry.ExtraAttributes
var tags []tag.Key
tagMutators = []tag.Mutator{}
for key, val := range extraAttributes {
Expand All @@ -73,33 +73,33 @@ func newHeartbeater(config *Config, pushLogFn func(ctx context.Context, ld plog.
tagMutators = append(tagMutators, tag.Insert(newTag, val))
}

heartbeatSentTotal = stats.Int64(
heartbeatSent = stats.Int64(
getMetricsName(overrides, defaultHBSentMetricsName),
"number of heartbeats made to the destination",
"number of heartbeats sent",
stats.UnitDimensionless)

heartbeatSuccessTotalView := &view.View{
Name: heartbeatSentTotal.Name(),
Description: heartbeatSentTotal.Description(),
heartbeatSentView := &view.View{
Name: heartbeatSent.Name(),
Description: heartbeatSent.Description(),
TagKeys: tags,
Measure: heartbeatSentTotal,
Measure: heartbeatSent,
Aggregation: view.Sum(),
}

heartbeatFailedTotal = stats.Int64(
heartbeatFailed = stats.Int64(
getMetricsName(overrides, defaultHBFailedMetricsName),
"number of heartbeats made to destination that failed",
"number of heartbeats failed",
stats.UnitDimensionless)

heartbeatErrorTotalView := &view.View{
Name: heartbeatFailedTotal.Name(),
Description: heartbeatFailedTotal.Description(),
heartbeatFailedView := &view.View{
Name: heartbeatFailed.Name(),
Description: heartbeatFailed.Description(),
TagKeys: tags,
Measure: heartbeatFailedTotal,
Measure: heartbeatFailed,
Aggregation: view.Sum(),
}

if err := view.Register(heartbeatSuccessTotalView, heartbeatErrorTotalView); err != nil {
if err := view.Register(heartbeatSentView, heartbeatFailedView); err != nil {
return nil
}
}
Expand All @@ -108,8 +108,8 @@ func newHeartbeater(config *Config, pushLogFn func(ctx context.Context, ld plog.
config: config,
pushLogFn: pushLogFn,
hbDoneChan: make(chan struct{}),
heartbeatSuccessTotal: heartbeatSentTotal,
heartbeatErrorTotal: heartbeatFailedTotal,
heartbeatSuccessTotal: heartbeatSent,
heartbeatErrorTotal: heartbeatFailed,
tagMutators: tagMutators,
}
}
Expand All @@ -119,7 +119,7 @@ func (h *heartbeater) shutdown() {
}

func (h *heartbeater) initHeartbeat(buildInfo component.BuildInfo) {
interval := h.config.HecHeartbeat.Interval
interval := h.config.Heartbeat.Interval
if interval == 0 {
return
}
Expand All @@ -143,7 +143,7 @@ func (h *heartbeater) initHeartbeat(buildInfo component.BuildInfo) {

// there is only use case for open census metrics recording for now. Extend to use open telemetry in the future.
func (h *heartbeater) observe(err error) {
if !h.config.HecTelemetry.Enabled {
if !h.config.Telemetry.Enabled {
return
}

Expand Down
6 changes: 3 additions & 3 deletions exporter/splunkhecexporter/heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ const (

func createTestConfig(metricsOverrides map[string]string, enableMetrics bool) *Config {
config := NewFactory().CreateDefaultConfig().(*Config)
config.HecHeartbeat = HecHeartbeat{
config.Heartbeat = HecHeartbeat{
Interval: 10 * time.Millisecond,
}
config.HecTelemetry = HecTelemetry{
config.Telemetry = HecTelemetry{
Enabled: enableMetrics,
OverrideMetricsNames: metricsOverrides,
ExtraAttributes: map[string]string{
Expand Down Expand Up @@ -93,7 +93,7 @@ func resetMetrics(metricsNames ...string) {

func Test_newHeartbeater_disabled(t *testing.T) {
config := createTestConfig(map[string]string{}, false)
config.HecHeartbeat.Interval = 0
config.Heartbeat.Interval = 0
hb := newHeartbeater(config, func(ctx context.Context, ld plog.Logs) error {
return nil
})
Expand Down
2 changes: 1 addition & 1 deletion exporter/splunkhecexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ splunk_hec/allsettings:
otel_to_hec_fields:
severity_text: "myseverityfield"
severity_number: "myseveritynumfield"
hec_heartbeat:
heartbeat:
interval: 30s
telemetry:
enabled: true
Expand Down

0 comments on commit d6b2071

Please sign in to comment.