Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
247
migrations/inputs_cassandra/migration.go
Normal file
247
migrations/inputs_cassandra/migration.go
Normal file
|
@ -0,0 +1,247 @@
|
|||
package inputs_cassandra
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/influxdata/toml"
|
||||
"github.com/influxdata/toml/ast"
|
||||
|
||||
"github.com/influxdata/telegraf/migrations"
|
||||
"github.com/influxdata/telegraf/migrations/common"
|
||||
)
|
||||
|
||||
// Define "old" data structure
|
||||
type cassandra struct {
|
||||
Context string `toml:"context"`
|
||||
Servers []string `toml:"servers"`
|
||||
Metrics []string `toml:"metrics"`
|
||||
common.InputOptions
|
||||
}
|
||||
|
||||
// Define "new" data structure(s)
|
||||
type metricConfig struct {
|
||||
Name string `toml:"name"`
|
||||
Mbean string `toml:"mbean"`
|
||||
FieldPrefix *string `toml:"field_prefix,omitempty"`
|
||||
TagKeys []string `toml:"tag_keys,omitempty"`
|
||||
}
|
||||
|
||||
type jolokiaAgent struct {
|
||||
URLs []string `toml:"urls"`
|
||||
Username string `toml:"username,omitempty"`
|
||||
Password string `toml:"password,omitempty"`
|
||||
Metrics []metricConfig `toml:"metric"`
|
||||
|
||||
// Common options
|
||||
Interval string `toml:"interval,omitempty"`
|
||||
Precision string `toml:"precision,omitempty"`
|
||||
CollectionJitter string `toml:"collection_jitter,omitempty"`
|
||||
CollectionOffset string `toml:"collection_offset,omitempty"`
|
||||
NamePrefix string `toml:"name_prefix,omitempty"`
|
||||
NameSuffix string `toml:"name_suffix,omitempty"`
|
||||
NameOverride string `toml:"name_override,omitempty"`
|
||||
Alias string `toml:"alias,omitempty"`
|
||||
Tags map[string]string `toml:"tags,omitempty"`
|
||||
|
||||
NamePass []string `toml:"namepass,omitempty"`
|
||||
NameDrop []string `toml:"namedrop,omitempty"`
|
||||
FieldInclude []string `toml:"fieldinclude,omitempty"`
|
||||
FieldExclude []string `toml:"fieldexclude,omitempty"`
|
||||
TagPassFilters map[string][]string `toml:"tagpass,omitempty"`
|
||||
TagDropFilters map[string][]string `toml:"tagdrop,omitempty"`
|
||||
TagExclude []string `toml:"tagexclude,omitempty"`
|
||||
TagInclude []string `toml:"taginclude,omitempty"`
|
||||
MetricPass string `toml:"metricpass,omitempty"`
|
||||
}
|
||||
|
||||
// Migration function
|
||||
func migrate(tbl *ast.Table) ([]byte, string, error) {
|
||||
// Decode the old data structure
|
||||
var old cassandra
|
||||
if err := toml.UnmarshalTable(tbl, &old); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
// Collect servers that use the same credentials
|
||||
endpoints := make(map[string]jolokiaAgent)
|
||||
for _, server := range old.Servers {
|
||||
u, err := url.Parse("http://" + server)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("invalid url %q: %w", server, err)
|
||||
}
|
||||
if u.Path != "" {
|
||||
return nil, "", fmt.Errorf("unexpected path in %q: %w", server, err)
|
||||
}
|
||||
if u.Hostname() == "" {
|
||||
u.Host = "localhost:" + u.Port()
|
||||
}
|
||||
user := u.User.Username()
|
||||
passwd, _ := u.User.Password()
|
||||
key := user + ":" + passwd
|
||||
|
||||
endpoint, found := endpoints[key]
|
||||
if !found {
|
||||
endpoint = jolokiaAgent{
|
||||
Username: user,
|
||||
Password: passwd,
|
||||
}
|
||||
endpoint.fillCommon(old.InputOptions)
|
||||
}
|
||||
u.User = nil
|
||||
endpoint.URLs = append(endpoint.URLs, u.String())
|
||||
endpoints[key] = endpoint
|
||||
}
|
||||
|
||||
// Create new-style metrics according to the old config
|
||||
var javaMetrics []metricConfig
|
||||
var cassandraMetrics []metricConfig
|
||||
for _, metric := range old.Metrics {
|
||||
bean := strings.TrimPrefix(metric, "/")
|
||||
|
||||
params := make(map[string]string)
|
||||
parts := strings.SplitN(bean, ":", 2)
|
||||
for _, p := range strings.Split(parts[1], ",") {
|
||||
x := strings.SplitN(p, "=", 2)
|
||||
params[x[0]] = x[1]
|
||||
}
|
||||
|
||||
name, found := params["type"]
|
||||
if !found {
|
||||
return nil, "", fmt.Errorf("cannot determine name for metric %q", metric)
|
||||
}
|
||||
name = strings.SplitN(name, "/", 2)[0]
|
||||
|
||||
var tagKeys []string
|
||||
var prefix *string
|
||||
for k := range params {
|
||||
switch k {
|
||||
case "name", "scope", "path", "keyspace":
|
||||
tagKeys = append(tagKeys, k)
|
||||
}
|
||||
}
|
||||
sort.Strings(tagKeys)
|
||||
for i, k := range tagKeys {
|
||||
if k == "name" {
|
||||
p := fmt.Sprintf("$%d_", i+1)
|
||||
prefix = &p
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
case strings.HasPrefix(bean, "java.lang:"):
|
||||
javaMetrics = append(javaMetrics, metricConfig{
|
||||
Name: name,
|
||||
Mbean: bean,
|
||||
TagKeys: tagKeys,
|
||||
FieldPrefix: prefix,
|
||||
})
|
||||
case strings.HasPrefix(bean, "org.apache.cassandra.metrics:"):
|
||||
cassandraMetrics = append(cassandraMetrics, metricConfig{
|
||||
Name: name,
|
||||
Mbean: bean,
|
||||
TagKeys: tagKeys,
|
||||
FieldPrefix: prefix,
|
||||
})
|
||||
default:
|
||||
return nil, "", fmt.Errorf("unknown java metric %q", metric)
|
||||
}
|
||||
}
|
||||
|
||||
// Create the corresponding metric configurations
|
||||
cfg := migrations.CreateTOMLStruct("inputs", "jolokia2_agent")
|
||||
for _, endpoint := range endpoints {
|
||||
if len(javaMetrics) > 0 {
|
||||
plugin := jolokiaAgent{
|
||||
URLs: endpoint.URLs,
|
||||
Username: endpoint.Username,
|
||||
Password: endpoint.Password,
|
||||
Metrics: javaMetrics,
|
||||
}
|
||||
plugin.fillCommon(old.InputOptions)
|
||||
plugin.NamePrefix = "java"
|
||||
cfg.Add("inputs", "jolokia2_agent", plugin)
|
||||
}
|
||||
if len(cassandraMetrics) > 0 {
|
||||
plugin := jolokiaAgent{
|
||||
URLs: endpoint.URLs,
|
||||
Username: endpoint.Username,
|
||||
Password: endpoint.Password,
|
||||
Metrics: cassandraMetrics,
|
||||
}
|
||||
plugin.fillCommon(old.InputOptions)
|
||||
plugin.NamePrefix = "cassandra"
|
||||
|
||||
cfg.Add("inputs", "jolokia2_agent", plugin)
|
||||
}
|
||||
}
|
||||
|
||||
// Marshal the new configuration
|
||||
buf, err := toml.Marshal(cfg)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
buf = append(buf, []byte("\n")...)
|
||||
|
||||
// Create the new content to output
|
||||
return buf, "", nil
|
||||
}
|
||||
|
||||
func (j *jolokiaAgent) fillCommon(o common.InputOptions) {
|
||||
o.Migrate()
|
||||
|
||||
j.Interval = o.Interval
|
||||
j.Precision = o.Precision
|
||||
j.CollectionJitter = o.CollectionJitter
|
||||
j.CollectionOffset = o.CollectionOffset
|
||||
j.NamePrefix = o.NamePrefix
|
||||
j.NameSuffix = o.NameSuffix
|
||||
j.NameOverride = o.NameOverride
|
||||
j.Alias = o.Alias
|
||||
if len(o.Tags) > 0 {
|
||||
j.Tags = make(map[string]string, len(o.Tags))
|
||||
for k, v := range o.Tags {
|
||||
j.Tags[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
if len(o.NamePass) > 0 {
|
||||
j.NamePass = append(j.NamePass, o.NamePass...)
|
||||
}
|
||||
if len(o.NameDrop) > 0 {
|
||||
j.NameDrop = append(j.NameDrop, o.NameDrop...)
|
||||
}
|
||||
if len(o.FieldInclude) > 0 {
|
||||
j.FieldInclude = append(j.FieldInclude, o.FieldInclude...)
|
||||
}
|
||||
if len(o.FieldExclude) > 0 {
|
||||
j.FieldExclude = append(j.FieldExclude, o.FieldExclude...)
|
||||
}
|
||||
if len(o.TagPassFilters) > 0 {
|
||||
j.TagPassFilters = make(map[string][]string, len(o.TagPassFilters))
|
||||
for k, v := range o.TagPassFilters {
|
||||
j.TagPassFilters[k] = v
|
||||
}
|
||||
}
|
||||
if len(o.TagDropFilters) > 0 {
|
||||
j.TagDropFilters = make(map[string][]string, len(o.TagDropFilters))
|
||||
for k, v := range o.TagDropFilters {
|
||||
j.TagDropFilters[k] = v
|
||||
}
|
||||
}
|
||||
if len(o.TagExclude) > 0 {
|
||||
j.TagExclude = append(j.TagExclude, o.TagExclude...)
|
||||
}
|
||||
if len(o.TagInclude) > 0 {
|
||||
j.TagInclude = append(j.TagInclude, o.TagInclude...)
|
||||
}
|
||||
j.MetricPass = o.MetricPass
|
||||
}
|
||||
|
||||
// Register the migration function for the plugin type
|
||||
func init() {
|
||||
migrations.AddPluginMigration("inputs.cassandra", migrate)
|
||||
}
|
61
migrations/inputs_cassandra/migration_test.go
Normal file
61
migrations/inputs_cassandra/migration_test.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
package inputs_cassandra_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/config"
|
||||
_ "github.com/influxdata/telegraf/migrations/inputs_cassandra" // register migration
|
||||
_ "github.com/influxdata/telegraf/plugins/inputs/jolokia2_agent" // register plugin
|
||||
)
|
||||
|
||||
func TestCases(t *testing.T) {
|
||||
// Get all directories in testdata
|
||||
folders, err := os.ReadDir("testcases")
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, f := range folders {
|
||||
// Only handle folders
|
||||
if !f.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
t.Run(f.Name(), func(t *testing.T) {
|
||||
testcasePath := filepath.Join("testcases", f.Name())
|
||||
inputFile := filepath.Join(testcasePath, "telegraf.conf")
|
||||
expectedFile := filepath.Join(testcasePath, "expected.conf")
|
||||
|
||||
// Read the expected output
|
||||
expected := config.NewConfig()
|
||||
require.NoError(t, expected.LoadConfig(expectedFile))
|
||||
require.NotEmpty(t, expected.Inputs)
|
||||
|
||||
// Read the input data
|
||||
input, remote, err := config.LoadConfigFile(inputFile)
|
||||
require.NoError(t, err)
|
||||
require.False(t, remote)
|
||||
require.NotEmpty(t, input)
|
||||
|
||||
// Migrate
|
||||
output, n, err := config.ApplyMigrations(input)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, output)
|
||||
require.GreaterOrEqual(t, n, uint64(1))
|
||||
actual := config.NewConfig()
|
||||
require.NoError(t, actual.LoadConfigData(output, config.EmptySourcePath))
|
||||
|
||||
// Test the output
|
||||
require.Len(t, actual.Inputs, len(expected.Inputs))
|
||||
actualIDs := make([]string, 0, len(expected.Inputs))
|
||||
expectedIDs := make([]string, 0, len(expected.Inputs))
|
||||
for i := range actual.Inputs {
|
||||
actualIDs = append(actualIDs, actual.Inputs[i].ID())
|
||||
expectedIDs = append(expectedIDs, expected.Inputs[i].ID())
|
||||
}
|
||||
require.ElementsMatch(t, expectedIDs, actualIDs)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
[[inputs.jolokia2_agent]]
|
||||
urls = ["http://10.10.10.1:8778"]
|
||||
username = "myuser"
|
||||
password = "mypassword"
|
||||
name_prefix = "java"
|
||||
|
||||
[[inputs.jolokia2_agent.metric]]
|
||||
name = "Memory"
|
||||
mbean = "java.lang:type=Memory/HeapMemoryUsage"
|
||||
|
||||
[inputs.jolokia2_agent.tagdrop]
|
||||
app = ["myapp"]
|
||||
location = ["e*"]
|
||||
|
||||
[[inputs.jolokia2_agent]]
|
||||
urls = ["http://10.10.10.1:8778"]
|
||||
username = "myuser"
|
||||
password = "mypassword"
|
||||
name_prefix = "cassandra"
|
||||
|
||||
[[inputs.jolokia2_agent.metric]]
|
||||
name = "Table"
|
||||
mbean = "org.apache.cassandra.metrics:type=Table,keyspace=*,scope=*,name=ReadLatency"
|
||||
field_prefix = "$2_"
|
||||
tag_keys = ["keyspace", "name", "scope"]
|
||||
|
||||
[inputs.jolokia2_agent.tagdrop]
|
||||
app = ["myapp"]
|
||||
location = ["e*"]
|
||||
|
||||
[[inputs.jolokia2_agent]]
|
||||
urls = ["http://10.10.10.2:8778", "http://localhost:8778"]
|
||||
name_prefix = "java"
|
||||
|
||||
[[inputs.jolokia2_agent.metric]]
|
||||
name = "Memory"
|
||||
mbean = "java.lang:type=Memory/HeapMemoryUsage"
|
||||
|
||||
[inputs.jolokia2_agent.tagdrop]
|
||||
app = ["myapp"]
|
||||
location = ["e*"]
|
||||
|
||||
[[inputs.jolokia2_agent]]
|
||||
urls = ["http://10.10.10.2:8778", "http://localhost:8778"]
|
||||
name_prefix = "cassandra"
|
||||
|
||||
[[inputs.jolokia2_agent.metric]]
|
||||
name = "Table"
|
||||
mbean = "org.apache.cassandra.metrics:type=Table,keyspace=*,scope=*,name=ReadLatency"
|
||||
field_prefix = "$2_"
|
||||
tag_keys = ["keyspace", "name", "scope"]
|
||||
|
||||
[inputs.jolokia2_agent.tagdrop]
|
||||
app = ["myapp"]
|
||||
location = ["e*"]
|
|
@ -0,0 +1,11 @@
|
|||
[[inputs.cassandra]]
|
||||
context = "/jolokia/read"
|
||||
servers = ["myuser:mypassword@10.10.10.1:8778","10.10.10.2:8778",":8778"]
|
||||
metrics = [
|
||||
"/java.lang:type=Memory/HeapMemoryUsage",
|
||||
"/org.apache.cassandra.metrics:type=Table,keyspace=*,scope=*,name=ReadLatency"
|
||||
]
|
||||
|
||||
[inputs.cassandra.tagdrop]
|
||||
app = ["myapp"]
|
||||
location = ["e*"]
|
|
@ -0,0 +1,64 @@
|
|||
[[inputs.jolokia2_agent]]
|
||||
urls = ["http://10.10.10.1:8778"]
|
||||
username = "myuser"
|
||||
password = "mypassword"
|
||||
interval = "20s"
|
||||
name_prefix = "java"
|
||||
alias = "mycassandra"
|
||||
|
||||
[[inputs.jolokia2_agent.metric]]
|
||||
name = "Memory"
|
||||
mbean = "java.lang:type=Memory/HeapMemoryUsage"
|
||||
|
||||
[inputs.jolokia2_agent.tags]
|
||||
app = "myapp"
|
||||
location = "east"
|
||||
|
||||
[[inputs.jolokia2_agent]]
|
||||
urls = ["http://10.10.10.1:8778"]
|
||||
username = "myuser"
|
||||
password = "mypassword"
|
||||
interval = "20s"
|
||||
name_prefix = "cassandra"
|
||||
alias = "mycassandra"
|
||||
|
||||
[[inputs.jolokia2_agent.metric]]
|
||||
name = "Table"
|
||||
mbean = "org.apache.cassandra.metrics:type=Table,keyspace=*,scope=*,name=ReadLatency"
|
||||
field_prefix = "$2_"
|
||||
tag_keys = ["keyspace", "name", "scope"]
|
||||
|
||||
[inputs.jolokia2_agent.tags]
|
||||
app = "myapp"
|
||||
location = "east"
|
||||
|
||||
[[inputs.jolokia2_agent]]
|
||||
urls = ["http://10.10.10.2:8778", "http://localhost:8778"]
|
||||
interval = "20s"
|
||||
name_prefix = "java"
|
||||
alias = "mycassandra"
|
||||
|
||||
[[inputs.jolokia2_agent.metric]]
|
||||
name = "Memory"
|
||||
mbean = "java.lang:type=Memory/HeapMemoryUsage"
|
||||
|
||||
[inputs.jolokia2_agent.tags]
|
||||
app = "myapp"
|
||||
location = "east"
|
||||
|
||||
[[inputs.jolokia2_agent]]
|
||||
urls = ["http://10.10.10.2:8778", "http://localhost:8778"]
|
||||
interval = "20s"
|
||||
name_prefix = "cassandra"
|
||||
alias = "mycassandra"
|
||||
|
||||
[[inputs.jolokia2_agent.metric]]
|
||||
name = "Table"
|
||||
mbean = "org.apache.cassandra.metrics:type=Table,keyspace=*,scope=*,name=ReadLatency"
|
||||
field_prefix = "$2_"
|
||||
tag_keys = ["keyspace", "name", "scope"]
|
||||
|
||||
[inputs.jolokia2_agent.tags]
|
||||
app = "myapp"
|
||||
location = "east"
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
[[inputs.cassandra]]
|
||||
interval = "20s"
|
||||
alias = "mycassandra"
|
||||
context = "/jolokia/read"
|
||||
servers = ["myuser:mypassword@10.10.10.1:8778","10.10.10.2:8778",":8778"]
|
||||
metrics = [
|
||||
"/java.lang:type=Memory/HeapMemoryUsage",
|
||||
"/org.apache.cassandra.metrics:type=Table,keyspace=*,scope=*,name=ReadLatency"
|
||||
]
|
||||
|
||||
[inputs.cassandra.tags]
|
||||
app = "myapp"
|
||||
location = "east"
|
40
migrations/inputs_cassandra/testcases/simple/expected.conf
Normal file
40
migrations/inputs_cassandra/testcases/simple/expected.conf
Normal file
|
@ -0,0 +1,40 @@
|
|||
[[inputs.jolokia2_agent]]
|
||||
urls = ["http://10.10.10.1:8778"]
|
||||
username = "myuser"
|
||||
password = "mypassword"
|
||||
name_prefix = "java"
|
||||
|
||||
[[inputs.jolokia2_agent.metric]]
|
||||
name = "Memory"
|
||||
mbean = "java.lang:type=Memory/HeapMemoryUsage"
|
||||
|
||||
[[inputs.jolokia2_agent]]
|
||||
urls = ["http://10.10.10.1:8778"]
|
||||
username = "myuser"
|
||||
password = "mypassword"
|
||||
name_prefix = "cassandra"
|
||||
|
||||
[[inputs.jolokia2_agent.metric]]
|
||||
name = "Table"
|
||||
mbean = "org.apache.cassandra.metrics:type=Table,keyspace=*,scope=*,name=ReadLatency"
|
||||
field_prefix = "$2_"
|
||||
tag_keys = ["keyspace", "name", "scope"]
|
||||
|
||||
[[inputs.jolokia2_agent]]
|
||||
urls = ["http://10.10.10.2:8778", "http://localhost:8778"]
|
||||
name_prefix = "java"
|
||||
|
||||
[[inputs.jolokia2_agent.metric]]
|
||||
name = "Memory"
|
||||
mbean = "java.lang:type=Memory/HeapMemoryUsage"
|
||||
|
||||
[[inputs.jolokia2_agent]]
|
||||
urls = ["http://10.10.10.2:8778", "http://localhost:8778"]
|
||||
name_prefix = "cassandra"
|
||||
|
||||
[[inputs.jolokia2_agent.metric]]
|
||||
name = "Table"
|
||||
mbean = "org.apache.cassandra.metrics:type=Table,keyspace=*,scope=*,name=ReadLatency"
|
||||
field_prefix = "$2_"
|
||||
tag_keys = ["keyspace", "name", "scope"]
|
||||
|
14
migrations/inputs_cassandra/testcases/simple/telegraf.conf
Normal file
14
migrations/inputs_cassandra/testcases/simple/telegraf.conf
Normal file
|
@ -0,0 +1,14 @@
|
|||
[[inputs.cassandra]]
|
||||
context = "/jolokia/read"
|
||||
## List of cassandra servers exposing jolokia read service
|
||||
servers = ["myuser:mypassword@10.10.10.1:8778","10.10.10.2:8778",":8778"]
|
||||
## List of metrics collected on above servers
|
||||
## Each metric consists of a jmx path.
|
||||
## This will collect all heap memory usage metrics from the jvm and
|
||||
## ReadLatency metrics for all keyspaces and tables.
|
||||
## "type=Table" in the query works with Cassandra3.0. Older versions might
|
||||
## need to use "type=ColumnFamily"
|
||||
metrics = [
|
||||
"/java.lang:type=Memory/HeapMemoryUsage",
|
||||
"/org.apache.cassandra.metrics:type=Table,keyspace=*,scope=*,name=ReadLatency"
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue