test(analytics): add test case and set the unit to be second.

This commit is contained in:
Haojun Liao 2025-03-04 23:31:02 +08:00
parent 5af14a905f
commit 2c92cca603
4 changed files with 26 additions and 18 deletions

View File

@ -30,8 +30,8 @@ extern "C" {
#define ANAL_FORECAST_DEFAULT_WNCHECK 1 #define ANAL_FORECAST_DEFAULT_WNCHECK 1
#define ANAL_FORECAST_MAX_ROWS 40000 #define ANAL_FORECAST_MAX_ROWS 40000
#define ANAL_ANOMALY_WINDOW_MAX_ROWS 40000 #define ANAL_ANOMALY_WINDOW_MAX_ROWS 40000
#define ANALY_FC_DEFAULT_TIMEOUT 60000 #define ANALY_DEFAULT_TIMEOUT 60
#define ANALY_FC_MAX_TIMEOUT (600*1000) #define ANALY_MAX_TIMEOUT 600
typedef struct { typedef struct {
EAnalAlgoType type; EAnalAlgoType type;

View File

@ -92,15 +92,15 @@ int32_t createAnomalywindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* p
bool hasTimeout = taosAnalGetOptInt(pAnomalyNode->anomalyOpt, "timeout", &pInfo->timeout); bool hasTimeout = taosAnalGetOptInt(pAnomalyNode->anomalyOpt, "timeout", &pInfo->timeout);
if (!hasTimeout) { if (!hasTimeout) {
qDebug("not set the timeout val, set default:%d", ANALY_FC_DEFAULT_TIMEOUT); qDebug("not set the timeout val, set default:%d", ANALY_DEFAULT_TIMEOUT);
pInfo->timeout = ANALY_FC_DEFAULT_TIMEOUT; pInfo->timeout = ANALY_DEFAULT_TIMEOUT;
} else { } else {
if (pInfo->timeout <= 500 || pInfo->timeout > 600*1000) { if (pInfo->timeout <= 0 || pInfo->timeout > ANALY_MAX_TIMEOUT) {
qDebug("timeout val:%" PRId64 "ms is invalid (greater than 10min or less than 0.5s), use default:%dms", qDebug("timeout val:%" PRId64 "s is invalid (greater than 10min or less than 1s), use default:%dms",
pInfo->timeout, ANALY_FC_DEFAULT_TIMEOUT); pInfo->timeout, ANALY_DEFAULT_TIMEOUT);
pInfo->timeout = ANALY_FC_DEFAULT_TIMEOUT; pInfo->timeout = ANALY_DEFAULT_TIMEOUT;
} else { } else {
qDebug("timeout val is set to: %" PRId64 "ms", pInfo->timeout); qDebug("timeout val is set to: %" PRId64 "s", pInfo->timeout);
} }
} }
@ -466,7 +466,7 @@ static int32_t anomalyAnalysisWindow(SOperatorInfo* pOperator) {
code = taosAnalBufClose(&analBuf); code = taosAnalBufClose(&analBuf);
QUERY_CHECK_CODE(code, lino, _OVER); QUERY_CHECK_CODE(code, lino, _OVER);
pJson = taosAnalySendReqRetJson(pInfo->algoUrl, ANALYTICS_HTTP_TYPE_POST, &analBuf, pInfo->timeout); pJson = taosAnalySendReqRetJson(pInfo->algoUrl, ANALYTICS_HTTP_TYPE_POST, &analBuf, pInfo->timeout * 1000);
if (pJson == NULL) { if (pJson == NULL) {
code = terrno; code = terrno;
goto _OVER; goto _OVER;

View File

@ -211,7 +211,7 @@ static int32_t forecastAnalysis(SForecastSupp* pSupp, SSDataBlock* pBlock, const
SColumnInfoData* pResHighCol = SColumnInfoData* pResHighCol =
(pSupp->resHighSlot != -1 ? taosArrayGet(pBlock->pDataBlock, pSupp->resHighSlot) : NULL); (pSupp->resHighSlot != -1 ? taosArrayGet(pBlock->pDataBlock, pSupp->resHighSlot) : NULL);
SJson* pJson = taosAnalySendReqRetJson(pSupp->algoUrl, ANALYTICS_HTTP_TYPE_POST, pBuf, pSupp->timeout); SJson* pJson = taosAnalySendReqRetJson(pSupp->algoUrl, ANALYTICS_HTTP_TYPE_POST, pBuf, pSupp->timeout * 1000);
if (pJson == NULL) { if (pJson == NULL) {
return terrno; return terrno;
} }
@ -534,15 +534,15 @@ static int32_t forecastParseAlgo(SForecastSupp* pSupp, const char* id) {
bool hasTimeout = taosAnalGetOptInt(pSupp->algoOpt, "timeout", &pSupp->timeout); bool hasTimeout = taosAnalGetOptInt(pSupp->algoOpt, "timeout", &pSupp->timeout);
if (!hasTimeout) { if (!hasTimeout) {
qDebug("%s not set the timeout val, set default:%d", id, ANALY_FC_DEFAULT_TIMEOUT); qDebug("%s not set the timeout val, set default:%d", id, ANALY_DEFAULT_TIMEOUT);
pSupp->timeout = ANALY_FC_DEFAULT_TIMEOUT; pSupp->timeout = ANALY_DEFAULT_TIMEOUT;
} else { } else {
if (pSupp->timeout <= 500 || pSupp->timeout > ANALY_FC_MAX_TIMEOUT) { if (pSupp->timeout <= 0 || pSupp->timeout > ANALY_MAX_TIMEOUT) {
qDebug("%s timeout val:%" PRId64 "ms is invalid (greater than 10min or less than 0.5s), use default:%dms", qDebug("%s timeout val:%" PRId64 "s is invalid (greater than 10min or less than 1s), use default:%dms",
id, pSupp->timeout, ANALY_FC_DEFAULT_TIMEOUT); id, pSupp->timeout, ANALY_DEFAULT_TIMEOUT);
pSupp->timeout = ANALY_FC_DEFAULT_TIMEOUT; pSupp->timeout = ANALY_DEFAULT_TIMEOUT;
} else { } else {
qDebug("%s timeout val is set to: %" PRId64 "ms", id, pSupp->timeout); qDebug("%s timeout val is set to: %" PRId64 "s", id, pSupp->timeout);
} }
} }

View File

@ -88,6 +88,14 @@ sql_error select count(*) from ct1 anomaly_window(c6, 'algo=ksigma,k=2');
sql_error select forecast(c6, 'algo=holtwinters,conf=0.5,wncheck=1,period=0') from ct1 sql_error select forecast(c6, 'algo=holtwinters,conf=0.5,wncheck=1,period=0') from ct1
print ==================== invalid timeout parameter
sql_error select forecast(c1, 'algo=holtwinters, timeout=6000') from ct1;
sql_error select forecast(c1, 'algo=holtwinters, timeout=0') from ct1;
print =========================== valid timeout
sql select forecast(c1, 'algo=holtwinters, timeout=120') from ct1;
sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=0.5,wncheck=1,period=0') from ct1 sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=0.5,wncheck=1,period=0') from ct1
sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=119,wncheck=1,period=0') from ct1 sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=119,wncheck=1,period=0') from ct1
sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters1,conf=0.5,wncheck=1,period=0') from ct1 sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters1,conf=0.5,wncheck=1,period=0') from ct1