gzip working

This commit is contained in:
Simon Larsen 2023-10-10 14:41:20 +01:00
parent 32960b90f8
commit 1892d06cec
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
6 changed files with 64 additions and 42 deletions

View File

@ -33,7 +33,7 @@ import { DashboardApiRoute } from 'Common/ServiceRoute';
import HTTPResponse from 'Common/Types/API/HTTPResponse';
import HTTPErrorResponse from 'Common/Types/API/HTTPErrorResponse';
import ServerException from 'Common/Types/Exception/ServerException';
import zlib from 'zlib';
// import zlib from 'zlib';
// import OpenTelemetrySDK from "./OpenTelemetry";
const app: ExpressApplication = Express.getExpressApp();
@ -98,19 +98,19 @@ app.use(setDefaultHeaders);
*/
app.use(function (req, res, next) {
if (req.headers['content-encoding'] === 'gzip') {
var gunzip = zlib.createGunzip();
req.pipe(gunzip);
var buffer: any = [];
gunzip.on('data', function (data) {
buffer.push(data.toString());
}).on('end', function () {
req.body = buffer;
// var gunzip = zlib.createGunzip();
// req.pipe(gunzip);
// var buffer: any = [];
// gunzip.on('data', function (data) {
// buffer.push(data.toString());
// }).on('end', function () {
// req.body = buffer.join('');
// next();
// }).on('error', function (e) {
// next(e);
// });
next();
}).on('error', function (e) {
next(e);
});
} else {
jsonBodyParserMiddleware(req, res, next);
}

View File

@ -7,7 +7,7 @@ import Express, {
import Response from 'CommonServer/Utils/Response';
import logger from 'CommonServer/Utils/Logger';
import protobuf from 'protobufjs';
import zlib from 'zlib';
// Load proto file for OTel
// Create a root namespace
@ -32,22 +32,36 @@ router.post(
): Promise<void> => {
try {
logger.info('OTelIngest URL: ', req.url);
let buffers: any = [];
req.on('data', (chunk) => {
buffers.push(chunk);
});
req.on('end', () => {
let buffer = Buffer.concat(buffers);
zlib.gunzip(buffer, (err, decoded) => {
if (err) {
console.error(err);
res.status(500).send('Error decompressing data');
return;
}
if (req.url === '/otel/v1/traces') {
const traces = TracesData.decode(req.body);
const traces = TracesData.decode(decoded);
logger.info('Traces: ', traces);
}
if (req.url === '/otel/v1/logs') {
const logs = LogsData.decode(req.body);
const logs = LogsData.decode(decoded);
logger.info('Logs: ', logs);
}
if (req.url === '/otel/v1/metrics') {
const metrics = MetricsData.decode(req.body);
const metrics = MetricsData.decode(decoded);
logger.info('Metrics: ', metrics);
}
@ -55,6 +69,14 @@ router.post(
// middleware marks the probe as alive.
// so we don't need to do anything here.
return Response.sendEmptyResponse(req, res);
});
});
logger.info('OTelIngest URL: ', req.url);
} catch (err) {
return next(err);
}

View File

@ -16,8 +16,8 @@ syntax = "proto3";
package opentelemetry.proto.logs.v1;
import "opentelemetry/proto/common/v1/common.proto";
import "opentelemetry/proto/resource/v1/resource.proto";
import "./common.proto";
import "./resource.proto";
option csharp_namespace = "OpenTelemetry.Proto.Logs.V1";
option java_multiple_files = true;

View File

@ -16,8 +16,8 @@ syntax = "proto3";
package opentelemetry.proto.metrics.v1;
import "opentelemetry/proto/common/v1/common.proto";
import "opentelemetry/proto/resource/v1/resource.proto";
import "./common.proto";
import "./resource.proto";
option csharp_namespace = "OpenTelemetry.Proto.Metrics.V1";
option java_multiple_files = true;

View File

@ -16,7 +16,7 @@ syntax = "proto3";
package opentelemetry.proto.resource.v1;
import "opentelemetry/proto/common/v1/common.proto";
import "./common.proto";
option csharp_namespace = "OpenTelemetry.Proto.Resource.V1";
option java_multiple_files = true;

View File

@ -16,8 +16,8 @@ syntax = "proto3";
package opentelemetry.proto.trace.v1;
import "opentelemetry/proto/common/v1/common.proto";
import "opentelemetry/proto/resource/v1/resource.proto";
import "./common.proto";
import "./resource.proto";
option csharp_namespace = "OpenTelemetry.Proto.Trace.V1";
option java_multiple_files = true;