alerting.go
alerting.go - Overview
-
Overview This file defines the data structures and related methods for managing and representing alert states, rule state history, and related information in the SigNoz query service. It includes definitions for alert states (inactive, pending, firing, etc.), history of rule states, and data structures used for querying and representing this history.
-
Detailed Documentation
AlertState
- Purpose:
AlertState
is an enumerated type representing the state of an active alert. - Type:
int
type AlertState int
StateInactive
- Purpose: Represents the inactive alert state.
- Type:
AlertState
const (
StateInactive AlertState = iota
StatePending
StateFiring
StateNoData
StateDisabled
)
StatePending
- Purpose: Represents the pending alert state.
- Type:
AlertState
const (
StateInactive AlertState = iota
StatePending
StateFiring
StateNoData
StateDisabled
)
StateFiring
- Purpose: Represents the firing alert state.
- Type:
AlertState
const (
StateInactive AlertState = iota
StatePending
StateFiring
StateNoData
StateDisabled
)
StateNoData
- Purpose: Represents the no data alert state.
- Type:
AlertState
const (
StateInactive AlertState = iota
StatePending
StateFiring
StateNoData
StateDisabled
)
StateDisabled
- Purpose: Represents the disabled alert state.
- Type:
AlertState
const (
StateInactive AlertState = iota
StatePending
StateFiring
StateNoData
StateDisabled
)
AlertState.String()
- Purpose: Returns the string representation of the
AlertState
. - Parameters:
s
(AlertState): The alert state to convert to a string.
- Returns:
string
: The string representation of the alert state (e.g., "inactive", "pending").
func (s AlertState) String() string
AlertState.MarshalJSON()
- Purpose: Marshals the
AlertState
to JSON. - Parameters:
s
(AlertState): The alert state to marshal.
- Returns:
[]byte
: The JSON representation of the alert state.error
: An error if marshalling fails.
func (s AlertState) MarshalJSON() ([]byte, error)
AlertState.UnmarshalJSON()
- Purpose: Unmarshals JSON into an
AlertState
. - Parameters:
b
([]byte): The JSON data to unmarshal.s
(*AlertState): A pointer to the AlertState to populate.
- Returns:
error
: An error if unmarshalling fails.
func (s *AlertState) UnmarshalJSON(b []byte) error
AlertState.Scan()
- Purpose: Implements the
sql.Scanner
interface forAlertState
. - Parameters:
value
(interface<>): The value to scan from the database.s
(*AlertState): A pointer to the AlertState to populate.
- Returns:
error
: An error if scanning fails.
func (s *AlertState) Scan(value interface{}) error
AlertState.Value()
- Purpose: Implements the
driver.Valuer
interface forAlertState
. - Parameters:
s
(*AlertState): A pointer to the AlertState.
- Returns:
driver.Value
: The driver value.error
: An error if retrieving the value fails.
func (s *AlertState) Value() (driver.Value, error)
LabelsString
- Purpose:
LabelsString
is a custom type for handling labels as a JSON string. - Type:
string
type LabelsString string
LabelsString.MarshalJSON()
- Purpose: Marshals the
LabelsString
to JSON. - Parameters:
l
(*LabelsString): A pointer to the LabelsString to marshal.
- Returns:
[]byte
: The JSON representation of the labels.error
: An error if marshalling fails.
func (l *LabelsString) MarshalJSON() ([]byte, error)
LabelsString.Scan()
- Purpose: Implements the
sql.Scanner
interface forLabelsString
. - Parameters:
src
(interface<>): The value to scan from the database.l
(*LabelsString): A pointer to the LabelsString to populate.
- Returns:
error
: An error if scanning fails.
func (l *LabelsString) Scan(src interface{}) error
LabelsString.String()
- Purpose: Returns the string representation of
LabelsString
. - Parameters:
l
(LabelsString): The LabelsString to convert to a string.
- Returns:
string
: The string representation of the labels.
func (l LabelsString) String() string
RuleStateTimeline
- Purpose: Represents a timeline of rule states.
type RuleStateTimeline struct {
Items []RuleStateHistory `json:"items"`
Total uint64 `json:"total"`
Labels map[string][]string `json:"labels"`
}
- Fields:
Items
([]RuleStateHistory
): A slice ofRuleStateHistory
items representing the history.Total
(uint64): The total number of items in the timeline.Labels
(map[string][]string): Labels associated with the timeline.
RuleStateHistory
- Purpose: Represents a single entry in the rule state history.
type RuleStateHistory struct {
RuleID string `json:"ruleID" ch:"rule_id"`
RuleName string `json:"ruleName" ch:"rule_name"`
// One of ["normal", "firing"]
OverallState AlertState `json:"overallState" ch:"overall_state"`
OverallStateChanged bool `json:"overallStateChanged" ch:"overall_state_changed"`
// One of ["normal", "firing", "no_data", "muted"]
State AlertState `json:"state" ch:"state"`
StateChanged bool `json:"stateChanged" ch:"state_changed"`
UnixMilli int64 `json:"unixMilli" ch:"unix_milli"`
Labels LabelsString `json:"labels" ch:"labels"`
Fingerprint uint64 `json:"fingerprint" ch:"fingerprint"`
Value float64 `json:"value" ch:"value"`
RelatedTracesLink string `json:"relatedTracesLink"`
RelatedLogsLink string `json:"relatedLogsLink"`
}
- Fields:
RuleID
(string): The ID of the rule.RuleName
(string): The name of the rule.OverallState
(AlertState): The overall state of the rule.OverallStateChanged
(bool): Indicates if the overall state has changed.State
(AlertState): The state of the rule.StateChanged
(bool): Indicates if the state has changed.UnixMilli
(int64): The Unix timestamp in milliseconds.Labels
(LabelsString): Labels associated with the rule state.Fingerprint
(uint64): A unique fingerprint for the rule state.Value
(float64): The value associated with the rule state.RelatedTracesLink
(string): Link to related traces.RelatedLogsLink
(string): Link to related logs.
QueryRuleStateHistory
- Purpose: Represents a query for rule state history.
type QueryRuleStateHistory struct {
Start int64 `json:"start"`
End int64 `json:"end"`
State string `json:"state"`
Filters *v3.FilterSet `json:"filters"`
Offset int64 `json:"offset"`
Limit int64 `json:"limit"`
Order string `json:"order"`
}
- Fields:
Start
(int64): The start timestamp for the query.End
(int64): The end timestamp for the query.State
(string): The state to filter by.Filters
(*v3.FilterSet): Filters to apply to the query.Offset
(int64): The offset for pagination.Limit
(int64): The limit for pagination.Order
(string): The order of the results ("asc" or "desc").
QueryRuleStateHistory.Validate()
- Purpose: Validates the
QueryRuleStateHistory
struct. - Parameters:
r
(*QueryRuleStateHistory): A pointer to the QueryRuleStateHistory to validate.
- Returns:
error
: An error if validation fails.
func (r *QueryRuleStateHistory) Validate() error
RuleStateHistoryContributor
- Purpose: Represents a contributor to the rule state history.
type RuleStateHistoryContributor struct {
Fingerprint uint64 `json:"fingerprint" ch:"fingerprint"`
Labels LabelsString `json:"labels" ch:"labels"`
Count uint64 `json:"count" ch:"count"`
RelatedTracesLink string `json:"relatedTracesLink"`
RelatedLogsLink string `json:"relatedLogsLink"`
}
- Fields:
Fingerprint
(uint64): A unique fingerprint.Labels
(LabelsString): Labels associated with the contributor.Count
(uint64): The count of the contributor.RelatedTracesLink
(string): Link to related traces.RelatedLogsLink
(string): Link to related logs.
RuleStateTransition
- Purpose: Represents a transition in the rule state.
type RuleStateTransition struct {
RuleID string `json:"ruleID" ch:"rule_id"`
State AlertState `json:"state" ch:"state"`
FiringTime int64 `json:"firingTime" ch:"firing_time"`
ResolutionTime int64 `json:"resolutionTime" ch:"resolution_time"`
}
- Fields:
RuleID
(string): The ID of the rule.State
(AlertState): The new state of the rule.FiringTime
(int64): The timestamp when the rule started firing.ResolutionTime
(int64): The timestamp when the rule was resolved.
ReleStateItem
- Purpose: Represents an item of the rule state.
type ReleStateItem struct {
State AlertState `json:"state"`
Start int64 `json:"start"`
End int64 `json:"end"`
}
- Fields:
State
(AlertState
): The alert state.Start
(int64
): The start timestamp.End
(int64
): The end timestamp.
Stats
- Purpose: Represents statistics related to alerting triggers and resolution times.
type Stats struct {
TotalCurrentTriggers uint64 `json:"totalCurrentTriggers"`
TotalPastTriggers uint64 `json:"totalPastTriggers"`
CurrentTriggersSeries *v3.Series `json:"currentTriggersSeries"`
PastTriggersSeries *v3.Series `json:"pastTriggersSeries"`
CurrentAvgResolutionTime string `json:"currentAvgResolutionTime"`
PastAvgResolutionTime string `json:"pastAvgResolutionTime"`
CurrentAvgResolutionTimeSeries *v3.Series `json:"currentAvgResolutionTimeSeries"`
PastAvgResolutionTimeSeries *v3.Series `json:"pastAvgResolutionTimeSeries"`
}
- Fields:
TotalCurrentTriggers
(uint64): Total number of current triggers.TotalPastTriggers
(uint64): Total number of past triggers.CurrentTriggersSeries
(*v3.Series): Time series data for current triggers.PastTriggersSeries
(*v3.Series): Time series data for past triggers.CurrentAvgResolutionTime
(string): Average resolution time for current triggers.PastAvgResolutionTime
(string): Average resolution time for past triggers.CurrentAvgResolutionTimeSeries
(*v3.Series): Time series data for current average resolution time.PastAvgResolutionTimeSeries
(*v3.Series): Time series data for past average resolution time.
Include in Getting Started: NO