Skip to content

Commit

Permalink
Making max payload size configurable (#1154)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigatk authored Oct 29, 2023
1 parent 70547cd commit d0e75e8
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@
import java.io.IOException;

public class GroupedResultsParser {
private static final int MAX_PAYLOAD_STRING_LENGTH = 50_000_000; // default is 20_000_000
public static final int DEFAULT_MAX_PAYLOAD_SIZE = 50_000_000; // Jackson default is 20_000_000

private final ObjectMapper mapper;

public GroupedResultsParser() {
this(DEFAULT_MAX_PAYLOAD_SIZE);
}

public GroupedResultsParser(Integer maxPayloadSize) {
this.mapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

this.mapper.getFactory()
.setStreamReadConstraints(StreamReadConstraints.builder().maxStringLength(MAX_PAYLOAD_STRING_LENGTH).build());
.setStreamReadConstraints(StreamReadConstraints.builder().maxStringLength(maxPayloadSize).build());
}

public GroupedResults parseGroupedResults(String groupedResultsBlob) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import projektor.parser.grouped.model.GroupedTestSuites
import projektor.parser.grouped.model.PerformanceResult
import projektor.parser.grouped.model.ResultsMetadata
import spock.lang.Specification
import spock.lang.Subject

class GroupedResultsParserSpec extends Specification {
@Subject
GroupedResultsParser groupedResultsParser = new GroupedResultsParser()
private int defaultMaxPayloadSize = 20_000_000
private int largeMaxPayloadSize = 50_000_000

private ObjectMapper mapper = new ObjectMapper()

def "should deserialize grouped results that were serialized"() {
given:
GroupedResultsParser groupedResultsParser = new GroupedResultsParser(defaultMaxPayloadSize)

List<GroupedTestSuites> groupedTestSuites = (1..3).collect { idx ->
new GroupedTestSuites(
groupName: "MyGroup${idx}",
Expand Down Expand Up @@ -56,6 +57,8 @@ class GroupedResultsParserSpec extends Specification {

def "should serialize grouped results"() {
given:
GroupedResultsParser groupedResultsParser = new GroupedResultsParser(defaultMaxPayloadSize)

List<GroupedTestSuites> groupedTestSuites = (1..2).collect { idx ->
new GroupedTestSuites(
groupName: "MyGroup${idx}",
Expand Down Expand Up @@ -83,6 +86,8 @@ class GroupedResultsParserSpec extends Specification {

def "should parse grouped results with all metadata"() {
given:
GroupedResultsParser groupedResultsParser = new GroupedResultsParser(defaultMaxPayloadSize)

List<GroupedTestSuites> groupedTestSuites = (1..2).collect { idx ->
new GroupedTestSuites(
groupName: "MyGroup${idx}",
Expand Down Expand Up @@ -120,6 +125,8 @@ class GroupedResultsParserSpec extends Specification {

def "should deserialize results with only performance results"() {
given:
GroupedResultsParser groupedResultsParser = new GroupedResultsParser(defaultMaxPayloadSize)

GroupedResults groupedResults = new GroupedResults()
groupedResults.metadata = new ResultsMetadata(
git: new GitMetadata(repoName: "my-repo", branchName: "main", isMainBranch: true)
Expand All @@ -138,6 +145,8 @@ class GroupedResultsParserSpec extends Specification {
}

def "should not fail on really large payloads"() {
GroupedResultsParser groupedResultsParser = new GroupedResultsParser(largeMaxPayloadSize)

String largeBlob = (1..5_000_000).collect { i -> i }.join()

GroupedTestSuites groupedTestSuite = new GroupedTestSuites(
Expand Down
4 changes: 3 additions & 1 deletion server/server-app/src/main/kotlin/projektor/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import projektor.parser.performance.PerformanceResultsParser
import projektor.performance.PerformanceResultsDatabaseRepository
import projektor.performance.PerformanceResultsRepository
import projektor.performance.PerformanceResultsService
import projektor.processing.ProcessingConfig
import projektor.quality.CodeQualityReportDatabaseRepository
import projektor.quality.CodeQualityReportRepository
import projektor.repository.coverage.RepositoryCoverageDatabaseRepository
Expand Down Expand Up @@ -78,6 +79,7 @@ fun createAppModule(
metricRegistry: MeterRegistry,
messageConfig: MessageConfig,
notificationConfig: NotificationConfig,
processingConfig: ProcessingConfig,
gitHubCommentService: GitHubCommentService?,
attachmentService: AttachmentService?
) = module {
Expand Down Expand Up @@ -111,7 +113,7 @@ fun createAppModule(

single { AppendTestResultsService(get(), get()) }
single { CoverageService(get(), get(), get(), get()) }
single { GroupedResultsParser() }
single { GroupedResultsParser(processingConfig.maxPayloadSize) }
single { PerformanceResultsParser() }
single { GroupedResultsConverter(get(), get(), get()) }
single { GroupedTestResultsService(get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
Expand Down
4 changes: 4 additions & 0 deletions server/server-app/src/main/kotlin/projektor/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import projektor.notification.github.comment.GitHubCommentClient
import projektor.notification.github.comment.GitHubCommentService
import projektor.organization.coverage.OrganizationCoverageService
import projektor.performance.PerformanceResultsService
import projektor.processing.ProcessingConfig
import projektor.quality.CodeQualityReportRepository
import projektor.repository.coverage.RepositoryCoverageService
import projektor.repository.performance.RepositoryPerformanceService
Expand Down Expand Up @@ -112,6 +113,8 @@ fun Application.main(meterRegistry: MeterRegistry? = null) {

val versionControlConfig = VersionControlConfig.createVersionControlConfig(applicationConfig)

val processingConfig = ProcessingConfig.createProcessingConfig(applicationConfig)

val notificationConfig = NotificationConfig.createNotificationConfig(applicationConfig)
val gitHubCommentService = conditionallyCreateGitHubCommentService(applicationConfig)

Expand All @@ -126,6 +129,7 @@ fun Application.main(meterRegistry: MeterRegistry? = null) {
metricRegistry = metricRegistry,
messageConfig = messageConfig,
notificationConfig = notificationConfig,
processingConfig = processingConfig,
gitHubCommentService = gitHubCommentService,
attachmentService = attachmentService
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package projektor.processing

import io.ktor.server.config.*
import projektor.parser.grouped.GroupedResultsParser

data class ProcessingConfig(val maxPayloadSize: Int) {
companion object {
fun createProcessingConfig(applicationConfig: ApplicationConfig): ProcessingConfig {
val maxPayloadSize: Int = applicationConfig.propertyOrNull("ktor.processing.maxPayloadSize")?.toString()?.toInt() ?: GroupedResultsParser.DEFAULT_MAX_PAYLOAD_SIZE

return ProcessingConfig(maxPayloadSize)
}
}
}
4 changes: 4 additions & 0 deletions server/server-app/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ ktor {
privateKey = ${?GITHUB_PRIVATE_KEY}
}
}

processing {
maxPayloadSize = ${?MAX_PAYLOAD_SIZE}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import projektor.metrics.InfluxMetricsConfig
import projektor.metrics.MetricsService
import projektor.metrics.createRegistry
import projektor.notification.NotificationConfig
import projektor.parser.grouped.GroupedResultsParser
import projektor.processing.ProcessingConfig
import java.util.TimeZone

open class DatabaseRepositoryTestCase : KoinTest {
Expand Down Expand Up @@ -120,6 +122,7 @@ open class DatabaseRepositoryTestCase : KoinTest {
createRegistry(metricsConfig),
MessageConfig(listOf()),
NotificationConfig(null),
ProcessingConfig(GroupedResultsParser.DEFAULT_MAX_PAYLOAD_SIZE),
null,
null
)
Expand Down

0 comments on commit d0e75e8

Please sign in to comment.