Skip to content

Commit

Permalink
updated the testcase
Browse files Browse the repository at this point in the history
WAN-2321 #time 30m
  • Loading branch information
shriyanshk128T committed Aug 31, 2023
1 parent f2006b7 commit 960379d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
10 changes: 5 additions & 5 deletions plugins/inputs/t128_graphql/t128_graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
timeoutDeadlineDiff = 1 * time.Second
)

//T128GraphQL is an input for metrics of a 128T router instance
// T128GraphQL is an input for metrics of a 128T router instance
type T128GraphQL struct {
CollectorName string `toml:"collector_name"`
BaseURL string `toml:"base_url"`
Expand All @@ -45,17 +45,17 @@ type T128GraphQL struct {
endpointNotFound bool
}

//SampleConfig returns the default configuration of the Input
// SampleConfig returns the default configuration of the Input
func (*T128GraphQL) SampleConfig() string {
return sampleConfig
}

//Description returns a one-sentence description on the Input
// Description returns a one-sentence description on the Input
func (*T128GraphQL) Description() string {
return "Make a 128T GraphQL query and return the data"
}

//Init sets up the input to be ready for action
// Init sets up the input to be ready for action
func (plugin *T128GraphQL) Init() error {
//check and load config
err := plugin.checkConfig()
Expand Down Expand Up @@ -138,7 +138,7 @@ func (plugin *T128GraphQL) checkConfig() error {
return nil
}

//Gather takes in an accumulator and adds the metrics that the Input gathers
// Gather takes in an accumulator and adds the metrics that the Input gathers
func (plugin *T128GraphQL) Gather(acc telegraf.Accumulator) error {
if !plugin.RetryIfNotFound && plugin.endpointNotFound {
return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/t128_peer_path/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The peer path input plugin collects data from a 128T instance via graphQL.

### Configuration
## Configuration

```toml
[[inputs.t128_peer_path]]
Expand All @@ -25,4 +25,4 @@ The peer path input plugin collects data from a 128T instance via graphQL.

## Versioned fields
# exclude_hostname = false
```
```
28 changes: 26 additions & 2 deletions plugins/inputs/t128_peer_path/t128_peer_path.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package t128_peer_path

import (
"fmt"
"time"

"github.com/influxdata/telegraf"
Expand Down Expand Up @@ -29,9 +30,31 @@ type T128PeerPath struct {
RetryIfNotFound bool `toml:"retry_if_not_found"`
ExcludeHostname bool `toml:"exclude_hostname"`
gqlCollector *t128_graphql.T128GraphQL
Query string
}

var sampleConfig = ``
var sampleConfig = `
[[inputs.t128_peer_path]]
## Required. A name for the collector which will be used as the measurement name of the produced data.
# collector_name = "peer-path-state"
## Required. The base url for data collection.
## graphQL ports vary across 128T versions.
# base_url = "http://localhost:31517/api/v1/graphql/"
## A socket to use for retrieving data - unused by default
# unix_socket = "/var/run/128technology/web-server.sock"
## Required. The path to a point in the graphQL tree from which extract_fields and extract_tags will
## be specified.
# entry_point = "allRouters/nodes/paths"
## Amount of time allowed before the client cancels the HTTP request
# timeout = "5s"
## Required. The versioned field to be included or not
# exclude_hostname = false
`

// SampleConfig returns the default configuration of the Input
func (*T128PeerPath) SampleConfig() string {
Expand All @@ -46,6 +69,7 @@ func (*T128PeerPath) Description() string {
// Init sets up the input to be ready for action
func (plugin *T128PeerPath) Init() error {

fmt.Println(plugin.CollectorName)
plugin.gqlCollector.CollectorName = plugin.CollectorName
plugin.gqlCollector.BaseURL = plugin.BaseURL
plugin.gqlCollector.UnixSocket = plugin.UnixSocket
Expand All @@ -54,6 +78,7 @@ func (plugin *T128PeerPath) Init() error {
plugin.gqlCollector.Tags = plugin.Tags
plugin.gqlCollector.Timeout = plugin.Timeout
plugin.gqlCollector.RetryIfNotFound = plugin.RetryIfNotFound
plugin.gqlCollector.Query = plugin.Query

plugin.gqlCollector.Init()

Expand All @@ -62,7 +87,6 @@ func (plugin *T128PeerPath) Init() error {

// Gather takes in an accumulator and adds the metrics that the Input gathers
func (plugin *T128PeerPath) Gather(acc telegraf.Accumulator) error {

plugin.gqlCollector.Gather(acc)
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions plugins/inputs/t128_peer_path/t128_peer_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/influxdata/telegraf"
plugin "github.com/influxdata/telegraf/plugins/inputs/t128_graphql"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -128,7 +127,7 @@ func TestT128PeerPathCollector(t *testing.T) {
fakeServer, requestCount := createTestServer(t, testCase.Endpoint)
defer fakeServer.Close()

plugin := &plugin.T128GraphQL{
plugin := &T128PeerPath{
CollectorName: "test-collector",
BaseURL: fakeServer.URL + "/api/v1/graphql",
EntryPoint: testCase.EntryPoint,
Expand Down

0 comments on commit 960379d

Please sign in to comment.