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
68
migrations/inputs_sflow/migration.go
Normal file
68
migrations/inputs_sflow/migration.go
Normal file
|
@ -0,0 +1,68 @@
|
|||
package inputs_sflow
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/influxdata/toml"
|
||||
"github.com/influxdata/toml/ast"
|
||||
|
||||
"github.com/influxdata/telegraf/migrations"
|
||||
"github.com/influxdata/telegraf/migrations/common"
|
||||
)
|
||||
|
||||
const msg = `
|
||||
Replacement 'inputs.netflow' will output a different metric format.
|
||||
Please adapt your queries!
|
||||
`
|
||||
|
||||
// Define "old" data structure
|
||||
type sflow struct {
|
||||
ServiceAddress string `toml:"service_address"`
|
||||
ReadBufferSize string `toml:"read_buffer_size"`
|
||||
common.InputOptions
|
||||
}
|
||||
|
||||
// Migration function
|
||||
func migrate(tbl *ast.Table) ([]byte, string, error) {
|
||||
// Decode the old data structure
|
||||
var old sflow
|
||||
if err := toml.UnmarshalTable(tbl, &old); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
// Fill common options
|
||||
plugin := make(map[string]interface{})
|
||||
old.InputOptions.Migrate()
|
||||
general, err := toml.Marshal(old.InputOptions)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("marshalling general options failed: %w", err)
|
||||
}
|
||||
if err := toml.Unmarshal(general, &plugin); err != nil {
|
||||
return nil, "", fmt.Errorf("re-unmarshalling general options failed: %w", err)
|
||||
}
|
||||
|
||||
// Use a map for the new plugin and fill in the data
|
||||
plugin["service_address"] = old.ServiceAddress
|
||||
if old.ReadBufferSize != "" {
|
||||
plugin["read_buffer_size"] = old.ReadBufferSize
|
||||
}
|
||||
|
||||
// Create the corresponding metric configurations
|
||||
cfg := migrations.CreateTOMLStruct("inputs", "netflow")
|
||||
cfg.Add("inputs", "netflow", 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, msg, nil
|
||||
}
|
||||
|
||||
// Register the migration function for the plugin type
|
||||
func init() {
|
||||
migrations.AddPluginMigration("inputs.sflow", migrate)
|
||||
}
|
62
migrations/inputs_sflow/migration_test.go
Normal file
62
migrations/inputs_sflow/migration_test.go
Normal file
|
@ -0,0 +1,62 @@
|
|||
package inputs_sflow_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/config"
|
||||
_ "github.com/influxdata/telegraf/migrations/inputs_sflow" // register migration
|
||||
_ "github.com/influxdata/telegraf/plugins/inputs/netflow" // register plugin
|
||||
_ "github.com/influxdata/telegraf/plugins/inputs/sflow" // 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.ElementsMatchf(t, expectedIDs, actualIDs, "generated config: %s", string(output))
|
||||
})
|
||||
}
|
||||
}
|
7
migrations/inputs_sflow/testcases/filters/expected.conf
Normal file
7
migrations/inputs_sflow/testcases/filters/expected.conf
Normal file
|
@ -0,0 +1,7 @@
|
|||
[[inputs.netflow]]
|
||||
service_address = "udp://:6343"
|
||||
read_buffer_size = "32KiB"
|
||||
fieldinclude = ["a"]
|
||||
name_override = "foo"
|
||||
[inputs.netflow.tags]
|
||||
foo = "bar"
|
8
migrations/inputs_sflow/testcases/filters/telegraf.conf
Normal file
8
migrations/inputs_sflow/testcases/filters/telegraf.conf
Normal file
|
@ -0,0 +1,8 @@
|
|||
[[inputs.sflow]]
|
||||
service_address = "udp://:6343"
|
||||
read_buffer_size = "32KiB"
|
||||
|
||||
name_override = "foo"
|
||||
fieldpass = ["a"]
|
||||
[inputs.sflow.tags]
|
||||
foo = "bar"
|
2
migrations/inputs_sflow/testcases/minimal/expected.conf
Normal file
2
migrations/inputs_sflow/testcases/minimal/expected.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
[[inputs.netflow]]
|
||||
service_address = "udp://:6343"
|
11
migrations/inputs_sflow/testcases/minimal/telegraf.conf
Normal file
11
migrations/inputs_sflow/testcases/minimal/telegraf.conf
Normal file
|
@ -0,0 +1,11 @@
|
|||
# SFlow V5 Protocol Listener
|
||||
[[inputs.sflow]]
|
||||
## Address to listen for sFlow packets.
|
||||
## example: service_address = "udp://:6343"
|
||||
## service_address = "udp4://:6343"
|
||||
## service_address = "udp6://:6343"
|
||||
service_address = "udp://:6343"
|
||||
|
||||
## Set the size of the operating system's receive buffer.
|
||||
## example: read_buffer_size = "64KiB"
|
||||
# read_buffer_size = ""
|
|
@ -0,0 +1,3 @@
|
|||
[[inputs.netflow]]
|
||||
service_address = "udp://:6343"
|
||||
read_buffer_size = "32KiB"
|
|
@ -0,0 +1,11 @@
|
|||
# SFlow V5 Protocol Listener
|
||||
[[inputs.sflow]]
|
||||
## Address to listen for sFlow packets.
|
||||
## example: service_address = "udp://:6343"
|
||||
## service_address = "udp4://:6343"
|
||||
## service_address = "udp6://:6343"
|
||||
service_address = "udp://:6343"
|
||||
|
||||
## Set the size of the operating system's receive buffer.
|
||||
## example: read_buffer_size = "64KiB"
|
||||
read_buffer_size = "32KiB"
|
Loading…
Add table
Add a link
Reference in a new issue