Skip to content

Commit

Permalink
chore: embed sample configurations into README for outputs (#11182)
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan authored May 25, 2022
1 parent 7d2016b commit d9a6d8b
Show file tree
Hide file tree
Showing 162 changed files with 622 additions and 501 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ generate_plugins_%: build_generator
go generate -run="plugindata/main.go$$" ./plugins/$*/...

.PHONY: generate
generate: insert_config_to_readme_inputs generate_plugins_outputs generate_plugins_processors generate_plugins_aggregators
generate: insert_config_to_readme_inputs insert_config_to_readme_outputs generate_plugins_processors generate_plugins_aggregators

.PHONY: generate-clean
generate-clean:
go generate -run="plugindata/main.go --clean" ./plugins/outputs/... ./plugins/processors/... ./plugins/aggregators/...
go generate -run="plugindata/main.go --clean" ./plugins/processors/... ./plugins/aggregators/...

.PHONY: build
build:
Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/amon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Metrics are grouped by converting any `_` characters to `.` in the Point Name.

## Configuration

```toml
```toml @sample.conf
# Configuration for Amon Server to send metrics to.
[[outputs.amon]]
## Amon Server Key
Expand Down
10 changes: 10 additions & 0 deletions plugins/outputs/amon/amon.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//go:generate ../../../tools/readme_config_includer/generator
package amon

import (
"bytes"
_ "embed"
"encoding/json"
"fmt"
"net/http"
Expand All @@ -13,6 +15,10 @@ import (
"github.com/influxdata/telegraf/plugins/outputs"
)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data.
//go:embed sample.conf
var sampleConfig string

type Amon struct {
ServerKey string `toml:"server_key"`
AmonInstance string `toml:"amon_instance"`
Expand All @@ -33,6 +39,10 @@ type Metric struct {

type Point [2]float64

func (*Amon) SampleConfig() string {
return sampleConfig
}

func (a *Amon) Connect() error {
if a.ServerKey == "" || a.AmonInstance == "" {
return fmt.Errorf("serverkey and amon_instance are required fields for amon output")
Expand Down
8 changes: 0 additions & 8 deletions plugins/outputs/amon/amon_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/outputs/amqp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For an introduction to AMQP see:

## Configuration

```toml
```toml @sample.conf
# Publishes metrics to an AMQP broker
[[outputs.amqp]]
## Broker to publish to.
Expand Down
10 changes: 10 additions & 0 deletions plugins/outputs/amqp/amqp.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//go:generate ../../../tools/readme_config_includer/generator
package amqp

import (
"bytes"
_ "embed"
"strings"
"time"

Expand All @@ -15,6 +17,10 @@ import (
"github.com/influxdata/telegraf/plugins/serializers"
)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data.
//go:embed sample.conf
var sampleConfig string

const (
DefaultURL = "amqp://localhost:5672/influxdb"
DefaultAuthMethod = "PLAIN"
Expand Down Expand Up @@ -71,6 +77,10 @@ type Client interface {
Close() error
}

func (*AMQP) SampleConfig() string {
return sampleConfig
}

func (q *AMQP) SetSerializer(serializer serializers.Serializer) {
q.serializer = serializer
}
Expand Down
8 changes: 0 additions & 8 deletions plugins/outputs/amqp/amqp_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/outputs/application_insights/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Insights](https://azure.microsoft.com/en-us/services/application-insights/).

## Configuration

```toml
```toml @sample.conf
# Send metrics to Azure Application Insights
[[outputs.application_insights]]
## Instrumentation key of the Application Insights resource.
Expand Down
13 changes: 12 additions & 1 deletion plugins/outputs/application_insights/application_insights.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
//go:generate ../../../tools/readme_config_includer/generator
package application_insights

import (
_ "embed"
"fmt"
"math"
"time"
"unsafe"

"github.com/microsoft/ApplicationInsights-Go/appinsights"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/outputs"
"github.com/microsoft/ApplicationInsights-Go/appinsights"
)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data.
//go:embed sample.conf
var sampleConfig string

type TelemetryTransmitter interface {
Track(appinsights.Telemetry)
Close() <-chan struct{}
Expand Down Expand Up @@ -39,6 +46,10 @@ var (
is32BitChecked bool
)

func (*ApplicationInsights) SampleConfig() string {
return sampleConfig
}

func (a *ApplicationInsights) Connect() error {
if a.InstrumentationKey == "" {
return fmt.Errorf("instrumentation key is required")
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/outputs/azure_data_explorer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ of logs, metrics and time series data.

## Configuration

```toml
```toml @sample.conf
# Sends metrics to Azure Data Explorer
[[outputs.azure_data_explorer]]
## The URI property of the Azure Data Explorer resource on Azure
Expand Down
11 changes: 11 additions & 0 deletions plugins/outputs/azure_data_explorer/azure_data_explorer.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//go:generate ../../../tools/readme_config_includer/generator
package azure_data_explorer

import (
"bytes"
"context"
_ "embed"
"errors"
"fmt"
"io"
Expand All @@ -13,13 +15,18 @@ import (
"github.com/Azure/azure-kusto-go/kusto/ingest"
"github.com/Azure/azure-kusto-go/kusto/unsafe"
"github.com/Azure/go-autorest/autorest/azure/auth"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/outputs"
"github.com/influxdata/telegraf/plugins/serializers"
"github.com/influxdata/telegraf/plugins/serializers/json"
)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data.
//go:embed sample.conf
var sampleConfig string

type AzureDataExplorer struct {
Endpoint string `toml:"endpoint_url"`
Database string `toml:"database"`
Expand Down Expand Up @@ -55,6 +62,10 @@ type ingestorFactory func(localClient, string, string) (localIngestor, error)
const createTableCommand = `.create-merge table ['%s'] (['fields']:dynamic, ['name']:string, ['tags']:dynamic, ['timestamp']:datetime);`
const createTableMappingCommand = `.create-or-alter table ['%s'] ingestion json mapping '%s_mapping' '[{"column":"fields", "Properties":{"Path":"$[\'fields\']"}},{"column":"name", "Properties":{"Path":"$[\'name\']"}},{"column":"tags", "Properties":{"Path":"$[\'tags\']"}},{"column":"timestamp", "Properties":{"Path":"$[\'timestamp\']"}}]'`

func (*AzureDataExplorer) SampleConfig() string {
return sampleConfig
}

func (adx *AzureDataExplorer) Connect() error {
authorizer, err := auth.NewAuthorizerFromEnvironmentWithResource(adx.Endpoint)
if err != nil {
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/outputs/azure_monitor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dimension on each Azure Monitor metric.

## Configuration

```toml
```toml @sample.conf
# Send aggregate metrics to Azure Monitor
[[outputs.azure_monitor]]
## Timeout for HTTP writes.
Expand Down
10 changes: 10 additions & 0 deletions plugins/outputs/azure_monitor/azure_monitor.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//go:generate ../../../tools/readme_config_includer/generator
package azure_monitor

import (
"bytes"
"compress/gzip"
"context"
_ "embed"
"encoding/binary"
"encoding/json"
"fmt"
Expand All @@ -25,6 +27,10 @@ import (
"github.com/influxdata/telegraf/selfstat"
)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data.
//go:embed sample.conf
var sampleConfig string

// AzureMonitor allows publishing of metrics to the Azure Monitor custom metrics
// service
type AzureMonitor struct {
Expand Down Expand Up @@ -103,6 +109,10 @@ const (
maxRequestBodySize = 4000000
)

func (*AzureMonitor) SampleConfig() string {
return sampleConfig
}

// Connect initializes the plugin and validates connectivity
func (a *AzureMonitor) Connect() error {
a.cache = make(map[time.Time]map[uint64]*aggregate, 36)
Expand Down
8 changes: 0 additions & 8 deletions plugins/outputs/azure_monitor/azure_monitor_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/outputs/bigquery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Be aware that this plugin accesses APIs that are

## Configuration

```toml
```toml @sample.conf
# Configuration for Google Cloud BigQuery to send entries
[[outputs.bigquery]]
## Credentials File
Expand Down
10 changes: 10 additions & 0 deletions plugins/outputs/bigquery/bigquery.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//go:generate ../../../tools/readme_config_includer/generator
package bigquery

import (
"context"
_ "embed"
"fmt"
"reflect"
"strings"
Expand All @@ -17,6 +19,10 @@ import (
"github.com/influxdata/telegraf/plugins/outputs"
)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data.
//go:embed sample.conf
var sampleConfig string

const timeStampFieldName = "timestamp"

var defaultTimeout = config.Duration(5 * time.Second)
Expand All @@ -36,6 +42,10 @@ type BigQuery struct {
warnedOnHyphens map[string]bool
}

func (*BigQuery) SampleConfig() string {
return sampleConfig
}

func (s *BigQuery) Connect() error {
if s.Project == "" {
return fmt.Errorf("Project is a required field for BigQuery output")
Expand Down
8 changes: 0 additions & 8 deletions plugins/outputs/bigquery/bigquery_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/outputs/cloud_pubsub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ as one of the supported [output data formats][].

## Configuration

```toml
```toml @sample.conf
# Publish Telegraf metrics to a Google Cloud PubSub topic
[[outputs.cloud_pubsub]]
## Required. Name of Google Cloud Platform (GCP) Project that owns
Expand Down
15 changes: 13 additions & 2 deletions plugins/outputs/cloud_pubsub/cloud_pubsub.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
//go:generate ../../../tools/readme_config_includer/generator
package cloud_pubsub

import (
"context"
_ "embed"
"encoding/base64"
"fmt"
"sync"
"time"

"cloud.google.com/go/pubsub"
"golang.org/x/oauth2/google"
"google.golang.org/api/option"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/outputs"
"github.com/influxdata/telegraf/plugins/serializers"
"golang.org/x/oauth2/google"
"google.golang.org/api/option"
)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data.
//go:embed sample.conf
var sampleConfig string

type PubSub struct {
CredentialsFile string `toml:"credentials_file"`
Project string `toml:"project"`
Expand All @@ -41,6 +48,10 @@ type PubSub struct {
publishResults []publishResult
}

func (*PubSub) SampleConfig() string {
return sampleConfig
}

func (ps *PubSub) SetSerializer(serializer serializers.Serializer) {
ps.serializer = serializer
}
Expand Down
8 changes: 0 additions & 8 deletions plugins/outputs/cloud_pubsub/cloud_pubsub_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/outputs/cloudwatch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The IAM user needs only the `cloudwatch:PutMetricData` permission.

## Configuration

```toml
```toml @sample.conf
# Configuration for AWS CloudWatch output.
[[outputs.cloudwatch]]
## Amazon REGION
Expand Down
Loading

0 comments on commit d9a6d8b

Please sign in to comment.