-
Notifications
You must be signed in to change notification settings - Fork 802
Templates
Message bodies in the notifiers are formatted according to the templates specified (either open or close templates). The format is the standard Golang text template. There are several good posts available on how to compose Golang templates:
- http://andlabs.lostsig.com/blog/go-templates/
- http://golangtutorials.blogspot.com/2011/06/go-templates.html
Every template is provided with a structure when it is compiled into a message. The following structure is what is provided to the templates:
struct {
Cluster string
Group string
ID string
Start time.Time
Extras map[string]string
Result *ConsumerGroupStatus
}
The Extras field is a map of the extra keys provided in the configuration.
Here are the structures that are used to build the ConsumerGroupStatus objects:
type ConsumerOffset struct {
// The offset that is stored
Offset int64 `json:"offset"`
// The timestamp at which the offset was committed
Timestamp int64 `json:"timestamp"`
// The number of messages that the consumer was behind at the time that the offset was committed. This number is
// not updated after the offset was committed, so it does not represent the current lag of the consumer.
Lag uint64 `json:"lag"`
}
type PartitionStatus struct {
// The topic name for this partition
Topic string `json:"topic"`
// The partition ID
Partition int32 `json:"partition"`
// If available (for active new consumers), the consumer host that currently owns this partiton
Owner string `json:"owner"`
// The status of the partition
Status StatusConstant `json:"status"`
// A ConsumerOffset object that describes the first (oldest) offset that Burrow is storing for this partition
Start *ConsumerOffset `json:"start"`
// A ConsumerOffset object that describes the last (latest) offset that Burrow is storing for this partition
End *ConsumerOffset `json:"end"`
// The current number of messages that the consumer is behind for this partition. This is calculated using the
// last committed offset and the current broker end offset
CurrentLag uint64 `json:"current_lag"`
// A number between 0.0 and 1.0 that describes the percentage complete the offset information is for this partition.
// For example, if Burrow has been configured to store 10 offsets, and Burrow has only stored 7 commits for this
// partition, Complete will be 0.7
Complete float32 `json:"complete"`
}
type ConsumerGroupStatus struct {
// The name of the cluster in which the group exists
Cluster string `json:"cluster"`
// The name of the consumer group
Group string `json:"group"`
// The status of the consumer group. This is either NOTFOUND, OK, WARN, or ERR. It is calculated from the highest
// Status for the individual partitions
Status StatusConstant `json:"status"`
// A number between 0.0 and 1.0 that describes the percentage complete the partition information is for this group.
// A partition that has a Complete value of less than 1.0 will be treated as zero.
Complete float32 `json:"complete"`
// A slice of PartitionStatus objects showing individual partition status. If the request ShowAll field was true,
// this slice will contain every partition consumed by the group. If ShowAll was false, this slice will only
// contain the partitions that have a status of WARN or above.
Partitions []*PartitionStatus `json:"partitions"`
// A count of the total number of partitions that the group has committed offsets for. Note, this may not be the
// same as the total number of partitions consumed by the group, if Burrow has not seen commits for all partitions
// yet.
TotalPartitions int `json:"partition_count"`
// A PartitionStatus object for the partition with the highest CurrentLag value
Maxlag *PartitionStatus `json:"maxlag"`
// The sum of all partition CurrentLag values for the group
TotalLag uint64 `json:"totallag"`
}
The StatusConstant type is an integer enum, and if you call the String() method on it (like {{.Status.String}}), you will get a text representation. You can also reference the integer values in the protocol/evaluator.go file.
There are several helper functions that are mapped into the template as well, in order to assist with compiling or formatting the information in the status object. For example, to call the jsonencoder helper on the Result.Partitions object:
{{jsonencoder .Result.Partitions}}
Function | Arguments | Return Value | Description |
---|---|---|---|
jsonencoder | any object | JSON encoded string | Encodes any object as a JSON string and returns that string |
classifyTopicsByStatus | slice of PartitionStatus objects | map of status name strings to slices of PartitionStatus objects | Sorts the provided PartitionStatus objects by their status value and returns the result as a map of status types to the sorted lists |
templateCountPartitions | slice of PartitionStatus objects | map of status name strings to integers | Sorts the provided PartitionStatus objects by their status value and returns a count of each status type present as a map |
templateAdd | two integers | integer | Adds the two provided integers together and returns the result. |
templateMinus | two integers | integer | Subtracts the second integer from the first and returns the result. |
templateMultiply | two integers | integer | Multiply the two provided integers together and returns the result. |
templateDivide | two integers | integer | Divide the first integer by the second integer and return the result. |
formatTimestamp | int64, time format string | string | Converts the provided int64 to a time.Time value and returns a formatted string for the Time using the provided format string. |