@@ -95,6 +95,28 @@ test "otlp HTTPClient uncompressed protobuf metrics payload" {
95
95
try otlp .Export (allocator , config , otlp.Signal.Data { .metrics = req });
96
96
}
97
97
98
+ test "otlp HTTPClient compressed protobuf metrics payload" {
99
+ const allocator = std .testing .allocator ;
100
+
101
+ var server = try HTTPTestServer .init (allocator , assertCompressionHeaderGzip );
102
+ defer server .deinit ();
103
+
104
+ const thread = try std .Thread .spawn (.{}, HTTPTestServer .processSingleRequest , .{server });
105
+ defer thread .join ();
106
+
107
+ const config = try ConfigOptions .init (allocator );
108
+ defer config .deinit ();
109
+ const endpoint = try std .fmt .allocPrint (allocator , "127.0.0.1:{d}" , .{server .port ()});
110
+ defer allocator .free (endpoint );
111
+ config .endpoint = endpoint ;
112
+
113
+ config .compression = otlp .Compression .gzip ;
114
+ const req = try oneDataPointMetricsExportRequest (allocator );
115
+ defer req .deinit ();
116
+
117
+ try otlp .Export (allocator , config , otlp.Signal.Data { .metrics = req });
118
+ }
119
+
98
120
fn emptyMetricsExportRequest (allocator : std.mem.Allocator ) ! pbcollector_metrics.ExportMetricsServiceRequest {
99
121
const rm = try allocator .alloc (pbmetrics .ResourceMetrics , 1 );
100
122
const rm0 = pbmetrics.ResourceMetrics {
@@ -179,12 +201,28 @@ fn assertUncompressedProtobufMetricsBodyCanBeParsed(request: *http.Server.Reques
179
201
};
180
202
defer proto .deinit ();
181
203
if (proto .resource_metrics .items .len != 1 ) {
182
- std .debug .print ("otlp HTTP test - decoded protobuf: {}\n " , proto );
204
+ std .debug .print ("otlp HTTP test - decoded protobuf: {}\n " , .{ proto } );
183
205
return AssertionError .ProtobufBodyMismatch ;
184
206
}
185
207
try request .respond ("" , .{ .status = .ok });
186
208
}
187
209
210
+ fn assertCompressionHeaderGzip (request : * http.Server.Request ) anyerror ! void {
211
+ var headers = request .iterateHeaders ();
212
+ while (headers .next ()) | header | {
213
+ if (std .mem .eql (u8 , header .name , "accept-encoding" )) {
214
+ const content_encoding = header .value ;
215
+ if (! std .mem .eql (u8 , content_encoding , "gzip" )) {
216
+ std .debug .print ("otlp HTTP test - compression header mismatch, want 'gzip' got '{s}'\n " , .{content_encoding });
217
+ return AssertionError .CompressionMismatch ;
218
+ }
219
+ try request .respond ("" , .{ .status = .ok });
220
+ return ;
221
+ }
222
+ }
223
+ return AssertionError .CompressionMismatch ;
224
+ }
225
+
188
226
const HTTPTestServer = struct {
189
227
const Self = @This ();
190
228
0 commit comments