Exemplo n.º 1
0
// NewProvider will use the values in the Metrics config object
// to generate a new go-kit/metrics/provider.Provider implementation.
// If no type is given, a no-op implementation will be used.
func (cfg Config) NewProvider() (provider.Provider, error) {
	if cfg.Logger == nil {
		cfg.Logger = log.NewNopLogger()
	}
	if cfg.Path == "" {
		cfg.Path = "/debug/vars"
	}
	if cfg.Interval == 0 {
		cfg.Interval = time.Second * 30
	}
	switch cfg.Type {
	case Statsd:
		return provider.NewStatsdProvider(cfg.Network, cfg.Addr,
			cfg.Prefix, cfg.Interval, cfg.Logger)
	case DogStatsd:
		return provider.NewDogStatsdProvider(cfg.Network, cfg.Addr,
			cfg.Prefix, cfg.Interval, cfg.Logger)
	case Graphite:
		return provider.NewGraphiteProvider(cfg.Network, cfg.Addr,
			cfg.Prefix, cfg.Interval, cfg.Logger)
	case Prometheus:
		return provider.NewPrometheusProvider(cfg.Namespace, cfg.Subsystem), nil
	case Expvar:
		return provider.NewExpvarProvider(cfg.Prefix), nil
	default:
		return provider.NewDiscardProvider(), nil
	}
}
Exemplo n.º 2
0
func TestRun(t *testing.T) {
	tests := []struct {
		givenSub pubsub.Subscriber

		wantArticles []nyt.SemanticConceptArticle
	}{
		{
			&pubsubtest.TestSubscriber{
				ProtoMessages: []proto.Message{
					&nyt.SemanticConceptArticle{
						Url: "http://www.nytimes.com/awesome-cat-article-1",
					},
					&nyt.SemanticConceptArticle{
						Url: "http://www.nytimes.com/awesome-cat-article-2",
					},
				},
			},

			[]nyt.SemanticConceptArticle{
				nyt.SemanticConceptArticle{
					Url: "http://www.nytimes.com/awesome-cat-article-1",
				},
				nyt.SemanticConceptArticle{
					Url: "http://www.nytimes.com/awesome-cat-article-2",
				},
			},
		},
	}

	for _, test := range tests {

		// set test env
		sub = test.givenSub
		metrics = provider.NewDiscardProvider()

		Run()

		for idx, article := range articles {
			if !reflect.DeepEqual(test.wantArticles[idx], article) {
				t.Errorf("got article[%d]:\n%#v\nexpected:\n%#v", idx, article, test.wantArticles[idx])
			}
		}

	}

}