Skip to content

Commit c5854fd

Browse files
authored
Merge pull request #24 from udzuki/feat-21-exclude-origin-caliper
feat: Caliperステートメント変換でlogstore_standard_log.originを条件にステートメント変換対象のログを選択
2 parents 2222c83 + d272949 commit c5854fd

7 files changed

Lines changed: 75 additions & 6 deletions

File tree

caliper/.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ APP_NAME=moodle
2121
APP_URL='http://localhost:8000'
2222

2323
OPENLRW_HOST='openlrw:9966/key/caliper'
24+
25+
# Specify origins to be excluded (e.g. origin1,origin2,...)
26+
EXCLUDED_ORIGINS=

caliper/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM composer:1.9 AS builder
22

3-
LABEL version="2.2.0"
3+
LABEL version="2.3.0"
44

55
WORKDIR /stage
66
COPY . .

caliper/app/Commands/Generate.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function handle()
3737
private function translateEvent()
3838
{
3939
$eventCount = env('EVENT_COUNT', 10000);
40+
$excludedOrigins = env('EXCLUDED_ORIGINS', '');
41+
$excludedOriginsArray = $excludedOrigins === '' ? [] : explode(',', $excludedOrigins);
4042

4143
$executionLog = new ExecutionLog();
4244
$failedLog = new FailedLog();
@@ -68,6 +70,9 @@ private function translateEvent()
6870
->reject(function ($event) {
6971
return $event->userid === 0;
7072
})
73+
->filter(function ($event) use ($excludedOriginsArray) {
74+
return !in_array($event->origin, $excludedOriginsArray);
75+
})
7176
->filter(function ($event) {
7277
return is_supported($event->eventname);
7378
});

caliper/app/Models/Moodle/Event.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public function scopeColumn($query)
8787
'courseid',
8888
'relateduserid',
8989
'other',
90-
'timecreated'
90+
'timecreated',
91+
'origin'
9192
]);
9293
}
9394
}

caliper/database/seeds/EventSeeder.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ private function event_factory(
1010
int $uid = 1,
1111
string $oTable = null,
1212
int $oId = null,
13-
string $other = null
13+
string $other = null,
14+
string $origin = null
1415
): array {
1516
return [
1617
'eventname' => $eventname,
@@ -29,7 +30,8 @@ private function event_factory(
2930
'relateduserid' => 1,
3031
'other' => $other,
3132
'timecreated' => time(),
32-
'ip' => '127.0.0.1'
33+
'ip' => '127.0.0.1',
34+
'origin' => $origin
3335
];
3436
}
3537

@@ -76,5 +78,7 @@ public function run(): void
7678
Event::create($this->event_factory('\core\event\dashboard_viewed'));
7779
Event::create($this->event_factory('\core\event\user_loggedin', 1, 'user', 1));
7880
Event::create($this->event_factory('\core\event\user_loggedout', 1, 'user', 1));
81+
Event::create($this->event_factory('\core\event\course_viewed', 1, 'user', 1, null, 'origin1'));
82+
Event::create($this->event_factory('\core\event\course_viewed', 1, 'user', 1, null, 'origin2'));
7983
}
8084
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use Illuminate\Support\Facades\Artisan;
6+
use Illuminate\Support\Facades\DB;
7+
use Tests\TestCase;
8+
9+
final class ExcludedOriginsTest extends TestCase
10+
{
11+
public function setUp(): void
12+
{
13+
parent::setUp();
14+
$this->app = $this->createApplication();
15+
}
16+
17+
public function testExcludedOriginsWithParams()
18+
{
19+
putenv('EXCLUDED_ORIGINS=origin1,origin2');
20+
Artisan::call('generate');
21+
$this->assertDatabaseHas(
22+
'execution_logs',
23+
[
24+
'id' => 1,
25+
'translated' => 13,
26+
'failed' => 1,
27+
'last_id' => 17,
28+
],
29+
'log'
30+
);
31+
}
32+
33+
public function testExcludedOriginsWithoutParams()
34+
{
35+
putenv('EXCLUDED_ORIGINS=');
36+
Artisan::call('generate');
37+
$this->assertDatabaseHas(
38+
'execution_logs',
39+
[
40+
'id' => 1,
41+
'translated' => 15,
42+
'failed' => 1,
43+
'last_id' => 17,
44+
],
45+
'log'
46+
);
47+
}
48+
49+
public function tearDown(): void
50+
{
51+
parent::tearDown();
52+
$this->createApplication();
53+
DB::connection('log')->table('failed_logs')->truncate();
54+
DB::connection('log')->table('execution_logs')->truncate();
55+
}
56+
}

caliper/tests/Feature/LoggingTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public function testExecutionLog()
2121
'execution_logs',
2222
[
2323
'id' => 1,
24-
'translated' => 13,
24+
'translated' => 15,
2525
'failed' => 1,
26-
'last_id' => 15,
26+
'last_id' => 17,
2727
],
2828
'log'
2929
);

0 commit comments

Comments
 (0)