Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DWH Analytic "event" doesnt work #4457

Open
hunterist opened this issue Jun 29, 2016 · 2 comments
Open

DWH Analytic "event" doesnt work #4457

hunterist opened this issue Jun 29, 2016 · 2 comments

Comments

@hunterist
Copy link

When I run:
php /opt/kaltura/bin/dwh_cycle.php /opt/kaltura/bin/sanity_config.ini

The result

PHP Fatal error:  Uncaught exception 'KalturaClientException' with message 'failed to unserialize server result php format
<?xml version="1.0" encoding="utf-8"?><xml><result><error><code>MISSING_MANDATORY_PARAMETER</code><message>Missing parameter &quot;event&quot;</message><objectType>KalturaAPIException</objectType><args><item><objectType>KalturaApiExceptionArg</objectType><name>PARAM_NAME</name><value>event</value></item></args></error></result><executionTime>0.0098199844360352</executionTime></xml>' in /opt/kaltura/web/content/clientlibs/php5/KalturaClientBase.php:404
Stack trace:
#0 /opt/kaltura/web/content/clientlibs/php5/KalturaClient.php(6899): KalturaClientBase->doQueue()
#1 /opt/kaltura/bin/dwh_cycle.php(126): KalturaStatsService->collect(Object(KalturaStatsEvent))
#2 {main}
  thrown in /opt/kaltura/web/content/clientlibs/php5/KalturaClientBase.php on line 40

I dont use try-catch with $client->stats->collect($event) function in /opt/kaltura/bin/dwh_cycle.php

Please help check. Thank you so much.

@hunterist
Copy link
Author

<?php
$config = null;
$clientConfig = null;
/* @var $clientConfig KalturaConfiguration */
$client = null;
/* @var $client KalturaClient */

require_once __DIR__ . '/init.php';


$logrotate = $config['dwh']['logRotateBin'];
$kitchen_script= $config['dwh']['kitchenScript'];
$appDir = $config['global']['appDir'];
$dwhDir = $config['dwh']['baseDir'];
$kalturaUser = $config['os']['kalturaUser'];


/**
 * Start a new session
 */
$partnerId = $config['session']['partnerId'];
$adminSecretForSigning = $config['session']['adminSecret'];

//echo $partnerId . " and " . $adminSecretForSigning; die();
$client->setKs($client->generateSessionV2($adminSecretForSigning, 'sanity-user', KalturaSessionType::ADMIN, $partnerId, 86400, ''));


//echo $client->generateSessionV2($adminSecretForSigning, 'sanity-user', KalturaSessionType::ADMIN, $partnerId, 86400, '');

/**
 * List players
 */
$playersFilter = new KalturaUiConfFilter();
$playersFilter->objTypeIn = KalturaUiConfObjType::PLAYER_V3 . ',' . KalturaUiConfObjType::PLAYER;
$playersFilter->orderBy = KalturaUiConfOrderBy::CREATED_AT_DESC;

$playersPager = new KalturaFilterPager();
$playersPager->pageSize = 1;

$playersList = $client->uiConf->listAction($playersFilter, $playersPager);
/* @var $playersList KalturaUiConfListResponse */

if(!$playersList || !$playersList->totalCount || !count($playersList->objects))
{
        echo "No player found\n";
        exit(-1);
}
$player = reset($playersList->objects);




/**
 * List ready media entries
 */
$entriesFilter = new KalturaMediaEntryFilter();
$entriesFilter->mediaTypeEqual = KalturaMediaType::VIDEO;
$entriesFilter->statusEqual = KalturaEntryStatus::READY;
$entriesFilter->orderBy = KalturaMediaEntryOrderBy::DURATION_ASC;
$entriesFilter->partnerId=$partnerId;

$entriesPager = new KalturaFilterPager();
$entriesPager->pageSize = 1;

$entriesList = $client->media->listAction($entriesFilter, $entriesPager);
/* @var $entriesList KalturaMediaListResponse */

if(!$entriesList || !$entriesList->totalCount || !count($entriesList->objects))
{
        echo "No ready media entry found\n";
        exit(-1);
}
$entry = reset($entriesList->objects);
/* @var $entry KalturaMediaEntry */



/**
 * Calls stats.collect
 *
 * TODO:
 *  - Run it once on each API server.
 */
$client->getConfig()->method = KalturaClientBase::METHOD_GET;

$event = new KalturaStatsEvent();
$event->isFirstInSession = false;
$event->seek = false;

$event->clientVer = '3.0:v3.7';
$event->referrer =  $clientConfig->serviceUrl . 'sanity/tests';
$event->sessionId = uniqid('SANITY-TEST-');

$event->entryId = $entry->id;
$event->partnerId = $entry->partnerId;
$event->duration = $entry->duration;
$event->currentPoint = 0;

