@@ -26,6 +26,7 @@ pub mod target;
26
26
use crate :: metrics:: ALERTS_STATES ;
27
27
use crate :: storage;
28
28
use crate :: utils:: uid;
29
+ use crate :: CONFIG ;
29
30
30
31
pub use self :: rule:: Rule ;
31
32
use self :: target:: Target ;
@@ -66,8 +67,8 @@ impl Alert {
66
67
ALERTS_STATES
67
68
. with_label_values ( & [
68
69
context. stream . as_str ( ) ,
69
- context. alert_name . as_str ( ) ,
70
- context. alert_state . to_string ( ) . as_str ( ) ,
70
+ context. alert_info . alert_name . as_str ( ) ,
71
+ context. alert_info . alert_state . to_string ( ) . as_str ( ) ,
71
72
] )
72
73
. inc ( ) ;
73
74
for target in & self . targets {
@@ -78,7 +79,13 @@ impl Alert {
78
79
}
79
80
80
81
fn get_context ( & self , stream_name : String , alert_state : AlertState , rule : & Rule ) -> Context {
82
+ let deployment_instance = format ! (
83
+ "{}://{}" ,
84
+ CONFIG . parseable. get_scheme( ) ,
85
+ CONFIG . parseable. address
86
+ ) ;
81
87
let deployment_id = storage:: StorageMetadata :: global ( ) . deployment_id ;
88
+ let deployment_mode = storage:: StorageMetadata :: global ( ) . mode . to_string ( ) ;
82
89
let additional_labels =
83
90
serde_json:: to_value ( rule) . expect ( "rule is perfectly deserializable" ) ;
84
91
let mut flatten_additional_labels = serde_json:: json!( { } ) ;
@@ -93,11 +100,13 @@ impl Alert {
93
100
94
101
Context :: new (
95
102
stream_name,
96
- self . name . clone ( ) ,
97
- self . message . clone ( ) ,
98
- self . rule . trigger_reason ( ) ,
99
- alert_state,
100
- deployment_id,
103
+ AlertInfo :: new (
104
+ self . name . clone ( ) ,
105
+ self . message . clone ( ) ,
106
+ rule. trigger_reason ( ) ,
107
+ alert_state,
108
+ ) ,
109
+ DeploymentInfo :: new ( deployment_instance, deployment_id, deployment_mode) ,
101
110
flatten_additional_labels,
102
111
)
103
112
}
@@ -110,44 +119,86 @@ pub trait CallableTarget {
110
119
#[ derive( Debug , Clone ) ]
111
120
pub struct Context {
112
121
stream : String ,
113
- alert_name : String ,
114
- message : String ,
115
- reason : String ,
116
- alert_state : AlertState ,
117
- deployment_id : uid:: Uid ,
122
+ alert_info : AlertInfo ,
123
+ deployment_info : DeploymentInfo ,
118
124
additional_labels : serde_json:: Value ,
119
125
}
120
126
121
127
impl Context {
122
128
pub fn new (
123
129
stream : String ,
124
- alert_name : String ,
125
- message : String ,
126
- reason : String ,
127
- alert_state : AlertState ,
128
- deployment_id : uid:: Uid ,
130
+ alert_info : AlertInfo ,
131
+ deployment_info : DeploymentInfo ,
129
132
additional_labels : serde_json:: Value ,
130
133
) -> Self {
131
134
Self {
132
135
stream,
133
- alert_name,
134
- message,
135
- reason,
136
- alert_state,
137
- deployment_id,
136
+ alert_info,
137
+ deployment_info,
138
138
additional_labels,
139
139
}
140
140
}
141
141
142
142
fn default_alert_string ( & self ) -> String {
143
143
format ! (
144
144
"{} triggered on {}\n Message: {}\n Failing Condition: {}" ,
145
- self . alert_name, self . stream, self . message, self . reason
145
+ self . alert_info. alert_name,
146
+ self . stream,
147
+ self . alert_info. message,
148
+ self . alert_info. reason
146
149
)
147
150
}
148
151
149
152
fn default_resolved_string ( & self ) -> String {
150
- format ! ( "{} on {} is now resolved " , self . alert_name, self . stream)
153
+ format ! (
154
+ "{} on {} is now resolved " ,
155
+ self . alert_info. alert_name, self . stream
156
+ )
157
+ }
158
+ }
159
+
160
+ #[ derive( Debug , Clone ) ]
161
+ pub struct AlertInfo {
162
+ alert_name : String ,
163
+ message : String ,
164
+ reason : String ,
165
+ alert_state : AlertState ,
166
+ }
167
+
168
+ impl AlertInfo {
169
+ pub fn new (
170
+ alert_name : String ,
171
+ message : String ,
172
+ reason : String ,
173
+ alert_state : AlertState ,
174
+ ) -> Self {
175
+ Self {
176
+ alert_name,
177
+ message,
178
+ reason,
179
+ alert_state,
180
+ }
181
+ }
182
+ }
183
+
184
+ #[ derive( Debug , Clone ) ]
185
+ pub struct DeploymentInfo {
186
+ deployment_instance : String ,
187
+ deployment_id : uid:: Uid ,
188
+ deployment_mode : String ,
189
+ }
190
+
191
+ impl DeploymentInfo {
192
+ pub fn new (
193
+ deployment_instance : String ,
194
+ deployment_id : uid:: Uid ,
195
+ deployment_mode : String ,
196
+ ) -> Self {
197
+ Self {
198
+ deployment_instance,
199
+ deployment_id,
200
+ deployment_mode,
201
+ }
151
202
}
152
203
}
153
204
0 commit comments