Skip to content

Commit

Permalink
Merge pull request #106 from ls1intum/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
valentin-boehm authored Jan 18, 2024
2 parents eab2da2 + 5b59e72 commit 3fe05ef
Show file tree
Hide file tree
Showing 17 changed files with 602 additions and 72 deletions.
322 changes: 275 additions & 47 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@
"sockjs-client": "1.6.1",
"tslib": "2.6.2",
"webstomp-client": "1.2.6",
"zone.js": "0.14.2"
"zone.js": "0.14.3"
},
"devDependencies": {
"@angular-builders/jest": "17.0.0",
"@angular-devkit/build-angular": "17.0.9",
"@angular-devkit/build-angular": "17.0.10",
"@angular-eslint/eslint-plugin": "17.1.1",
"@angular/cli": "17.0.9",
"@angular/cli": "17.0.10",
"@angular/compiler-cli": "17.0.4",
"@angular/service-worker": "17.0.4",
"@types/jest": "29.5.10",
"@types/node": "20.10.6",
"@types/node": "20.11.1",
"@types/sockjs-client": "1.5.4",
"@typescript-eslint/eslint-plugin": "6.18.0",
"@typescript-eslint/parser": "6.12.0",
Expand All @@ -123,7 +123,7 @@
"jest-preset-angular": "13.1.4",
"jest-sonar": "0.2.16",
"lint-staged": "15.2.0",
"prettier": "3.1.1",
"prettier": "3.2.2",
"prettier-plugin-java": "2.5.0",
"prettier-plugin-packagejson": "2.4.9",
"rimraf": "5.0.5",
Expand Down
2 changes: 1 addition & 1 deletion src/main/docker/config/mysql/my.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ innodb_ft_total_cache_size=32000000
#### http://www.tocker.ca/2014/03/10/configuring-mysql-to-use-minimal-memory.html

# per thread or per operation settings
thread_stack=131072
thread_stack=192000
sort_buffer_size=32K
read_buffer_size=8200
read_rnd_buffer_size=8200
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/de/tum/cit/ase/domain/SimulationStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public class SimulationStats {
@JoinColumn(name = "simulation_stats_id")
private Set<StatsByMinute> statsByMinute;

@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
@JoinColumn(name = "simulation_stats_id")
private Set<StatsBySecond> statsBySecond;

@Enumerated(EnumType.STRING)
@Column(name = "request_type", nullable = false)
private RequestType requestType;
Expand Down Expand Up @@ -79,6 +83,14 @@ public void setSimulationRun(SimulationRun simulationRun) {
this.simulationRun = simulationRun;
}

public Set<StatsBySecond> getStatsBySecond() {
return statsBySecond;
}

public void setStatsBySecond(Set<StatsBySecond> statsBySecond) {
this.statsBySecond = statsBySecond;
}

@Override
public String toString() {
return (
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/de/tum/cit/ase/domain/StatsBySecond.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package de.tum.cit.ase.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import java.time.ZonedDateTime;

@Entity
public class StatsBySecond {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "date_time", nullable = false)
private ZonedDateTime dateTime;

@Column(name = "number_of_requests", nullable = false)
private long numberOfRequests;

@Column(name = "avg_response_time", nullable = false)
private long avgResponseTime;

@ManyToOne
@JoinColumn(name = "simulation_stats_id", nullable = false)
@JsonIgnore
private SimulationStats simulationStats;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public ZonedDateTime getDateTime() {
return dateTime;
}

public void setDateTime(ZonedDateTime dateTime) {
this.dateTime = dateTime;
}

public long getNumberOfRequests() {
return numberOfRequests;
}

public void setNumberOfRequests(long numberOfRequests) {
this.numberOfRequests = numberOfRequests;
}

public long getAvgResponseTime() {
return avgResponseTime;
}

public void setAvgResponseTime(long avgResponseTime) {
this.avgResponseTime = avgResponseTime;
}

public SimulationStats getSimulationStats() {
return simulationStats;
}

public void setSimulationStats(SimulationStats simulationStats) {
this.simulationStats = simulationStats;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.tum.cit.ase.repository;

import de.tum.cit.ase.domain.StatsBySecond;
import org.springframework.data.jpa.repository.JpaRepository;

public interface StatsBySecondRepository extends JpaRepository<StatsBySecond, Long> {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.tum.cit.ase.domain.RequestType;
import de.tum.cit.ase.repository.SimulationStatsRepository;
import de.tum.cit.ase.repository.StatsByMinuteRepository;
import de.tum.cit.ase.repository.StatsBySecondRepository;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Collection;
Expand All @@ -18,10 +19,16 @@ public class SimulationResultService {

private final SimulationStatsRepository simulationStatsRepository;
private final StatsByMinuteRepository statsByMinuteRepository;
private final StatsBySecondRepository statsBySecondRepository;

public SimulationResultService(SimulationStatsRepository simulationStatsRepository, StatsByMinuteRepository statsByMinuteRepository) {
public SimulationResultService(
SimulationStatsRepository simulationStatsRepository,
StatsByMinuteRepository statsByMinuteRepository,
StatsBySecondRepository statsBySecondRepository
) {
this.simulationStatsRepository = simulationStatsRepository;
this.statsByMinuteRepository = statsByMinuteRepository;
this.statsBySecondRepository = statsBySecondRepository;
}

/**
Expand All @@ -37,12 +44,18 @@ public SimulationRun calculateAndSaveResult(SimulationRun simulationRun, List<Re
totalStats.setAvgResponseTime(getAverage(requestStats));
totalStats.setRequestType(RequestType.TOTAL);
Set<StatsByMinute> totalStatsByMinute = calculateStatsByMinute(requestStats);
Set<StatsBySecond> totalStatsBySecond = calculateStatsBySecond(requestStats);
simulationStatsRepository.save(totalStats);
totalStats.setStatsByMinute(totalStatsByMinute);
totalStatsByMinute.forEach(statsByMinute -> {
statsByMinute.setSimulationStats(totalStats);
statsByMinuteRepository.save(statsByMinute);
});
totalStats.setStatsBySecond(totalStatsBySecond);
totalStatsBySecond.forEach(statsByTenSec -> {
statsByTenSec.setSimulationStats(totalStats);
statsBySecondRepository.save(statsByTenSec);
});

SimulationStats authStats = calculateStatsForRequestType(requestStats, RequestType.AUTHENTICATION, simulationRun);

Expand Down Expand Up @@ -90,6 +103,12 @@ private SimulationStats calculateStatsForRequestType(List<RequestStat> requestSt
statsByMinute.setSimulationStats(simulationStats);
statsByMinuteRepository.save(statsByMinute);
});
Set<StatsBySecond> statsBySecond = calculateStatsBySecond(filteredRequestStats);
simulationStats.setStatsBySecond(statsBySecond);
statsBySecond.forEach(statsByTenSec -> {
statsByTenSec.setSimulationStats(simulationStats);
statsBySecondRepository.save(statsByTenSec);
});
return simulationStats;
}

Expand Down Expand Up @@ -117,6 +136,23 @@ private static Set<StatsByMinute> calculateStatsByMinute(Collection<RequestStat>
.collect(Collectors.toSet());
}

private static Set<StatsBySecond> calculateStatsBySecond(Collection<RequestStat> requestStats) {
Map<ZonedDateTime, Long> requestsBySecond = calculateRequestsBySecond(requestStats);
Map<ZonedDateTime, Double> avgResponseTimeBySecond = calculateAvgResponseTimeBySecond(requestStats);

return requestsBySecond
.keySet()
.stream()
.map(dateTime -> {
StatsBySecond statsBySecond = new StatsBySecond();
statsBySecond.setDateTime(dateTime);
statsBySecond.setNumberOfRequests(requestsBySecond.get(dateTime));
statsBySecond.setAvgResponseTime(avgResponseTimeBySecond.get(dateTime).longValue());
return statsBySecond;
})
.collect(Collectors.toSet());
}

private static Map<ZonedDateTime, Long> calculateRequestsByMinute(Collection<RequestStat> requestStats) {
return requestStats
.stream()
Expand All @@ -133,4 +169,21 @@ private static Map<ZonedDateTime, Double> calculateAvgResponseTimeByMinute(Colle
)
);
}

private static Map<ZonedDateTime, Long> calculateRequestsBySecond(Collection<RequestStat> requestStats) {
return requestStats
.stream()
.collect(Collectors.groupingBy(stat -> stat.dateTime().truncatedTo(ChronoUnit.SECONDS), Collectors.counting()));
}

private static Map<ZonedDateTime, Double> calculateAvgResponseTimeBySecond(Collection<RequestStat> requestStats) {
return requestStats
.stream()
.collect(
Collectors.groupingBy(
stat -> stat.dateTime().truncatedTo(ChronoUnit.SECONDS),
Collectors.averagingLong(RequestStat::duration)
)
);
}
}
10 changes: 10 additions & 0 deletions src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ spring:
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
messages:
basename: i18n/messages
mail:
host: postout.lrz.de
port: 587
protocol: smtp
tls: true
username:
password:
properties.mail.smtp:
auth: true
starttls.enable: true
main:
allow-bean-definition-overriding: true
mvc:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

<changeSet id="00000000000016" author="valentin-boehm">
<createTable tableName="stats_by_second">
<column name="id" type="bigint" autoIncrement="true" startWith="0">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="number_of_requests" type="int"/>
<column name="avg_response_time" type="bigint"/>
<column name="simulation_stats_id" type="bigint"/>
<column name="date_time" type="timestamp"/>
</createTable>
</changeSet>
</databaseChangeLog>
1 change: 1 addition & 0 deletions src/main/resources/config/liquibase/master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<include file="config/liquibase/changelog/00000000000013_add_instructor_credentials.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/00000000000014_add_run_end_date.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/00000000000015_add_local_ci_status.xml" relativeToChangelogFile="false"/>
<include file="/config/liquibase/changelog/00000000000016_add_stats_by_second.xml" relativeToChangelogFile="false"/>
<!-- jhipster-needle-liquibase-add-changelog - JHipster will add liquibase changelogs here -->
<!-- jhipster-needle-liquibase-add-constraints-changelog - JHipster will add liquibase constraints changelogs here -->
<!-- jhipster-needle-liquibase-add-incremental-changelog - JHipster will add incremental liquibase changelogs here -->
Expand Down
4 changes: 4 additions & 0 deletions src/main/webapp/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { ServerBadgeComponent } from './layouts/server-badge/server-badge.compon
import { ModeExplanationComponent } from './layouts/mode-explanation/mode-explanation.component';
import { PrometheusBoxComponent } from './layouts/prometheus-box/prometheus-box.component';
import { LocalCiStatusCardComponent } from './layouts/local-ci-status-card/local-ci-status-card.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgxChartsModule } from '@swimlane/ngx-charts';
// jhipster-needle-angular-add-module-import JHipster will add new module here

@NgModule({
Expand All @@ -46,6 +48,8 @@ import { LocalCiStatusCardComponent } from './layouts/local-ci-status-card/local
NgbAccordionModule,
PrometheusBoxComponent,
LocalCiStatusCardComponent,
NgxChartsModule,
BrowserAnimationsModule,
],
providers: [
Title,
Expand Down
5 changes: 3 additions & 2 deletions src/main/webapp/app/entities/simulation/simulationStats.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SimulationRun } from './simulationRun';
import { RequestType } from './requestType';
import { StatsByMinute } from './statsByMinute';
import { StatsByTime } from './statsByTime';

export class SimulationStats {
constructor(
Expand All @@ -9,7 +9,8 @@ export class SimulationStats {
public avgResponseTime: number,
public simulationRun: SimulationRun,
public requestType: RequestType,
public statsByMinute: StatsByMinute[],
public statsByMinute: StatsByTime[],
public statsBySecond: StatsByTime[],
) {}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SimulationStats } from './simulationStats';

export class StatsByMinute {
export class StatsByTime {
constructor(
public id: number,
public dateTime: Date,
Expand Down
Loading

0 comments on commit 3fe05ef

Please sign in to comment.