Skip to content

Commit 7db5472

Browse files
committed
Enforce body storage max size
1 parent db13583 commit 7db5472

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/ServiceControl.Audit.Persistence.PostgreSQL/UnitOfWork/PostgreSQLAuditIngestionUnitOfWork.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ class PostgreSQLAuditIngestionUnitOfWork : IAuditIngestionUnitOfWork
1414
{
1515
readonly NpgsqlBatch batch;
1616
readonly NpgsqlConnection connection;
17+
readonly DatabaseConfiguration databaseConfiguration;
1718

18-
public PostgreSQLAuditIngestionUnitOfWork(NpgsqlConnection connection)
19+
public PostgreSQLAuditIngestionUnitOfWork(NpgsqlConnection connection, DatabaseConfiguration databaseConfiguration)
1920
{
2021
batch = new NpgsqlBatch(connection);
2122
this.connection = connection;
23+
this.databaseConfiguration = databaseConfiguration;
2224
}
2325

2426
public async ValueTask DisposeAsync()
@@ -47,7 +49,7 @@ INSERT INTO processed_messages (
4749
);";
4850

4951
processedMessage.MessageMetadata["ContentLength"] = body.Length;
50-
if (!body.IsEmpty)
52+
if (!body.IsEmpty && body.Length <= databaseConfiguration.MaxBodySizeToStore)
5153
{
5254
cmd.Parameters.AddWithValue("body", body);
5355
}

src/ServiceControl.Audit.Persistence.PostgreSQL/UnitOfWork/PostgreSQLAuditIngestionUnitOfWorkFactory.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@ namespace ServiceControl.Audit.Persistence.PostgreSQL.UnitOfWork;
55
using ServiceControl.Audit.Persistence.UnitOfWork;
66
using ServiceControl.Audit.Persistence.PostgreSQL;
77

8-
class PostgreSQLAuditIngestionUnitOfWorkFactory : IAuditIngestionUnitOfWorkFactory
8+
class PostgreSQLAuditIngestionUnitOfWorkFactory(PostgreSQLConnectionFactory connectionFactory, DatabaseConfiguration databaseConfiguration) : IAuditIngestionUnitOfWorkFactory
99
{
10-
readonly PostgreSQLConnectionFactory connectionFactory;
11-
12-
public PostgreSQLAuditIngestionUnitOfWorkFactory(PostgreSQLConnectionFactory connectionFactory)
13-
{
14-
this.connectionFactory = connectionFactory;
15-
}
16-
1710
public async ValueTask<IAuditIngestionUnitOfWork> StartNew(int batchSize, CancellationToken cancellationToken)
1811
{
1912
var connection = await connectionFactory.OpenConnection(cancellationToken);
20-
return new PostgreSQLAuditIngestionUnitOfWork(connection);
13+
return new PostgreSQLAuditIngestionUnitOfWork(connection, databaseConfiguration);
2114
}
2215

2316
public bool CanIngestMore() => true;

0 commit comments

Comments
 (0)