Skip to content

Commit

Permalink
fix(states): updated window periods
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarobernal2412 committed Jan 20, 2025
1 parent 8f9d9a0 commit e30b4e2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
8 changes: 7 additions & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@
],
"separateMajorMinor": false,
"groupName": "ci",
"automerge": false
"automerge": true,
"automergeType": "pr",
"automergeStrategy": "squash",
"matchUpdateTypes": [
"patch",
"minor"
]
},
{
"matchUpdateTypes": [
Expand Down
18 changes: 9 additions & 9 deletions src/controllers/v6/states/guarantees/guarantees.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,31 +206,31 @@ async function processGuaranteesSequentially(manager, res, result, lastPeriodFla
async function buildGuaranteeQueries(manager, guarantee, lastPeriodFlag, newPeriodsFlag, from, to) {
const guaranteeDefinition = manager.agreement.terms.guarantees.find(e => guarantee.id === e.id);
const requestWindow = guaranteeDefinition.of[0].window;

logger.info(`Building queries for guarantee: ${guarantee.id}`);
logger.info(`Request window: ${JSON.stringify(requestWindow)}`);

if (lastPeriodFlag) {
const period = utils.time.getLastPeriod(manager.agreement, requestWindow);
logger.info(`Last period: ${JSON.stringify(period)}`);
return [gUtils.buildGuaranteeQuery(guarantee.id, period.from, period.to)];
}
if (from && to) {
requestWindow.from = from;
requestWindow.end = to;

logger.info(`From: ${from}, To: ${to}`);
logger.info(`New periods flag: ${newPeriodsFlag}`);

const periods = newPeriodsFlag
? utils.time.getPeriods(manager.agreement, requestWindow)
: [{ from: new Date(from).toISOString(), to: new Date(to).toISOString() }];

logger.info(`Periods: ${JSON.stringify(periods)}`);
return periods.map(period =>
gUtils.buildGuaranteeQuery(guarantee.id, period.from, period.to)
);
}

if (lastPeriodFlag) {
const period = utils.time.getLastPeriod(manager.agreement, requestWindow);
logger.info(`Last period: ${JSON.stringify(period)}`);
return [gUtils.buildGuaranteeQuery(guarantee.id, period.from, period.to)];
}
logger.info(`Returning guarantee ID: ${guarantee.id}`);
return [guarantee.id];
}
Expand Down
23 changes: 4 additions & 19 deletions src/stateManager/v6/metric-calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
'use strict';
const governify = require('governify-commons');
const logger = governify.getLogger().tag('metric-calculator');
const Promise = require('bluebird');
const JSONStream = require('JSONStream');

const utils = require('../../utils');

const Query = utils.Query;
const promiseErrorHandler = utils.errors.promiseErrorHandler;

/**
* Metric calculator module.
* @module metricCalculator
Expand Down Expand Up @@ -80,7 +77,7 @@ async function processMetric(agreement, metricId, metricQuery) {
}

if (collector.type === 'PPINOT-V1') {
return await processPpinotV1Metric(metric, agreement, collectorQuery, collector, metricId);
return await processPpinotV1Metric(metric, agreement, collectorQuery, collector, metricId, metricQuery);
}

logger.error(`Unsupported collector type: ${collector.type}`);
Expand All @@ -102,7 +99,6 @@ async function processPostGetV1Metric(metric, agreement, scope, collectorQuery,
method: 'POST',
data: { config: collector.config, metric: metric.measure },
});

const collectorResponse = requestMetric.data;
const monthMetrics = await getComputationV2(
collector.infrastructurePath,
Expand All @@ -118,7 +114,7 @@ async function processPostGetV1Metric(metric, agreement, scope, collectorQuery,
}
}

async function processPpinotV1Metric(metric, agreement, collectorQuery, collector, metricId) {
async function processPpinotV1Metric(metric, agreement, collectorQuery, collector, metricId, metricQuery) {
try {
const logDefinition = getLogDefinition(metric, agreement);
collectorQuery.logs = {
Expand Down Expand Up @@ -154,7 +150,7 @@ async function getComputationV2(infrastructurePath, computationURL, ttl) {
const response = await service.get(computationURL);

if (response.status === 202) {
logger.debug(`Computation not ready, retrying in 200ms.`);
logger.debug('Computation not ready, retrying in 200ms.');
return new Promise(resolve =>
setTimeout(() => resolve(getComputationV2(infrastructurePath, computationURL, ttl - 200)), 200)
);
Expand All @@ -179,7 +175,7 @@ function getLogDefinition(metric, agreement) {
if (!logId) throw new Error('Log field in metric is not well defined.');
logDefinition = metric.log[logId];
} else {
const defaultLog = Object.entries(agreement.context.definitions.logs).find(([_, log]) => log.default);
const defaultLog = Object.entries(agreement.context.definitions.logs).find(([, log]) => log.default);
if (!defaultLog) throw new Error('No default log defined in agreement.');
[logId, logDefinition] = defaultLog;
}
Expand All @@ -200,8 +196,6 @@ function processMetricStates(monthMetrics, metric, logs, metricId) {
return metricState;
});

logger.debug(`Processed metric ${metricId}: \n ${JSON.stringify(compositeResponse, null, 2)}`);

return {metricId: metricId, metricValues: compositeResponse};
}

Expand All @@ -221,15 +215,6 @@ function handleStreamResponse(requestStream, metric, logs, metricId) {
});
}

class Config {
constructor(ptkey, schedules, holidays, overrides, measures) {
this.ptkey = ptkey;
this.schedules = schedules;
this.holidays = holidays;
this.overrides = overrides;
this.measures = measures;
}
}

class LogField {
constructor(uri, stateUri, terminator, structure) {
Expand Down

0 comments on commit e30b4e2

Please sign in to comment.