mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Merge branch 'master' into ma/cloud-110
This commit is contained in:
commit
2cec88e19d
6 changed files with 35 additions and 19 deletions
|
|
@ -27,7 +27,7 @@ import (
|
|||
|
||||
const (
|
||||
// namespace is prepended to each metric event name with "_"
|
||||
defaultNamespace = "pilosa"
|
||||
defaultNamespace = "general"
|
||||
)
|
||||
|
||||
// Ensure client implements interface.
|
||||
|
|
|
|||
|
|
@ -47,7 +47,9 @@ func TestPrometheusClient_WithTags(t *testing.T) {
|
|||
|
||||
func TestPrometheusClient_Methods(t *testing.T) {
|
||||
// Create a new client.
|
||||
c, err := pilosaPrometheus.NewPrometheusClient()
|
||||
c, err := pilosaPrometheus.NewPrometheusClient(
|
||||
pilosaPrometheus.OptClientNamespace("testns"),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -64,7 +66,7 @@ func TestPrometheusClient_Methods(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, metricName := range []string{"pilosa_ct", "pilosa_cc", "pilosa_gg", "pilosa_hh", "pilosa_tt"} {
|
||||
for _, metricName := range []string{"testns_ct", "testns_cc", "testns_gg", "testns_hh", "testns_tt"} {
|
||||
if metricExists(metricName, metricFams) {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ const (
|
|||
defaultBindPort = "10101"
|
||||
defaultBindGRPCPort = "20101"
|
||||
defaultDiagnosticsInterval = 1 * time.Hour
|
||||
|
||||
namespacePilosa = "pilosa"
|
||||
namespaceFeaturebase = "featurebase"
|
||||
)
|
||||
|
||||
// TLSConfig contains TLS configuration
|
||||
|
|
@ -237,6 +240,14 @@ type Config struct {
|
|||
} `toml:"future"`
|
||||
}
|
||||
|
||||
// Namespace returns the namespace to use based on the Future flag.
|
||||
func (c *Config) Namespace() string {
|
||||
if c.Future.Rename {
|
||||
return namespaceFeaturebase
|
||||
}
|
||||
return namespacePilosa
|
||||
}
|
||||
|
||||
// MustValidate checks that all ports in a Config are unique and not zero.
|
||||
// We disallow zero because the tests need to be using from the pre-allocated
|
||||
// block of ports maintained by the pilosa/test/port port-mapper.
|
||||
|
|
|
|||
|
|
@ -391,7 +391,7 @@ func (m *Command) SetupServer() error {
|
|||
diagnosticsInterval = defaultDiagnosticsInterval
|
||||
}
|
||||
|
||||
statsClient, err := newStatsClient(m.Config.Metric.Service, m.Config.Metric.Host)
|
||||
statsClient, err := newStatsClient(m.Config.Metric.Service, m.Config.Metric.Host, m.Config.Namespace())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "new stats client")
|
||||
}
|
||||
|
|
@ -611,14 +611,16 @@ func (m *Command) Close() error {
|
|||
}
|
||||
|
||||
// newStatsClient creates a stats client from the config
|
||||
func newStatsClient(name string, host string) (stats.StatsClient, error) {
|
||||
func newStatsClient(name string, host string, namespace string) (stats.StatsClient, error) {
|
||||
switch name {
|
||||
case "expvar":
|
||||
return stats.NewExpvarStatsClient(), nil
|
||||
case "statsd":
|
||||
return statsd.NewStatsClient(host)
|
||||
return statsd.NewStatsClient(host, namespace)
|
||||
case "prometheus":
|
||||
return prometheus.NewPrometheusClient()
|
||||
return prometheus.NewPrometheusClient(
|
||||
prometheus.OptClientNamespace(namespace),
|
||||
)
|
||||
case "nop", "none":
|
||||
return stats.NopStatsClient, nil
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -27,9 +27,6 @@ import (
|
|||
// statsD defailt host is "127.0.0.1:8125"
|
||||
|
||||
const (
|
||||
// prefix is appended to each metric event name
|
||||
prefix = "pilosa."
|
||||
|
||||
// bufferLen Stats lient buffer size.
|
||||
bufferLen = 1024
|
||||
)
|
||||
|
|
@ -42,10 +39,13 @@ type statsClient struct {
|
|||
client *statsd.Client
|
||||
tags []string
|
||||
logger logger.Logger
|
||||
|
||||
// prefix is appended to each metric event name
|
||||
prefix string
|
||||
}
|
||||
|
||||
// NewStatsClient returns a new instance of StatsClient.
|
||||
func NewStatsClient(host string) (*statsClient, error) {
|
||||
func NewStatsClient(host string, namespace string) (*statsClient, error) {
|
||||
c, err := statsd.NewBuffered(host, bufferLen)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -54,6 +54,7 @@ func NewStatsClient(host string) (*statsClient, error) {
|
|||
return &statsClient{
|
||||
client: c,
|
||||
logger: logger.NopLogger,
|
||||
prefix: namespace + ".",
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +82,7 @@ func (c *statsClient) WithTags(tags ...string) stats.StatsClient {
|
|||
|
||||
// Count tracks the number of times something occurs per second.
|
||||
func (c *statsClient) Count(name string, value int64, rate float64) {
|
||||
if err := c.client.Count(prefix+name, value, c.tags, rate); err != nil {
|
||||
if err := c.client.Count(c.prefix+name, value, c.tags, rate); err != nil {
|
||||
c.logger.Errorf("statsd.StatsClient.Count error: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -89,35 +90,35 @@ func (c *statsClient) Count(name string, value int64, rate float64) {
|
|||
// CountWithCustomTags tracks the number of times something occurs per second with custom tags.
|
||||
func (c *statsClient) CountWithCustomTags(name string, value int64, rate float64, t []string) {
|
||||
tags := append(c.tags, t...)
|
||||
if err := c.client.Count(prefix+name, value, tags, rate); err != nil {
|
||||
if err := c.client.Count(c.prefix+name, value, tags, rate); err != nil {
|
||||
c.logger.Errorf("statsd.StatsClient.Count error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Gauge sets the value of a metric.
|
||||
func (c *statsClient) Gauge(name string, value float64, rate float64) {
|
||||
if err := c.client.Gauge(prefix+name, value, c.tags, rate); err != nil {
|
||||
if err := c.client.Gauge(c.prefix+name, value, c.tags, rate); err != nil {
|
||||
c.logger.Errorf("statsd.StatsClient.Gauge error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Histogram tracks statistical distribution of a metric.
|
||||
func (c *statsClient) Histogram(name string, value float64, rate float64) {
|
||||
if err := c.client.Histogram(prefix+name, value, c.tags, rate); err != nil {
|
||||
if err := c.client.Histogram(c.prefix+name, value, c.tags, rate); err != nil {
|
||||
c.logger.Errorf("statsd.StatsClient.Histogram error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Set tracks number of unique elements.
|
||||
func (c *statsClient) Set(name string, value string, rate float64) {
|
||||
if err := c.client.Set(prefix+name, value, c.tags, rate); err != nil {
|
||||
if err := c.client.Set(c.prefix+name, value, c.tags, rate); err != nil {
|
||||
c.logger.Errorf("statsd.StatsClient.Set error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Timing tracks timing information for a metric.
|
||||
func (c *statsClient) Timing(name string, value time.Duration, rate float64) {
|
||||
if err := c.client.Timing(prefix+name, value, c.tags, rate); err != nil {
|
||||
if err := c.client.Timing(c.prefix+name, value, c.tags, rate); err != nil {
|
||||
c.logger.Errorf("statsd.StatsClient.Timing error: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import (
|
|||
|
||||
func TestStatsClient_WithTags(t *testing.T) {
|
||||
// Create a new client.
|
||||
c, err := statsd.NewStatsClient("localhost:19444")
|
||||
c, err := statsd.NewStatsClient("localhost:19444", "testnamespace")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ func TestStatsClient_WithTags(t *testing.T) {
|
|||
|
||||
func TestStatsClient_Methods(t *testing.T) {
|
||||
// Create a new client.
|
||||
c, err := statsd.NewStatsClient("localhost:19444")
|
||||
c, err := statsd.NewStatsClient("localhost:19444", "testnamespace")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue