Skip to content

Commit

Permalink
chore: reduce amount of configuration passed to reports module
Browse files Browse the repository at this point in the history
  • Loading branch information
slandelle committed Dec 15, 2023
1 parent 1295d74 commit 10c557b
Show file tree
Hide file tree
Showing 22 changed files with 138 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ private final class RunResultProcessor(configuration: GatlingConfiguration) {
if (reportsGenerationEnabled) {
println("Generating reports...")
val reportsGenerationInputs = new ReportsGenerationInputs(runId, logFileData, assertionResults)
val indexFile = new ReportsGenerator(configuration).generateFor(reportsGenerationInputs)
val indexFile = new ReportsGenerator(configuration.data.zoneId, configuration.core.charset, configuration.core.directory, configuration.charting)
.generateFor(reportsGenerationInputs)
println(s"Reports generated, please open the following file: ${indexFile.toUri}")
}

Expand Down
2 changes: 1 addition & 1 deletion gatling-app/src/main/scala/io/gatling/app/Selection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object Selection {
if (configuration.core.directory.reportsOnly.isDefined) {
Nil
} else {
SimulationClassLoader(GatlingFiles.binariesDirectory(configuration)).simulationClasses.sortBy(_.canonicalName)
SimulationClassLoader(GatlingFiles.binariesDirectory(configuration.core.directory)).simulationClasses.sortBy(_.canonicalName)
}

singleSimulationFromConfig(simulationClasses, configDefinedSimulationClassName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.gatling.charts.component

import io.gatling.charts.stats.{ GeneralStats, Ranges }
import io.gatling.core.config.GatlingConfiguration
import io.gatling.core.config.IndicatorsConfiguration
import io.gatling.shared.util.NumberHelper._

private[charts] object Stats {
Expand Down Expand Up @@ -47,7 +47,7 @@ private[charts] final class RequestStatistics(
val meanNumberOfRequestsPerSecondStatistics: Stats[Double]
)

private[charts] final class DetailsStatsTableComponent(configuration: GatlingConfiguration) extends Component {
private[charts] final class DetailsStatsTableComponent(configuration: IndicatorsConfiguration) extends Component {
override def html: String = s"""
<div class="infos">
<div class="infos-in">
Expand Down Expand Up @@ -92,25 +92,25 @@ private[charts] final class DetailsStatsTableComponent(configuration: GatlingCon
<td id="minResponseTimeKO" class="ko"></td>
</tr>
<tr>
<td class="title">${configuration.charting.indicators.percentile1.toRank} percentile</td>
<td class="title">${configuration.percentile1.toRank} percentile</td>
<td id="percentiles1" class="total"></td>
<td id="percentiles1OK" class="ok"></td>
<td id="percentiles1KO" class="ko"></td>
</tr>
<tr>
<td class="title">${configuration.charting.indicators.percentile2.toRank} percentile</td>
<td class="title">${configuration.percentile2.toRank} percentile</td>
<td id="percentiles2" class="total"></td>
<td id="percentiles2OK" class="ok"></td>
<td id="percentiles2KO" class="ko"></td>
</tr>
<tr>
<td class="title">${configuration.charting.indicators.percentile3.toRank} percentile</td>
<td class="title">${configuration.percentile3.toRank} percentile</td>
<td id="percentiles3" class="total"></td>
<td id="percentiles3OK" class="ok"></td>
<td id="percentiles3KO" class="ko"></td>
</tr>
<tr>
<td class="title">${configuration.charting.indicators.percentile4.toRank} percentile</td>
<td class="title">${configuration.percentile4.toRank} percentile</td>
<td id="percentiles4" class="total"></td>
<td id="percentiles4OK" class="ok"></td>
<td id="percentiles4KO" class="ko"></td>
Expand Down Expand Up @@ -142,5 +142,5 @@ private[charts] final class DetailsStatsTableComponent(configuration: GatlingCon

val js = ""

val jsFiles: Seq[String] = Seq.empty
val jsFiles: Seq[String] = Nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ private[charts] final class ErrorsTableComponent(errors: Seq[ErrorStats]) extend
</div>
"""

def jsFiles: Seq[String] = Seq.empty
def jsFiles: Seq[String] = Nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,24 @@ package io.gatling.charts.component
import io.gatling.charts.config.ChartsFiles.AllRequestLineTitle
import io.gatling.charts.report.Container.{ Group, Request }
import io.gatling.commons.util.StringHelper._
import io.gatling.core.config.GatlingConfiguration
import io.gatling.core.config.IndicatorsConfiguration
import io.gatling.shared.util.NumberHelper._

private[charts] final class GlobalStatsTableComponent(configuration: GatlingConfiguration) extends Component {
private[charts] final class GlobalStatsTableComponent(configuration: IndicatorsConfiguration) extends Component {

override val html: String = {
def pctTitle(pct: Double) = pct.toRank + " pct"

val pct1 = pctTitle(configuration.charting.indicators.percentile1)
val pct2 = pctTitle(configuration.charting.indicators.percentile2)
val pct3 = pctTitle(configuration.charting.indicators.percentile3)
val pct4 = pctTitle(configuration.charting.indicators.percentile4)
val responseTimeFields = Vector("Min", pct1, pct2, pct3, pct4, "Max", "Mean", """<abbr title="Standard Deviation">Std Dev</abbr>""")
val responseTimeFields = List(
"Min",
pctTitle(configuration.percentile1),
pctTitle(configuration.percentile2),
pctTitle(configuration.percentile3),
pctTitle(configuration.percentile4),
"Max",
"Mean",
"""<abbr title="Standard Deviation">Std Dev</abbr>"""
)

s"""
<div id="statistics_table_container">
Expand Down Expand Up @@ -203,5 +208,5 @@ if (lines.index < 30) {
$$('.table-cell-tooltip').popover({trigger:'hover'});
"""

val jsFiles: Seq[String] = Seq.empty
val jsFiles: Seq[String] = Nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ package io.gatling.charts.config
import java.nio.file.{ Path, Paths }

import io.gatling.charts.FileNamingConventions
import io.gatling.core.config.GatlingConfiguration
import io.gatling.core.config.GatlingFiles
import io.gatling.core.config.{ DirectoryConfiguration, GatlingFiles }

private[charts] object ChartsFiles {
private val AllSessionsFile = "all_sessions.js"
Expand Down Expand Up @@ -48,7 +47,7 @@ private[charts] object ChartsFiles {
val GatlingAssetsStylePackage: Path = GatlingAssetsPackage.resolve(GatlingStyleFolder)
}

private[charts] class ChartsFiles(runUuid: String, configuration: GatlingConfiguration) {
private[charts] class ChartsFiles(runUuid: String, configuration: DirectoryConfiguration) {
import ChartsFiles._

private val resultDirectory = GatlingFiles.resultDirectory(runUuid, configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@

package io.gatling.charts.report

import java.nio.charset.Charset

import io.gatling.charts.component.ComponentLibrary
import io.gatling.charts.config.ChartsFiles
import io.gatling.charts.stats.{ IntVsTimePlot, Series }
import io.gatling.charts.util.Color
import io.gatling.core.config.GatlingConfiguration

private[charts] class AllSessionsReportGenerator(
reportsGenerationInputs: ReportsGenerationInputs,
chartsFiles: ChartsFiles,
componentLibrary: ComponentLibrary,
configuration: GatlingConfiguration
charset: Charset
) extends ReportGenerator {
def generate(): Unit = {
import reportsGenerationInputs._
Expand All @@ -35,6 +36,6 @@ private[charts] class AllSessionsReportGenerator(

val javascript = componentLibrary.getAllUsersJs(logFileData.runInfo.injectStart, series)

new TemplateWriter(chartsFiles.allSessionsFile).writeToFile(javascript, configuration)
new TemplateWriter(chartsFiles.allSessionsFile).writeToFile(javascript, charset)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@

package io.gatling.charts.report

import java.nio.charset.Charset

import io.gatling.charts.config.ChartsFiles
import io.gatling.charts.template.AssertionsJUnitTemplate
import io.gatling.core.config.GatlingConfiguration

private[charts] class AssertionsReportGenerator(
reportsGenerationInputs: ReportsGenerationInputs,
chartsFiles: ChartsFiles,
configuration: GatlingConfiguration
charset: Charset
) {
import reportsGenerationInputs._

def generate(): Unit =
new TemplateWriter(chartsFiles.assertionsJUnitFile).writeToFile(new AssertionsJUnitTemplate(logFileData.runInfo, assertionResults).getOutput, configuration)
new TemplateWriter(chartsFiles.assertionsJUnitFile).writeToFile(new AssertionsJUnitTemplate(logFileData.runInfo, assertionResults).getOutput, charset)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@

package io.gatling.charts.report

import java.nio.charset.Charset
import java.time.ZoneId

import io.gatling.charts.component._
import io.gatling.charts.config.ChartsFiles
import io.gatling.charts.stats._
import io.gatling.charts.template.GlobalPageTemplate
import io.gatling.charts.util.Color
import io.gatling.commons.stats.{ KO, OK, Status }
import io.gatling.core.config.GatlingConfiguration
import io.gatling.core.config.ChartingConfiguration

private[charts] class GlobalReportGenerator(
reportsGenerationInputs: ReportsGenerationInputs,
chartsFiles: ChartsFiles,
componentLibrary: ComponentLibrary,
configuration: GatlingConfiguration
zoneId: ZoneId,
charset: Charset,
configuration: ChartingConfiguration
) extends ReportGenerator {
def generate(): Unit = {
import reportsGenerationInputs._
Expand Down Expand Up @@ -100,10 +105,10 @@ private[charts] class GlobalReportGenerator(
new SchemaContainerComponent(
componentLibrary.getRangesComponent("Response Time Ranges", "requests", large = false),
componentLibrary.getRequestCountPolarComponent,
new SimulationCardComponent(logFileData.runInfo, configuration.data.zoneId)
new SimulationCardComponent(logFileData.runInfo, zoneId)
),
new AssertionsTableComponent(assertionResults),
new GlobalStatsTableComponent(configuration),
new GlobalStatsTableComponent(configuration.indicators),
new ErrorsTableComponent(logFileData.errors(None, None)),
activeSessionsChartComponent,
responseTimeDistributionChartComponent,
Expand All @@ -112,6 +117,6 @@ private[charts] class GlobalReportGenerator(
responsesChartComponent
)

new TemplateWriter(chartsFiles.globalFile).writeToFile(template.getOutput, configuration)
new TemplateWriter(chartsFiles.globalFile).writeToFile(template.getOutput, charset)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@

package io.gatling.charts.report

import java.nio.charset.Charset

import io.gatling.charts.component.{ Component, ComponentLibrary, DetailsStatsTableComponent, ErrorsTableComponent }
import io.gatling.charts.config.ChartsFiles
import io.gatling.charts.stats.{ Group, GroupStatsPath, PercentilesVsTimePlot, RequestPath, Series }
import io.gatling.charts.template.GroupDetailsPageTemplate
import io.gatling.charts.util.Color
import io.gatling.commons.stats.OK
import io.gatling.core.config.GatlingConfiguration
import io.gatling.core.config.ChartingConfiguration

private[charts] class GroupDetailsReportGenerator(
reportsGenerationInputs: ReportsGenerationInputs,
chartsFiles: ChartsFiles,
componentLibrary: ComponentLibrary,
configuration: GatlingConfiguration
charset: Charset,
configuration: ChartingConfiguration
) extends ReportGenerator {
def generate(): Unit = {
import reportsGenerationInputs._
Expand Down Expand Up @@ -84,7 +87,7 @@ private[charts] class GroupDetailsReportGenerator(
group,
new SchemaContainerComponent(
componentLibrary.getRangesComponent("Group Duration Ranges", "groups", large = true),
new DetailsStatsTableComponent(configuration)
new DetailsStatsTableComponent(configuration.indicators)
),
new ErrorsTableComponent(logFileData.errors(None, Some(group))),
durationDistributionChartComponent,
Expand All @@ -93,7 +96,7 @@ private[charts] class GroupDetailsReportGenerator(
cumulatedResponseTimeChartComponent
)

new TemplateWriter(chartsFiles.groupFile(path)).writeToFile(template.getOutput, configuration)
new TemplateWriter(chartsFiles.groupFile(path)).writeToFile(template.getOutput, charset)
}

logFileData.statsPaths.foreach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,32 @@

package io.gatling.charts.report

import java.nio.charset.Charset
import java.nio.file.Path
import java.time.ZoneId

import io.gatling.charts.component.ComponentLibrary
import io.gatling.charts.config.ChartsFiles
import io.gatling.charts.stats.RequestStatsPath
import io.gatling.core.config.GatlingConfiguration
import io.gatling.core.config.{ ChartingConfiguration, DirectoryConfiguration }
import io.gatling.shared.util.ScanHelper

private[gatling] class ReportsGenerator(configuration: GatlingConfiguration) {
private[gatling] final class ReportsGenerator(
zoneId: ZoneId,
charset: Charset,
directoryConfiguration: DirectoryConfiguration,
chartingConfiguration: ChartingConfiguration
) {
def generateFor(reportsGenerationInputs: ReportsGenerationInputs): Path = {
import reportsGenerationInputs._

val chartsFiles = new ChartsFiles(reportFolderName, configuration)
val chartsFiles = new ChartsFiles(reportsGenerationInputs.reportFolderName, directoryConfiguration)

def hasAtLeastOneRequestReported: Boolean =
logFileData.statsPaths.exists(_.isInstanceOf[RequestStatsPath])
reportsGenerationInputs.logFileData.statsPaths.exists(_.isInstanceOf[RequestStatsPath])

def generateStats(): Unit = new StatsReportGenerator(reportsGenerationInputs, chartsFiles, configuration).generate()
def generateStats(): Unit = new StatsReportGenerator(reportsGenerationInputs, chartsFiles, charset, chartingConfiguration).generate()

def generateAssertions(): Unit = new AssertionsReportGenerator(reportsGenerationInputs, chartsFiles, configuration).generate()
def generateAssertions(): Unit = new AssertionsReportGenerator(reportsGenerationInputs, chartsFiles, charset).generate()

def copyAssets(): Unit = {
ScanHelper.deepCopyPackageContent(ChartsFiles.GatlingAssetsStylePackage, chartsFiles.styleDirectory)
Expand All @@ -47,10 +53,29 @@ private[gatling] class ReportsGenerator(configuration: GatlingConfiguration) {

val reportGenerators =
List(
new AllSessionsReportGenerator(reportsGenerationInputs, chartsFiles, ComponentLibrary.Instance, configuration),
new GlobalReportGenerator(reportsGenerationInputs, chartsFiles, ComponentLibrary.Instance, configuration),
new RequestDetailsReportGenerator(reportsGenerationInputs, chartsFiles, ComponentLibrary.Instance, configuration),
new GroupDetailsReportGenerator(reportsGenerationInputs, chartsFiles, ComponentLibrary.Instance, configuration)
new AllSessionsReportGenerator(reportsGenerationInputs, chartsFiles, ComponentLibrary.Instance, charset),
new GlobalReportGenerator(
reportsGenerationInputs,
chartsFiles,
ComponentLibrary.Instance,
zoneId,
charset,
chartingConfiguration
),
new RequestDetailsReportGenerator(
reportsGenerationInputs,
chartsFiles,
ComponentLibrary.Instance,
charset,
chartingConfiguration
),
new GroupDetailsReportGenerator(
reportsGenerationInputs,
chartsFiles,
ComponentLibrary.Instance,
charset,
chartingConfiguration
)
)

copyAssets()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@

package io.gatling.charts.report

import java.nio.charset.Charset

import io.gatling.charts.component._
import io.gatling.charts.config.ChartsFiles
import io.gatling.charts.stats._
import io.gatling.charts.template.RequestDetailsPageTemplate
import io.gatling.charts.util.Color
import io.gatling.commons.stats.{ KO, OK, Status }
import io.gatling.core.config.GatlingConfiguration
import io.gatling.core.config.ChartingConfiguration

private[charts] class RequestDetailsReportGenerator(
reportsGenerationInputs: ReportsGenerationInputs,
chartsFiles: ChartsFiles,
componentLibrary: ComponentLibrary,
configuration: GatlingConfiguration
charset: Charset,
configuration: ChartingConfiguration
) extends ReportGenerator {
def generate(): Unit = {
import reportsGenerationInputs._
Expand Down Expand Up @@ -106,7 +109,7 @@ private[charts] class RequestDetailsReportGenerator(
group,
new SchemaContainerComponent(
componentLibrary.getRangesComponent("Response Time Ranges", "requests", large = true),
new DetailsStatsTableComponent(configuration)
new DetailsStatsTableComponent(configuration.indicators)
),
new ErrorsTableComponent(logFileData.errors(Some(requestName), group)),
responseTimeDistributionChartComponent,
Expand All @@ -116,7 +119,7 @@ private[charts] class RequestDetailsReportGenerator(
responseTimeScatterChartComponent
)

new TemplateWriter(chartsFiles.requestFile(path)).writeToFile(template.getOutput, configuration)
new TemplateWriter(chartsFiles.requestFile(path)).writeToFile(template.getOutput, charset)
}

logFileData.statsPaths.foreach {
Expand Down
Loading

0 comments on commit 10c557b

Please sign in to comment.