Skip to content

Commit

Permalink
Split PR of easy review
Browse files Browse the repository at this point in the history
  • Loading branch information
AkhigbeEromo committed Jan 14, 2025
1 parent e35b860 commit 8cb4584
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 360 deletions.
24 changes: 12 additions & 12 deletions exporter/sematextexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
| Status | |
| ------------- |-----------|
| Stability | [development]: metrics, logs |
| Distributions | [contrib] |
| Distributions | [] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aexporter%2Fsematext%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aexporter%2Fsematext) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aexporter%2Fsematext%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aexporter%2Fsematext) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@AkhigbeEromo](https://www.github.com/AkhigbeEromo), [@boratanrikulu](https://www.github.com/boratanrikulu), [@akshatagarwl](https://www.github.com/akshatagarwl) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@AkhigbeEromo](https://www.github.com/AkhigbeEromo) |

[development]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#development
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
<!-- end autogenerated section -->

This exporter supports sending metrics to [Sematext Cloud](https://sematext.com/) in Influx line protocol format and logs using the Bulk Index Api format.
Expand All @@ -20,20 +19,21 @@ The following configuration options are supported:
* `region` Region specifies the Sematext region the user is operating in; must be one of:
* `US`
* `EU`
* `retry_on_failure` [details here](https://github.com/open-telemetry/opentelemetry-collector/blob/v0.25.0/exporter/exporterhelper/README.md#configuration)
* `enabled` (default = true)
* `initial_interval` (default = 5s) Time to wait after the first failure before retrying
* `max_interval` (default = 30s) Upper bound on backoff interval
* `max_elapsed_time` (default = 120s) Maximum amount of time (including retries) spent trying to send a request/batch
* `metrics.app_token` specifies the token of the Sematext Monitoring App to which metrics data will be sent. It must be a valid UUID string in the format `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`. For example: `2046e37c-4fac-45f6-831d-922d43fde759`.
* `logs.app_token` specifies the token of the Sematext Logs App to which logs data will be sent. It must be a valid UUID string in the format `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`. For example: `9604e37c-49ac-49f6-831d-922d43fde759`.
* `payload_max_lines` (default = 1_000) Maximum number of lines allowed per HTTP POST request
* `payload_max_bytes` (default = 300_000) Maximum number of bytes allowed per HTTP POST request
* `metrics_schema` (default = telegraf-prometheus-v2) The chosen metrics schema to write
* `sending_queue` [details here](https://github.com/open-telemetry/opentelemetry-collector/blob/v0.25.0/exporter/exporterhelper/README.md#configuration)
* `metrics.payload_max_lines` (default = 1_000) Maximum number of lines allowed per HTTP POST request
* `metrics.payload_max_bytes` (default = 300_000) Maximum number of bytes allowed per HTTP POST request
* `metrics.metrics_schema` (default = telegraf-prometheus-v2) The chosen metrics schema to write
* `metrics.sending_queue` [details here](https://github.com/open-telemetry/opentelemetry-collector/blob/v0.25.0/exporter/exporterhelper/README.md#configuration)
* `enabled` (default = true)
* `num_consumers` (default = 10) The number of consumers from the queue
* `queue_size` (default = 1000) Maximum number of batches allowed in queue at a given time
* `retry_on_failure` [details here](https://github.com/open-telemetry/opentelemetry-collector/blob/v0.25.0/exporter/exporterhelper/README.md#configuration)
* `enabled` (default = true)
* `initial_interval` (default = 5s) Time to wait after the first failure before retrying
* `max_interval` (default = 30s) Upper bound on backoff interval
* `max_elapsed_time` (default = 120s) Maximum amount of time (including retries) spent trying to send a request/batch


The full list of settings exposed for this exporter are documented in [config.go](config.go).

Expand Down
81 changes: 1 addition & 80 deletions exporter/sematextexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,4 @@

package sematextexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sematextexporter"

import (
"fmt"
"regexp"
"strings"

"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter/exporterhelper"
)

const (
euRegion = "eu"
usRegion = "us"
euMetricsEndpoint = "https://spm-receiver.eu.sematext.com"
euLogsEndpoint = "https://logsene-receiver.eu.sematext.com"
usMetricsEndpoint = "https://spm-receiver.sematext.com"
usLogsEndpoint = "https://logsene-receiver.sematext.com"
)

type Config struct {
confighttp.ClientConfig `mapstructure:",squash"`
configretry.BackOffConfig `mapstructure:"retry_on_failure"`
// Region specifies the Sematext region the user is operating in
// Options:
// - EU
// - US
Region string `mapstructure:"region"`
// MetricsConfig defines the configuration specific to metrics
MetricsConfig `mapstructure:"metrics"`
// LogsConfig defines the configuration specific to logs
LogsConfig `mapstructure:"logs"`
}

type MetricsConfig struct {
// App token is the token of Sematext Monitoring App to which you want to send the metrics.
AppToken string `mapstructure:"app_token"`
// MetricsEndpoint specifies the endpoint for receiving metrics in Sematext
MetricsEndpoint string `mapstructure:"metrics_endpoint"`
QueueSettings exporterhelper.QueueConfig `mapstructure:"sending_queue"`
// MetricsSchema indicates the metrics schema to emit to line protocol.
// Default: telegraf-prometheus-v2
MetricsSchema string `mapstructure:"metrics_schema"`
// PayloadMaxLines is the maximum number of line protocol lines to POST in a single request.
PayloadMaxLines int `mapstructure:"payload_max_lines"`
// PayloadMaxBytes is the maximum number of line protocol bytes to POST in a single request.
PayloadMaxBytes int `mapstructure:"payload_max_bytes"`
}
type LogsConfig struct {
// App token is the token of Sematext Logs App to which you want to send the logs.
AppToken string `mapstructure:"app_token"`
// LogsEndpoint specifies the endpoint for receiving logs in Sematext
LogsEndpoint string `mapstructure:"logs_endpoint"`
}

// Validate checks for invalid or missing entries in the configuration.
func (cfg *Config) Validate() error {
if strings.ToLower(cfg.Region) != euRegion && strings.ToLower(cfg.Region) != usRegion {
return fmt.Errorf("invalid region: %s. please use either 'EU' or 'US'", cfg.Region)
}
if !isValidUUID(cfg.MetricsConfig.AppToken) {
return fmt.Errorf("invalid metrics app_token: %s. app_token is not a valid UUID", cfg.MetricsConfig.AppToken)
}
if !isValidUUID(cfg.LogsConfig.AppToken) {
return fmt.Errorf("invalid logs app_token: %s. app_token is not a valid UUID", cfg.LogsConfig.AppToken)
}
if strings.ToLower(cfg.Region) == euRegion {
cfg.MetricsEndpoint = euMetricsEndpoint
cfg.LogsEndpoint = euLogsEndpoint
}
if strings.ToLower(cfg.Region) == usRegion {
cfg.MetricsEndpoint = usMetricsEndpoint
cfg.LogsEndpoint = usLogsEndpoint
}

return nil
}
func isValidUUID(uuid string) bool {
const uuidPattern = `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`
return regexp.MustCompile(uuidPattern).MatchString(strings.ToLower(uuid))
}
type Config struct{}
183 changes: 0 additions & 183 deletions exporter/sematextexporter/config_test.go

This file was deleted.

32 changes: 1 addition & 31 deletions exporter/sematextexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@ package sematextexporter // import "github.com/open-telemetry/opentelemetry-coll

import (
"context"
"time"

"github.com/google/uuid"
"github.com/influxdata/influxdb-observability/common"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/pdata/plog"
Expand All @@ -23,9 +17,6 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sematextexporter/internal/metadata"
)

var metricsAppToken = uuid.NewString()
var logsAppToken = uuid.NewString()

// NewFactory creates a factory for the Sematext metrics exporter.
func NewFactory() exporter.Factory {
return exporter.NewFactory(
Expand All @@ -37,28 +28,7 @@ func NewFactory() exporter.Factory {
}

func createDefaultConfig() component.Config {
cfg := &Config{
ClientConfig: confighttp.ClientConfig{
Timeout: 5 * time.Second,
Headers: map[string]configopaque.String{
"User-Agent": "OpenTelemetry -> Sematext",
},
},
MetricsConfig: MetricsConfig{
MetricsEndpoint: usMetricsEndpoint,
MetricsSchema: common.MetricsSchemaTelegrafPrometheusV2.String(),
AppToken: metricsAppToken,
QueueSettings: exporterhelper.NewDefaultQueueConfig(),
PayloadMaxLines: 1_000,
PayloadMaxBytes: 300_000,
},
LogsConfig: LogsConfig{
LogsEndpoint: usLogsEndpoint,
AppToken: logsAppToken,
},
BackOffConfig: configretry.NewDefaultBackOffConfig(),
Region: usRegion,
}
cfg := &Config{}
return cfg
}

Expand Down
Loading

0 comments on commit 8cb4584

Please sign in to comment.