$event->uiconfId = $player->id;

$event->eventType = KalturaStatsEventType::WIDGET_LOADED;
$event->eventTimestamp = microtime(true);

try
{
        $client->stats->collect($event);
}
catch (KalturaClientException $e){}
echo "Sent event [KalturaStatsEventType::WIDGET_LOADED]\n";

$event->eventType = KalturaStatsEventType::MEDIA_LOADED;
$event->eventTimestamp = microtime(true);
try
{
        $client->stats->collect($event);
}
catch (KalturaClientException $e){}
echo "Sent event [KalturaStatsEventType::MEDIA_LOADED]\n";

$event->eventType = KalturaStatsEventType::PLAY;
$event->eventTimestamp = microtime(true);

//$s = unserialize($event);
//var_dump($event);die();

$client->stats->collect($event);

try
{
        //$client->stats->collect($event);
    //var_dump($client);die();

}
catch (KalturaClientException $e){
    //var_dump($event);
    //echo $e->getMessage();die();
}

echo "Sent event [KalturaStatsEventType::PLAY]\n";

$quarter = ceil(($entry->msDuration / 4) * 1000);

usleep($quarter);
$event->currentPoint += $quarter;
$event->eventType = KalturaStatsEventType::PLAY_REACHED_25;
$event->eventTimestamp = microtime(true);
try
{
        $client->stats->collect($event);
}
catch (KalturaClientException $e){
    echo "Can not count play_reached_25\n";
}
echo "Sent event [KalturaStatsEventType::PLAY_REACHED_25]\n";

usleep($quarter);
$event->currentPoint += $quarter;
$event->eventType = KalturaStatsEventType::PLAY_REACHED_50;
$event->eventTimestamp = microtime(true);
try
{
        $client->stats->collect($event);
}
catch (KalturaClientException $e){}
echo "Sent event [KalturaStatsEventType::PLAY_REACHED_50]\n";

usleep($quarter);
$event->currentPoint += $quarter;
$event->eventType = KalturaStatsEventType::PLAY_REACHED_75;
$event->eventTimestamp = microtime(true);
try
{
        $client->stats->collect($event);
}
catch (KalturaClientException $e){}
echo "Sent event [KalturaStatsEventType::PLAY_REACHED_75]\n";

usleep($quarter);
$event->currentPoint = $entry->msDuration;
$event->eventType = KalturaStatsEventType::PLAY_REACHED_100;
$event->eventTimestamp = microtime(true);
try
{
        $client->stats->collect($event);
}
catch (KalturaClientException $e){}
echo "Sent event [KalturaStatsEventType::PLAY_REACHED_100]\n";

$client->getConfig()->method = KalturaClientBase::METHOD_POST;




/**
 * Rotate logs.
 */
$returnedValue = null;
$cmd = "$logrotate -f  /etc/logrotate.d/kaltura_apache";
echo "Executing [$cmd]";
passthru($cmd, $returnedValue);
if($returnedValue !== 0)
{
       // echo " failed\n";
       // exit(-1);
}
echo " log rotated\n";



/**
 * Run hourly scripts.
 */
$cmd = "su $kalturaUser -c '$dwhDir/etlsource/execute/etl_hourly.sh -p $dwhDir  -k $kitchen_script '";
echo "Executing [$cmd]";
passthru($cmd, $returnedValue);
if($returnedValue !== 0)
{
        echo " failed\n";
        exit(-1);
}
echo " OK\n";


/**
 * Run update dimensions.
 */
$cmd = "su $kalturaUser -c '$dwhDir/etlsource/execute/etl_update_dims.sh -p $dwhDir -k $kitchen_script'";
echo "Executing [$cmd]";
passthru($cmd, $returnedValue);
//if($returnedValue !== 0)
//{
//      echo " failed [$cmd]\n";
//      exit(-1);
//}
echo " OK\n";



/**
 * Run daily scripts.
 */
$cmd = "su $kalturaUser -c '$dwhDir/etlsource/execute/etl_daily.sh -p $dwhDir -k $kitchen_script'";
echo "Executing [$cmd]";
passthru($cmd, $returnedValue);
if($returnedValue !== 0)
{
        echo " failed [$cmd]\n";
        exit(-1);
}
echo " OK\n";



/**
 * Validate the results using the API
 *
 * TODO:
 *  - Validate that the data collected from all API machines.
 */
$dateTimeZoneServer = new DateTimeZone(date_default_timezone_get());
$dateTimeZoneUTC = new DateTimeZone("UTC");
$dateTimeUTC = new DateTime("now", $dateTimeZoneUTC);
$timeOffsetSeconds = $dateTimeZoneServer->getOffset($dateTimeUTC);

