Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/snowflake_exporter/snowflake_exporter.go
5414 views
1
package snowflake_exporter
2
3
import (
4
"github.com/go-kit/log"
5
"github.com/grafana/agent/pkg/integrations"
6
integrations_v2 "github.com/grafana/agent/pkg/integrations/v2"
7
"github.com/grafana/agent/pkg/integrations/v2/metricsutils"
8
"github.com/grafana/snowflake-prometheus-exporter/collector"
9
config_util "github.com/prometheus/common/config"
10
)
11
12
// DefaultConfig is the default config for the snowflake integration
13
var DefaultConfig = Config{
14
Role: "ACCOUNTADMIN",
15
}
16
17
// Config is the configuration for the snowflake integration
18
type Config struct {
19
AccountName string `yaml:"account_name,omitempty"`
20
Username string `yaml:"username,omitempty"`
21
Password config_util.Secret `yaml:"password,omitempty"`
22
Role string `yaml:"role,omitempty"`
23
Warehouse string `yaml:"warehouse,omitempty"`
24
}
25
26
func (c *Config) exporterConfig() *collector.Config {
27
return &collector.Config{
28
AccountName: c.AccountName,
29
Username: c.Username,
30
Password: string(c.Password),
31
Role: c.Role,
32
Warehouse: c.Warehouse,
33
}
34
}
35
36
// Identifier returns a string that identifies the integration.
37
func (c *Config) InstanceKey(agentKey string) (string, error) {
38
return c.AccountName, nil
39
}
40
41
// UnmarshalYAML implements yaml.Unmarshaler for Config
42
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
43
*c = DefaultConfig
44
45
type plain Config
46
return unmarshal((*plain)(c))
47
}
48
49
// Name returns the name of the integration this config is for.
50
func (c *Config) Name() string {
51
return "snowflake"
52
}
53
54
func init() {
55
integrations.RegisterIntegration(&Config{})
56
integrations_v2.RegisterLegacy(&Config{}, integrations_v2.TypeMultiplex, metricsutils.NewNamedShim("snowflake"))
57
}
58
59
// NewIntegration creates a new integration from the config.
60
func (c *Config) NewIntegration(l log.Logger) (integrations.Integration, error) {
61
exporterConfig := c.exporterConfig()
62
63
if err := exporterConfig.Validate(); err != nil {
64
return nil, err
65
}
66
67
col := collector.NewCollector(l, exporterConfig)
68
return integrations.NewCollectorIntegration(
69
c.Name(),
70
integrations.WithCollectors(col),
71
), nil
72
}
73
74