Skip to content

Commit

Permalink
Merge branch 'master' into supported-status-codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakerdotes authored May 12, 2022
2 parents e2f86ec + 2cad990 commit 680e5d1
Show file tree
Hide file tree
Showing 61 changed files with 450 additions and 357 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: "Semantic PR and Commit Messages"

on:
pull_request:
types: [opened, reopened, synchronize, edited]
branches:
- master

jobs:
semantic:
uses: influxdata/validate-semantic-github-messages/.github/workflows/semantic.yml@main
with:
CHECK_PR_TITLE_OR_ONE_COMMIT: true

9 changes: 8 additions & 1 deletion internal/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"os"
"os/exec"
"sync"
"sync/atomic"
Expand All @@ -26,13 +27,14 @@ type Process struct {

name string
args []string
envs []string
pid int32
cancel context.CancelFunc
mainLoopWg sync.WaitGroup
}

// New creates a new process wrapper
func New(command []string) (*Process, error) {
func New(command []string, envs []string) (*Process, error) {
if len(command) == 0 {
return nil, errors.New("no command")
}
Expand All @@ -41,6 +43,7 @@ func New(command []string) (*Process, error) {
RestartDelay: 5 * time.Second,
name: command[0],
args: []string{},
envs: envs,
}

if len(command) > 1 {
Expand Down Expand Up @@ -85,6 +88,10 @@ func (p *Process) Stop() {
func (p *Process) cmdStart() error {
p.Cmd = exec.Command(p.name, p.args...)

if len(p.envs) > 0 {
p.Cmd.Env = append(os.Environ(), p.envs...)
}

var err error
p.Stdin, err = p.Cmd.StdinPipe()
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestRestartingRebindsPipes(t *testing.T) {
exe, err := os.Executable()
require.NoError(t, err)

p, err := New([]string{exe, "-external"})
p, err := New([]string{exe, "-external"}, []string{"INTERNAL_PROCESS_MODE=application"})
p.RestartDelay = 100 * time.Nanosecond
p.Log = testutil.Logger{}
require.NoError(t, err)
Expand Down Expand Up @@ -62,7 +62,8 @@ var external = flag.Bool("external", false,

func TestMain(m *testing.M) {
flag.Parse()
if *external {
runMode := os.Getenv("INTERNAL_PROCESS_MODE")
if *external && runMode == "application" {
externalProcess()
os.Exit(0)
}
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/aerospike/aerospike.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (a *Aerospike) parseNodeInfo(acc telegraf.Accumulator, stats map[string]str
if len(parts) < 2 {
continue
}
key := strings.Replace(parts[0], "-", "_", -1)
key := strings.ReplaceAll(parts[0], "-", "_")
nFields[key] = parseAerospikeValue(key, parts[1])
}
acc.AddFields("aerospike_node", nFields, nTags, time.Now())
Expand Down Expand Up @@ -244,7 +244,7 @@ func (a *Aerospike) parseNamespaceInfo(acc telegraf.Accumulator, stats map[strin
if len(parts) < 2 {
continue
}
key := strings.Replace(parts[0], "-", "_", -1)
key := strings.ReplaceAll(parts[0], "-", "_")
nFields[key] = parseAerospikeValue(key, parts[1])
}
acc.AddFields("aerospike_namespace", nFields, nTags, time.Now())
Expand Down Expand Up @@ -311,7 +311,7 @@ func (a *Aerospike) parseSetInfo(acc telegraf.Accumulator, stats map[string]stri
continue
}

key := strings.Replace(pieces[0], "-", "_", -1)
key := strings.ReplaceAll(pieces[0], "-", "_")
nFields[key] = parseAerospikeValue(key, pieces[1])
}
acc.AddFields("aerospike_set", nFields, nTags, time.Now())
Expand Down Expand Up @@ -403,7 +403,7 @@ func (a *Aerospike) parseHistogram(acc telegraf.Accumulator, stats map[string]st
}
}

acc.AddFields(fmt.Sprintf("aerospike_histogram_%v", strings.Replace(histogramType, "-", "_", -1)), nFields, nTags, time.Now())
acc.AddFields(fmt.Sprintf("aerospike_histogram_%v", strings.ReplaceAll(histogramType, "-", "_")), nFields, nTags, time.Now())
}

func splitNamespaceSet(namespaceSet string) (namespace string, set string) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/aliyuncms/aliyuncms.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,14 @@ func formatField(metricName string, statistic string) string {
}

func formatMeasurement(project string) string {
project = strings.Replace(project, "/", "_", -1)
project = strings.ReplaceAll(project, "/", "_")
project = snakeCase(project)
return fmt.Sprintf("aliyuncms_%s", project)
}

func snakeCase(s string) string {
s = internal.SnakeCase(s)
s = strings.Replace(s, "__", "_", -1)
s = strings.ReplaceAll(s, "__", "_")
return s
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/amd_rocm_smi/amd_rocm_smi.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func genTagsFields(gpus map[string]GPU, system map[string]sysInfo) []metric {
setTagIfUsed(tags, "gpu_id", payload.GpuID)
setTagIfUsed(tags, "gpu_unique_id", payload.GpuUniqueID)

setIfUsed("int", fields, "driver_version", strings.Replace(system["system"].DriverVersion, ".", "", -1))
setIfUsed("int", fields, "driver_version", strings.ReplaceAll(system["system"].DriverVersion, ".", ""))
setIfUsed("int", fields, "fan_speed", payload.GpuFanSpeedPercentage)
setIfUsed("int64", fields, "memory_total", payload.GpuVRAMTotalMemory)
setIfUsed("int64", fields, "memory_used", payload.GpuVRAMTotalUsedMemory)
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/apache/apache.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (n *Apache) gatherURL(addr *url.URL, acc telegraf.Accumulator) error {
line := sc.Text()
if strings.Contains(line, ":") {
parts := strings.SplitN(line, ":", 2)
key, part := strings.Replace(parts[0], " ", "", -1), strings.TrimSpace(parts[1])
key, part := strings.ReplaceAll(parts[0], " ", ""), strings.TrimSpace(parts[1])

switch key {
case "Scoreboard":
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/burrow/burrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// remap uri to json file, eg: /v3/kafka -> ./testdata/v3_kafka.json
func getResponseJSON(requestURI string) ([]byte, int) {
uri := strings.TrimLeft(requestURI, "/")
mappedFile := strings.Replace(uri, "/", "_", -1)
mappedFile := strings.ReplaceAll(uri, "/", "_")
jsonFile := fmt.Sprintf("./testdata/%s.json", mappedFile)

code := 200
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/ceph/ceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ func (c *Ceph) execute(command string) (string, error) {

// Ceph doesn't sanitize its output, and may return invalid JSON. Patch this
// up for them, as having some inaccurate data is better than none.
output = strings.Replace(output, "-inf", "0", -1)
output = strings.Replace(output, "inf", "0", -1)
output = strings.ReplaceAll(output, "-inf", "0")
output = strings.ReplaceAll(output, "inf", "0")

return output, nil
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/chrony/chrony.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func processChronycOutput(out string) (map[string]interface{}, map[string]string
if len(stats) < 2 {
return nil, nil, fmt.Errorf("unexpected output from chronyc, expected ':' in %s", out)
}
name := strings.ToLower(strings.Replace(strings.TrimSpace(stats[0]), " ", "_", -1))
name := strings.ToLower(strings.ReplaceAll(strings.TrimSpace(stats[0]), " ", "_"))
// ignore reference time
if strings.Contains(name, "ref_time") {
continue
Expand Down
10 changes: 5 additions & 5 deletions plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (c *CiscoTelemetryMDT) Start(acc telegraf.Accumulator) error {
// Fill extra tags
c.extraTags = make(map[string]map[string]struct{})
for _, tag := range c.EmbeddedTags {
dir := strings.Replace(path.Dir(tag), "-", "_", -1)
dir := strings.ReplaceAll(path.Dir(tag), "-", "_")
if _, hasKey := c.extraTags[dir]; !hasKey {
c.extraTags[dir] = make(map[string]struct{})
}
Expand Down Expand Up @@ -441,7 +441,7 @@ func decodeTag(field *telemetry.TelemetryField) string {

// Recursively parse tag fields
func (c *CiscoTelemetryMDT) parseKeyField(tags map[string]string, field *telemetry.TelemetryField, prefix string) {
localname := strings.Replace(field.Name, "-", "_", -1)
localname := strings.ReplaceAll(field.Name, "-", "_")
name := localname
if len(localname) == 0 {
name = prefix
Expand Down Expand Up @@ -529,7 +529,7 @@ func (c *CiscoTelemetryMDT) parseClassAttributeField(grouper *metric.SeriesGroup

func (c *CiscoTelemetryMDT) parseContentField(grouper *metric.SeriesGrouper, field *telemetry.TelemetryField, prefix string,
encodingPath string, tags map[string]string, timestamp time.Time) {
name := strings.Replace(field.Name, "-", "_", -1)
name := strings.ReplaceAll(field.Name, "-", "_")

if (name == "modTs" || name == "createTs") && decodeValue(field) == "never" {
return
Expand All @@ -540,7 +540,7 @@ func (c *CiscoTelemetryMDT) parseContentField(grouper *metric.SeriesGrouper, fie
name = prefix + "/" + name
}

extraTags := c.extraTags[strings.Replace(encodingPath, "-", "_", -1)+"/"+name]
extraTags := c.extraTags[strings.ReplaceAll(encodingPath, "-", "_")+"/"+name]

if value := decodeValue(field); value != nil {
// Do alias lookup, to shorten measurement names
Expand Down Expand Up @@ -571,7 +571,7 @@ func (c *CiscoTelemetryMDT) parseContentField(grouper *metric.SeriesGrouper, fie
if len(extraTags) > 0 {
for _, subfield := range field.Fields {
if _, isExtraTag := extraTags[subfield.Name]; isExtraTag {
tags[name+"/"+strings.Replace(subfield.Name, "-", "_", -1)] = decodeTag(subfield)
tags[name+"/"+strings.ReplaceAll(subfield.Name, "-", "_")] = decodeTag(subfield)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,15 @@ func New() *CloudWatch {
}

func sanitizeMeasurement(namespace string) string {
namespace = strings.Replace(namespace, "/", "_", -1)
namespace = strings.ReplaceAll(namespace, "/", "_")
namespace = snakeCase(namespace)
return "cloudwatch_" + namespace
}

func snakeCase(s string) string {
s = internal.SnakeCase(s)
s = strings.Replace(s, " ", "_", -1)
s = strings.Replace(s, "__", "_", -1)
s = strings.ReplaceAll(s, " ", "_")
s = strings.ReplaceAll(s, "__", "_")
return s
}

Expand Down
Loading

0 comments on commit 680e5d1

Please sign in to comment.