Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterSectionTest(name string, callback SectionTestCallback)
- func SanitizeMetricName(metric string, uniDecode bool) string
- func TestAlwaysTrue(PathSection) bool
- func TestIsNotEmpty(s PathSection) bool
- func TestIsNumeric(s PathSection) bool
- type Bucket
- type HTTPMetricNameAlterCallback
- type HTTPRequest
- type MetricOperation
- type PathSection
- type Plain
- type Prometheus
- type SecondLevelIDConfig
- type SectionTestCallback
- type SectionTestDefinition
- type SectionsTestsMap
Constants ¶
const ( // SectionRequest is default section name for tracking HTTP requests SectionRequest = "request" // MetricEmptyPlaceholder is a string placeholder for empty (unset) sections of operation MetricEmptyPlaceholder = "-" // MetricIDPlaceholder is a string placeholder for ID section of operation if any MetricIDPlaceholder = "-id-" // MetricOperationsMaxLength is maximum number of operations allowed in one bucket MetricOperationsMaxLength = 3 )
const ( // SectionTestTrue is a name for "stats.TestAlwaysTrue" test callback function SectionTestTrue = "true" // SectionTestIsNumeric is a name for "stats.TestIsNumeric" test callback function SectionTestIsNumeric = "numeric" // SectionTestIsNotEmpty is a name for "stats.TestIsNotEmpty" test callback function SectionTestIsNotEmpty = "not_empty" )
Variables ¶
var ( // ErrInvalidFormat error indicates that sections string has invalid format ErrInvalidFormat = errors.New("invalid sections format") // ErrUnknownSectionTest error indicates that section has unknown test callback name ErrUnknownSectionTest = errors.New("unknown section test") // ErrLooksLikeID error indicates that second level ID auto-discover found suspicious metric ErrLooksLikeID = errors.New("metric looks like ID") )
Functions ¶
func RegisterSectionTest ¶
func RegisterSectionTest(name string, callback SectionTestCallback)
RegisterSectionTest registers new section test callback function with its name
func SanitizeMetricName ¶
SanitizeMetricName modifies metric name to work well with statsd
func TestAlwaysTrue ¶
func TestAlwaysTrue(PathSection) bool
TestAlwaysTrue section test callback function that gives true result to any section
func TestIsNotEmpty ¶
func TestIsNotEmpty(s PathSection) bool
TestIsNotEmpty section test callback function that gives true result if section is not empty placeholder ("-")
func TestIsNumeric ¶
func TestIsNumeric(s PathSection) bool
TestIsNumeric section test callback function that gives true result if section is numeric
Types ¶
type Bucket ¶
type Bucket interface {
// Metric builds simple metric name in the form "<section>.<operation-0>.<operation-1>.<operation-2>"
Metric() string
// MetricWithSuffix builds metric name with success suffix in the form "<section>-ok|fail.<operation-0>.<operation-1>.<operation-2>"
MetricWithSuffix() string
// MetricTotal builds simple total metric name in the form total.<section>"
MetricTotal() string
// MetricTotalWithSuffix builds total metric name with success suffix in the form total-ok|fail.<section>"
MetricTotalWithSuffix() string
}
Bucket is an interface for building metric names for operations
type HTTPMetricNameAlterCallback ¶
type HTTPMetricNameAlterCallback func(metricParts *MetricOperation, r *http.Request) *MetricOperation
HTTPMetricNameAlterCallback is a type for HTTP Request metric alter handler
func NewHasIDAtSecondLevelCallback ¶
func NewHasIDAtSecondLevelCallback(config *SecondLevelIDConfig) HTTPMetricNameAlterCallback
NewHasIDAtSecondLevelCallback returns HttpMetricNameAlterCallback implementation that checks for IDs on the second level of HTTP Request path
type HTTPRequest ¶
type HTTPRequest struct {
*Plain
// contains filtered or unexported fields
}
HTTPRequest struct in an implementation of Bucket interface that produces metric names for HTTP Request. Metrics has the following formats for methods:
Metric() -> <section>.<method>.<path-level-0>.<path-level-1> MetricWithSuffix() -> <section>-ok|fail.<method>.<path-level-0>.<path-level-1> TotalRequests() -> total.<section> MetricTotalWithSuffix() -> total-ok|fail.<section>
Normally "<section>" is set to "request", but you can use any string value here.
func NewHTTPRequest ¶
func NewHTTPRequest(section string, r *http.Request, success bool, callback HTTPMetricNameAlterCallback, unicode bool) *HTTPRequest
NewHTTPRequest builds and returns new HTTPRequest instance
type MetricOperation ¶
type MetricOperation struct {
sync.Mutex
Labels map[string]string
// contains filtered or unexported fields
}
MetricOperation is a list of metric operations to use for metric
func BuildHTTPRequestMetricOperation ¶ added in v0.3.1
func BuildHTTPRequestMetricOperation(r *http.Request, callback HTTPMetricNameAlterCallback) *MetricOperation
BuildHTTPRequestMetricOperation builds metric operation from HTTP request
func NewMetricOperation ¶ added in v1.0.0
func NewMetricOperation(operations ...string) *MetricOperation
NewMetricOperation builds and returns new MetricOperation instance with defined label keys
func (*MetricOperation) WithLabels ¶ added in v1.0.0
func (m *MetricOperation) WithLabels(labels map[string]string) *MetricOperation
WithLabels adds label value to existing MetricOperation instance
type Plain ¶
type Plain struct {
// contains filtered or unexported fields
}
Plain struct in an implementation of Bucket interface that produces metric names for given section and operation
func NewPlain ¶
func NewPlain(section string, operation *MetricOperation, success, uniDecode bool) *Plain
NewPlain builds and returns new Plain instance
func (*Plain) Metric ¶
Metric builds simple metric name in the form:
<section>.<operation-0>.<operation-1>.<operation-2>
func (*Plain) MetricTotal ¶
MetricTotal builds simple total metric name in the form:
total.<section>
func (*Plain) MetricTotalWithSuffix ¶
MetricTotalWithSuffix builds total metric name with success suffix in the form
total-ok|fail.<section>
func (*Plain) MetricWithSuffix ¶
MetricWithSuffix builds metric name with success suffix in the form:
<section>-ok|fail.<operation-0>.<operation-1>.<operation-2>
type Prometheus ¶ added in v1.0.0
type Prometheus struct {
// contains filtered or unexported fields
}
Prometheus struct in an implementation of Bucket interface that produces metric names with labels for given section and operation
func NewPrometheus ¶ added in v1.0.0
func NewPrometheus(section string, operation *MetricOperation, success, uniDecode bool) *Prometheus
NewPrometheus builds and returns new Prometheus instance
func (*Prometheus) Metric ¶ added in v1.0.0
func (b *Prometheus) Metric() string
Metric builds simple metric name in the form:
<section>_<operation-0>_<operation-1>_<operation-2>
func (*Prometheus) MetricTotal ¶ added in v1.0.0
func (b *Prometheus) MetricTotal() string
MetricTotal builds simple total metric name in the form:
total.<section>
func (*Prometheus) MetricTotalWithSuffix ¶ added in v1.0.0
func (b *Prometheus) MetricTotalWithSuffix() string
MetricTotalWithSuffix builds total metric name with success suffix in the form
total-ok|fail_<section>
func (*Prometheus) MetricWithSuffix ¶ added in v1.0.0
func (b *Prometheus) MetricWithSuffix() string
MetricWithSuffix builds metric name with success suffix in the form:
<section>-ok|fail.<operation-0>.<operation-1>.<operation-2>
type SecondLevelIDConfig ¶ added in v0.4.0
type SecondLevelIDConfig struct {
HasIDAtSecondLevel SectionsTestsMap
AutoDiscoverThreshold uint
AutoDiscoverWhiteList []string
// contains filtered or unexported fields
}
SecondLevelIDConfig configuration struct for second level ID callback
type SectionTestCallback ¶
type SectionTestCallback func(PathSection) bool
SectionTestCallback type represents section test callback function
func GetSectionTestCallback ¶
func GetSectionTestCallback(name string) SectionTestCallback
GetSectionTestCallback returns section test callback function by name
type SectionTestDefinition ¶
type SectionTestDefinition struct {
Name string
Callback SectionTestCallback
}
SectionTestDefinition type represents section test callback definition
type SectionsTestsMap ¶
type SectionsTestsMap map[PathSection]SectionTestDefinition
SectionsTestsMap type represents section test callbacks definitions map
func ParseSectionsTestsMap ¶
func ParseSectionsTestsMap(s string) (SectionsTestsMap, error)
ParseSectionsTestsMap parses string into SectionsTestsMap. In most cases string comes as config to the application e.g. from env. Valid string formats are: 1. <section-0>:<test-callback-name-0>:<section-1>:<test-callback-name-1>:<section-2>:<test-callback-name-2> 2. <section-0>:<test-callback-name-0>\n<section-1>:<test-callback-name-1>\n<section-2>:<test-callback-name-2> 3. <section-0>:<test-callback-name-0>:<section-1>:<test-callback-name-1>\n<section-2>:<test-callback-name-2>
func (SectionsTestsMap) String ¶
func (m SectionsTestsMap) String() string
String returns pretty formatted string representation of SectionsTestsMap