chore(inputs.riemann_legacy)!: Remove deprecated plugin (#14867)
This commit is contained in:
parent
b836bc17a9
commit
bd52eb1cfb
|
|
@ -1,5 +0,0 @@
|
||||||
//go:build !custom || outputs || outputs.riemann_legacy
|
|
||||||
|
|
||||||
package all
|
|
||||||
|
|
||||||
import _ "github.com/influxdata/telegraf/plugins/outputs/riemann_legacy" // register plugin
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
# Riemann Legacy Output Plugin
|
|
||||||
|
|
||||||
This is a deprecated plugin. Please use the [Riemann Output Plugin][new]
|
|
||||||
instead.
|
|
||||||
|
|
||||||
[new]: ../riemann/README.md
|
|
||||||
|
|
||||||
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
|
|
||||||
|
|
||||||
In addition to the plugin-specific configuration settings, plugins support
|
|
||||||
additional global and plugin configuration settings. These settings are used to
|
|
||||||
modify metrics, tags, and field or create aliases and configure ordering, etc.
|
|
||||||
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
|
||||||
|
|
||||||
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
```toml @sample.conf
|
|
||||||
# Configuration for the Riemann server to send metrics to
|
|
||||||
[[outputs.riemann_legacy]]
|
|
||||||
## URL of server
|
|
||||||
url = "localhost:5555"
|
|
||||||
## transport protocol to use either tcp or udp
|
|
||||||
transport = "tcp"
|
|
||||||
## separator to use between input name and field name in Riemann service name
|
|
||||||
separator = " "
|
|
||||||
```
|
|
||||||
|
|
@ -1,147 +0,0 @@
|
||||||
//go:generate ../../../tools/readme_config_includer/generator
|
|
||||||
package riemann_legacy
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "embed"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/amir/raidman"
|
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
|
||||||
"github.com/influxdata/telegraf/plugins/outputs"
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:embed sample.conf
|
|
||||||
var sampleConfig string
|
|
||||||
|
|
||||||
const deprecationMsg = "Error: this Riemann output plugin will be deprecated in a future release, " +
|
|
||||||
"see https://github.com/influxdata/telegraf/issues/1878 for more details & discussion."
|
|
||||||
|
|
||||||
type Riemann struct {
|
|
||||||
URL string `toml:"url"`
|
|
||||||
Transport string `toml:"transport"`
|
|
||||||
Separator string `toml:"separator"`
|
|
||||||
Log telegraf.Logger `toml:"-"`
|
|
||||||
|
|
||||||
client *raidman.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*Riemann) SampleConfig() string {
|
|
||||||
return sampleConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Riemann) Connect() error {
|
|
||||||
r.Log.Error(deprecationMsg)
|
|
||||||
c, err := raidman.Dial(r.Transport, r.URL)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
r.client = nil
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
r.client = c
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Riemann) Close() error {
|
|
||||||
if r.client == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
err := r.client.Close()
|
|
||||||
r.client = nil
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Riemann) Write(metrics []telegraf.Metric) error {
|
|
||||||
r.Log.Error(deprecationMsg)
|
|
||||||
if len(metrics) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.client == nil {
|
|
||||||
err := r.Connect()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to (re)connect to Riemann: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var events []*raidman.Event
|
|
||||||
for _, p := range metrics {
|
|
||||||
evs := buildEvents(p, r.Separator)
|
|
||||||
events = append(events, evs...)
|
|
||||||
}
|
|
||||||
|
|
||||||
var senderr = r.client.SendMulti(events)
|
|
||||||
if senderr != nil {
|
|
||||||
r.Close()
|
|
||||||
return fmt.Errorf("failed to send riemann message (will try to reconnect): %w", senderr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func buildEvents(p telegraf.Metric, s string) []*raidman.Event {
|
|
||||||
events := []*raidman.Event{}
|
|
||||||
for fieldName, value := range p.Fields() {
|
|
||||||
host, ok := p.Tags()["host"]
|
|
||||||
if !ok {
|
|
||||||
hostname, err := os.Hostname()
|
|
||||||
if err != nil {
|
|
||||||
host = "unknown"
|
|
||||||
} else {
|
|
||||||
host = hostname
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
event := &raidman.Event{
|
|
||||||
Host: host,
|
|
||||||
Service: serviceName(s, p.Name(), p.Tags(), fieldName),
|
|
||||||
}
|
|
||||||
|
|
||||||
switch value := value.(type) {
|
|
||||||
case string:
|
|
||||||
event.State = value
|
|
||||||
default:
|
|
||||||
event.Metric = value
|
|
||||||
}
|
|
||||||
|
|
||||||
events = append(events, event)
|
|
||||||
}
|
|
||||||
|
|
||||||
return events
|
|
||||||
}
|
|
||||||
|
|
||||||
func serviceName(s string, n string, t map[string]string, f string) string {
|
|
||||||
serviceStrings := []string{}
|
|
||||||
serviceStrings = append(serviceStrings, n)
|
|
||||||
|
|
||||||
// we'll skip the 'host' tag
|
|
||||||
tagStrings := []string{}
|
|
||||||
tagNames := []string{}
|
|
||||||
|
|
||||||
for tagName := range t {
|
|
||||||
tagNames = append(tagNames, tagName)
|
|
||||||
}
|
|
||||||
sort.Strings(tagNames)
|
|
||||||
|
|
||||||
for _, tagName := range tagNames {
|
|
||||||
if tagName != "host" {
|
|
||||||
tagStrings = append(tagStrings, t[tagName])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var tagString = strings.Join(tagStrings, s)
|
|
||||||
if tagString != "" {
|
|
||||||
serviceStrings = append(serviceStrings, tagString)
|
|
||||||
}
|
|
||||||
serviceStrings = append(serviceStrings, f)
|
|
||||||
return strings.Join(serviceStrings, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
outputs.Add("riemann_legacy", func() telegraf.Output {
|
|
||||||
return &Riemann{}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
package riemann_legacy
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/docker/go-connections/nat"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/testcontainers/testcontainers-go/wait"
|
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestConnectAndWrite(t *testing.T) {
|
|
||||||
if testing.Short() {
|
|
||||||
t.Skip("Skipping integration test in short mode")
|
|
||||||
}
|
|
||||||
|
|
||||||
servicePort := "5555"
|
|
||||||
container := testutil.Container{
|
|
||||||
Image: "rlister/riemann",
|
|
||||||
ExposedPorts: []string{servicePort},
|
|
||||||
WaitingFor: wait.ForAll(
|
|
||||||
wait.ForLog("Hyperspace core online"),
|
|
||||||
wait.ForListeningPort(nat.Port(servicePort)),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
err := container.Start()
|
|
||||||
require.NoError(t, err, "failed to start container")
|
|
||||||
defer container.Terminate()
|
|
||||||
|
|
||||||
url := fmt.Sprintf("%s:%s", container.Address, container.Ports[servicePort])
|
|
||||||
|
|
||||||
r := &Riemann{
|
|
||||||
URL: url,
|
|
||||||
Transport: "tcp",
|
|
||||||
Log: testutil.Logger{},
|
|
||||||
}
|
|
||||||
|
|
||||||
err = r.Connect()
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
err = r.Write(testutil.MockMetrics())
|
|
||||||
require.NoError(t, err)
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
# Configuration for the Riemann server to send metrics to
|
|
||||||
[[outputs.riemann_legacy]]
|
|
||||||
## URL of server
|
|
||||||
url = "localhost:5555"
|
|
||||||
## transport protocol to use either tcp or udp
|
|
||||||
transport = "tcp"
|
|
||||||
## separator to use between input name and field name in Riemann service name
|
|
||||||
separator = " "
|
|
||||||
Loading…
Reference in New Issue