$reportInputFilter = new KalturaReportInputFilter();
$reportInputFilter->timeZoneOffset = ($timeOffsetSeconds / -60);
$reportInputFilter->fromDay = date('Ymd', time() - (60 * 60 * 24));
$reportInputFilter->toDay = date('Ymd');

$reportInputPager = new KalturaFilterPager();
$reportTable = $client->report->getTable(KalturaReportType::TOP_CONTENT, $reportInputFilter, $reportInputPager, null, $entry->id);
/* @var $reportTable KalturaReportTable */

if($reportTable->totalCount != 1)
{
//print_r($reportTable);
        echo "Reported wrong total count [$reportTable->totalCount]\n";
        exit(-1);
}

$titles = explode(',', $reportTable->header);
$data = explode(';', $reportTable->data);
if(!$reportTable->data || count($data) != 2)
{
        echo "Reported wrong data count\n";
        exit(-1);
}

$recordData = explode(',', reset($data));
$record = array_combine($titles, $recordData);
if($record['object_id'] != $entry->id)
{
        echo "Reported data of wrong entry [" . $record['object_id'] . "]\n";
        exit(-1);
}
if(!isset($record['count_plays']) || !$record['count_plays'] || !intval($record['count_plays']))
{
        echo "Reported wrong plays count [" . $record['count_plays'] . "]\n";
        exit(-1);
}
if(!isset($record['count_loads']) || !$record['count_loads'] || !intval($record['count_loads']))
{
        echo "Reported wrong loads count [" . $record['count_loads'] . "]\n";
        exit(-1);
}
$expectedTimeViewed = round($entry->duration / 60, 2);
if(!isset($record['sum_time_viewed']) || !$record['sum_time_viewed'] || floatval($record['sum_time_viewed']) < $expectedTimeViewed)
{
        echo "Reported wrong view time [" . $record['sum_time_viewed'] . "] expected at least [$expectedTimeViewed]\n";
        exit(-1);
}
echo "Reports OK\n";



/**
 * Syncyng plays and view from the dwh to the operational db
 */
$cmd = "su $kalturaUser -c $appDir/alpha/scripts/dwh/dwh_plays_views_sync.sh >/tmp/dwh_plays_views_sync.log";
echo "Executing [$cmd]";
passthru($cmd, $returnedValue);
if($returnedValue !== 0)
{
        echo " failed [$cmd]\n";
        exit(-1);
}
echo " OK\n";



/**
 * Reload the entry and check plays and views
 */
$reloadedEntry = $client->media->get($entry->id);
/* @var $reloadedEntry KalturaMediaEntry 

*/
if($reloadedEntry->plays <= $entry->plays)
{
        echo "Entry [$entry->id] plays [$reloadedEntry->plays] did not incremented\n";
        exit(-1);
}
if($reloadedEntry->views <= $entry->views)
{
        echo "Entry [$entry->id] views [$reloadedEntry->views] did not incremented\n";
        exit(-1);
}

echo "Plays and views OK - $entry->id\n";

@hunterist hunterist changed the title Missing parameter &quot;event&quot; <code>MISSING_MANDATORY_PARAMETER</code><message>Missing parameter "event"</message> Jun 29, 2016
@kaltura-hooks
Copy link

Hi @hunterist,

Thank for you reporting an issue and helping improve Kaltura!

To get the fastest response time, and help the maintainers review and test your reported issues or suggestions, please ensure that your issue includes the following (please comment with more info if you have not included all this info in your original issue):

  • Is the issue you're experiencing consistent and across platforms? or does it only happens on certain conditions?
    please provide as much details as possible.
  • Which Kaltura deployment you're using: Kaltura SaaS, or self-hosted?
    If self hosted, are you using the RPM or deb install?
  • Packages installed.
    When using RPM, paste the output for:
    # rpm -qa \"kaltura*\"
For deb based systems:
    # dpkg -l \"kaltura-*\"
  • If running a self hosted ENV - provide the MySQL server version used
  • If running a self hosted ENV - is this a single all in 1 server or a cluster?
  • If running a self hosted ENV, while making the problematic request, run:
    # tail -f /opt/kaltura/log/*.log /opt/kaltura/log/batch/*.log | grep -A 1 -B 1 --color \"ERR:\|PHP\|trace\|CRIT\|\[error\]\"

and paste the output.

  • When relevant, provide any screenshots or screen recordings showing the issue you're experiencing.

For general troubleshooting see:
https://github.com/kaltura/platform-install-packages/blob/Jupiter-10.13.0/doc/kaltura-packages-faq.md#troubleshooting-help

If you only have a general question rather than a bug report, please close this issue and post at:
http://forum.kaltura.org

Thank you in advance,

@hunterist hunterist changed the title <code>MISSING_MANDATORY_PARAMETER</code><message>Missing parameter "event"</message> DWH Analytic "event" doesnt work Jun 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants