@@ -49,6 +49,13 @@ pub const DEFAULT_ENCODING: &str = "snappy";
49
49
pub const VM_ENCODING : & str = "zstd" ;
50
50
pub const VM_PROTO_VERSION : & str = "1" ;
51
51
52
+ #[ derive( Clone ) ]
53
+ pub struct PromStoreState {
54
+ pub prom_store_handler : PromStoreProtocolHandlerRef ,
55
+ pub prom_store_with_metric_engine : bool ,
56
+ pub is_strict_mode : bool ,
57
+ }
58
+
52
59
#[ derive( Debug , Serialize , Deserialize ) ]
53
60
pub struct RemoteWriteQuery {
54
61
pub db : Option < String > ,
@@ -69,99 +76,32 @@ impl Default for RemoteWriteQuery {
69
76
}
70
77
}
71
78
72
- /// Same with [remote_write] but won't store data to metric engine.
73
- #[ axum_macros:: debug_handler]
74
- pub async fn route_write_without_metric_engine (
75
- handler : State < PromStoreProtocolHandlerRef > ,
76
- query : Query < RemoteWriteQuery > ,
77
- extension : Extension < QueryContext > ,
78
- content_encoding : TypedHeader < headers:: ContentEncoding > ,
79
- raw_body : Bytes ,
80
- ) -> Result < impl IntoResponse > {
81
- remote_write_impl (
82
- handler,
83
- query,
84
- extension,
85
- content_encoding,
86
- raw_body,
87
- true ,
88
- false ,
89
- )
90
- . await
91
- }
92
-
93
- /// Same with [remote_write] but won't store data to metric engine.
94
- /// And without strict_mode on will not check invalid UTF-8.
95
- #[ axum_macros:: debug_handler]
96
- pub async fn route_write_without_metric_engine_and_strict_mode (
97
- handler : State < PromStoreProtocolHandlerRef > ,
98
- query : Query < RemoteWriteQuery > ,
99
- extension : Extension < QueryContext > ,
100
- content_encoding : TypedHeader < headers:: ContentEncoding > ,
101
- raw_body : Bytes ,
102
- ) -> Result < impl IntoResponse > {
103
- remote_write_impl (
104
- handler,
105
- query,
106
- extension,
107
- content_encoding,
108
- raw_body,
109
- false ,
110
- false ,
111
- )
112
- . await
113
- }
114
-
115
79
#[ axum_macros:: debug_handler]
116
80
#[ tracing:: instrument(
117
81
skip_all,
118
82
fields( protocol = "prometheus" , request_type = "remote_write" )
119
83
) ]
120
84
pub async fn remote_write (
121
- handler : State < PromStoreProtocolHandlerRef > ,
122
- query : Query < RemoteWriteQuery > ,
123
- extension : Extension < QueryContext > ,
124
- content_encoding : TypedHeader < headers:: ContentEncoding > ,
125
- raw_body : Bytes ,
126
- ) -> Result < impl IntoResponse > {
127
- remote_write_impl (
128
- handler,
129
- query,
130
- extension,
131
- content_encoding,
132
- raw_body,
133
- true ,
134
- true ,
135
- )
136
- . await
137
- }
138
-
139
- #[ axum_macros:: debug_handler]
140
- #[ tracing:: instrument(
141
- skip_all,
142
- fields( protocol = "prometheus" , request_type = "remote_write" )
143
- ) ]
144
- pub async fn remote_write_without_strict_mode (
145
- handler : State < PromStoreProtocolHandlerRef > ,
85
+ State ( state) : State < PromStoreState > ,
146
86
query : Query < RemoteWriteQuery > ,
147
87
extension : Extension < QueryContext > ,
148
88
content_encoding : TypedHeader < headers:: ContentEncoding > ,
149
89
raw_body : Bytes ,
150
90
) -> Result < impl IntoResponse > {
151
91
remote_write_impl (
152
- handler ,
92
+ state . prom_store_handler ,
153
93
query,
154
94
extension,
155
95
content_encoding,
156
96
raw_body,
157
- false ,
158
- true ,
97
+ state . is_strict_mode ,
98
+ state . prom_store_with_metric_engine ,
159
99
)
160
100
. await
161
101
}
162
102
163
103
async fn remote_write_impl (
164
- State ( handler) : State < PromStoreProtocolHandlerRef > ,
104
+ handler : PromStoreProtocolHandlerRef ,
165
105
Query ( params) : Query < RemoteWriteQuery > ,
166
106
Extension ( mut query_ctx) : Extension < QueryContext > ,
167
107
content_encoding : TypedHeader < headers:: ContentEncoding > ,
@@ -222,7 +162,7 @@ impl IntoResponse for PromStoreResponse {
222
162
fields( protocol = "prometheus" , request_type = "remote_read" )
223
163
) ]
224
164
pub async fn remote_read (
225
- State ( handler ) : State < PromStoreProtocolHandlerRef > ,
165
+ State ( state ) : State < PromStoreState > ,
226
166
Query ( params) : Query < RemoteWriteQuery > ,
227
167
Extension ( mut query_ctx) : Extension < QueryContext > ,
228
168
body : Bytes ,
@@ -236,7 +176,7 @@ pub async fn remote_read(
236
176
237
177
let request = decode_remote_read_request ( body) . await ?;
238
178
239
- handler . read ( request, query_ctx) . await
179
+ state . prom_store_handler . read ( request, query_ctx) . await
240
180
}
241
181
242
182
fn try_decompress ( is_zstd : bool , body : & [ u8 ] ) -> Result < Bytes > {
0 commit comments