@@ -26,6 +26,7 @@ pub mod target;
2626use crate :: metrics:: ALERTS_STATES ;
2727use crate :: storage;
2828use crate :: utils:: uid;
29+ use crate :: CONFIG ;
2930
3031pub use self :: rule:: Rule ;
3132use self :: target:: Target ;
@@ -66,8 +67,8 @@ impl Alert {
6667 ALERTS_STATES
6768 . with_label_values ( & [
6869 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 ( ) ,
7172 ] )
7273 . inc ( ) ;
7374 for target in & self . targets {
@@ -78,7 +79,13 @@ impl Alert {
7879 }
7980
8081 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+ ) ;
8187 let deployment_id = storage:: StorageMetadata :: global ( ) . deployment_id ;
88+ let deployment_mode = storage:: StorageMetadata :: global ( ) . mode . to_string ( ) ;
8289 let additional_labels =
8390 serde_json:: to_value ( rule) . expect ( "rule is perfectly deserializable" ) ;
8491 let mut flatten_additional_labels = serde_json:: json!( { } ) ;
@@ -93,11 +100,13 @@ impl Alert {
93100
94101 Context :: new (
95102 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) ,
101110 flatten_additional_labels,
102111 )
103112 }
@@ -110,44 +119,86 @@ pub trait CallableTarget {
110119#[ derive( Debug , Clone ) ]
111120pub struct Context {
112121 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 ,
118124 additional_labels : serde_json:: Value ,
119125}
120126
121127impl Context {
122128 pub fn new (
123129 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 ,
129132 additional_labels : serde_json:: Value ,
130133 ) -> Self {
131134 Self {
132135 stream,
133- alert_name,
134- message,
135- reason,
136- alert_state,
137- deployment_id,
136+ alert_info,
137+ deployment_info,
138138 additional_labels,
139139 }
140140 }
141141
142142 fn default_alert_string ( & self ) -> String {
143143 format ! (
144144 "{} 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
146149 )
147150 }
148151
149152 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+ }
151202 }
152203}
153204
0 commit comments