-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92f8ce8
commit be2c91e
Showing
4 changed files
with
157 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
static/integrations/catchpoint_exporter/catchpoint_exporter.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package catchpoint_exporter | ||
|
||
import ( | ||
"github.com/go-kit/log" | ||
"github.com/grafana/agent/static/integrations" | ||
integrations_v2 "github.com/grafana/agent/static/integrations/v2" | ||
"github.com/grafana/agent/static/integrations/v2/metricsutils" | ||
collector "github.com/grafana/catchpoint-prometheus-exporter" | ||
) | ||
|
||
// DefaultConfig is the default config for the snowflake integration | ||
var DefaultConfig = Config{ | ||
Verbose: false, | ||
WebhookPath: "/catchpoint-webhook", | ||
Port: "9090", | ||
} | ||
|
||
// Config is the configuration for the snowflake integration | ||
type Config struct { | ||
Verbose bool `yaml:"verbose,omitempty"` | ||
WebhookPath string `yaml:"webhookpath,omitempty"` | ||
Port string `yaml:"port,omitempty"` | ||
} | ||
|
||
func (c *Config) exporterConfig() *collector.Config { | ||
return &collector.Config{ | ||
Verbose: c.Verbose, | ||
WebhookPath: c.WebhookPath, | ||
Port: string(c.Port), | ||
} | ||
} | ||
|
||
// Identifier returns a string that identifies the integration. | ||
func (c *Config) InstanceKey(agentKey string) (string, error) { | ||
return c.Port, nil | ||
} | ||
|
||
// UnmarshalYAML implements yaml.Unmarshaler for Config | ||
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
*c = DefaultConfig | ||
|
||
type plain Config | ||
return unmarshal((*plain)(c)) | ||
} | ||
|
||
// Name returns the name of the integration this config is for. | ||
func (c *Config) Name() string { | ||
return "catchpoint" | ||
} | ||
|
||
func init() { | ||
integrations.RegisterIntegration(&Config{}) | ||
integrations_v2.RegisterLegacy(&Config{}, integrations_v2.TypeMultiplex, metricsutils.NewNamedShim("catchpoint")) | ||
} | ||
|
||
// NewIntegration creates a new integration from the config. | ||
func (c *Config) NewIntegration(l log.Logger) (integrations.Integration, error) { | ||
exporterConfig := c.exporterConfig() | ||
|
||
if err := exporterConfig.Validate(); err != nil { | ||
return nil, err | ||
} | ||
|
||
col := collector.NewCollector(l, exporterConfig) | ||
return integrations.NewCollectorIntegration( | ||
c.Name(), | ||
integrations.WithCollectors(col), | ||
), nil | ||
} |
64 changes: 64 additions & 0 deletions
64
static/integrations/catchpoint_exporter/catchpoint_exporter_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package catchpoint_exporter | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/stretchr/testify/require" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
func TestConfig_UnmarshalYaml(t *testing.T) { | ||
strConfig := ` | ||
port = "3030" | ||
verbose = true | ||
webhookpath = "/nondefault-webhook-path" | ||
` | ||
|
||
var c Config | ||
|
||
require.NoError(t, yaml.UnmarshalStrict([]byte(strConfig), &c)) | ||
|
||
require.Equal(t, Config{ | ||
Verbose: true, | ||
Port: "3030", | ||
WebhookPath: "/nondefault-webhook-path", | ||
}, c) | ||
} | ||
|
||
func TestConfig_NewIntegration(t *testing.T) { | ||
t.Run("integration with valid config", func(t *testing.T) { | ||
c := &Config{ | ||
Verbose: true, | ||
Port: "3030", | ||
WebhookPath: "/nondefault-webhook-path", | ||
} | ||
|
||
i, err := c.NewIntegration(log.NewJSONLogger(os.Stdout)) | ||
require.NoError(t, err) | ||
require.NotNil(t, i) | ||
}) | ||
|
||
t.Run("integration with invalid config", func(t *testing.T) { | ||
c := &Config{ | ||
Verbose: "incorrect_value", | ||
Port: "3030", | ||
WebhookPath: "/nondefault-webhook-path", | ||
} | ||
|
||
i, err := c.NewIntegration(log.NewJSONLogger(os.Stdout)) | ||
require.Nil(t, i) | ||
require.ErrorContains(t, err, "") | ||
}) | ||
} | ||
|
||
func TestConfig_AgentKey(t *testing.T) { | ||
c := DefaultConfig | ||
c.Port = "3030" | ||
|
||
ik := "agent-key" | ||
id, err := c.InstanceKey(ik) | ||
require.NoError(t, err) | ||
require.Equal(t, "localhost:3030", id) | ||
} |