Revision 3c81218ba373248450e46728f5667a899bb38109 authored by Grot (@grafanabot) on 14 May 2021, 06:52:03 UTC, committed by GitHub on 14 May 2021, 06:52:03 UTC
* Timeline: Text align option, but does not work

* working text alignment

* Refactoring and fixing rendering text values on the right edge that does not fit

Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
(cherry picked from commit 96183d70a8bebdd6ee79a01fcc3611a8fb3b9da1)

Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
1 parent 728a2bd
Raw File
settings.go
package metrics

import (
	"fmt"
	"strings"
	"time"

	"github.com/grafana/grafana/pkg/infra/metrics/graphitebridge"
	"github.com/grafana/grafana/pkg/setting"
	"github.com/prometheus/client_golang/prometheus"
)

func (im *InternalMetricsService) readSettings() error {
	var section, err = im.Cfg.Raw.GetSection("metrics")
	if err != nil {
		return fmt.Errorf("unable to find metrics config section: %w", err)
	}

	im.intervalSeconds = section.Key("interval_seconds").MustInt64(10)

	if err := im.parseGraphiteSettings(); err != nil {
		return fmt.Errorf("unable to parse metrics graphite section: %w", err)
	}

	return nil
}

func (im *InternalMetricsService) parseGraphiteSettings() error {
	graphiteSection, err := im.Cfg.Raw.GetSection("metrics.graphite")
	if err != nil {
		return nil
	}

	address := graphiteSection.Key("address").String()
	if address == "" {
		return nil
	}

	bridgeCfg := &graphitebridge.Config{
		URL:             address,
		Prefix:          graphiteSection.Key("prefix").MustString("prod.grafana.%(instance_name)s"),
		CountersAsDelta: true,
		Gatherer:        prometheus.DefaultGatherer,
		Interval:        time.Duration(im.intervalSeconds) * time.Second,
		Timeout:         10 * time.Second,
		Logger:          &logWrapper{logger: metricsLogger},
		ErrorHandling:   graphitebridge.ContinueOnError,
	}

	safeInstanceName := strings.ReplaceAll(setting.InstanceName, ".", "_")
	prefix := graphiteSection.Key("prefix").Value()

	if prefix == "" {
		prefix = "prod.grafana.%(instance_name)s."
	}

	bridgeCfg.Prefix = strings.ReplaceAll(prefix, "%(instance_name)s", safeInstanceName)

	im.graphiteCfg = bridgeCfg
	return nil
}
back to top