Skip to content

Commit

Permalink
fix: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
razbroc committed Jul 31, 2024
1 parent 1ee72ee commit 7378fa6
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 75 deletions.
5 changes: 4 additions & 1 deletion config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
}
},
"tracing": {
"enabled": "TELEMETRY_TRACING_ENABLED",
"enabled": {
"__name": "TELEMETRY_TRACING_ENABLED",
"__format": "boolean"
},
"url": "TELEMETRY_TRACING_URL"
},
"metrics": {
Expand Down
2 changes: 1 addition & 1 deletion helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ data:
LOG_PRETTY_PRINT_ENABLED: {{ .Values.env.logPrettyPrintEnabled | quote }}
TELEMETRY_TRACING_ENABLED: {{ $tracing.enabled | quote }}
{{ if $tracing.enabled }}
TELEMETRY_TRACING_URL: {{ $metrics.tracingUrl }}
TELEMETRY_TRACING_URL: {{ $tracing.tracingUrl }}
{{ end }}
TELEMETRY_METRICS_ENABLED: {{ $metrics.enabled | quote }}
{{ if $metrics.enabled}}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@
"ts-jest": "^29.0.5",
"typescript": "^5.1.3"
}
}
}
1 change: 0 additions & 1 deletion src/clients/jobManagerWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export class JobManagerWrapper extends JobManagerClient {
this.jobDomain = config.get<string>('externalClientsConfig.clientsUrls.jobManager.jobDomain');
}

//TODO: once will be only one kind of exported jobs, no need to filter by ROI's
@withSpanAsyncV4
public async getExportJobs(queryParams: IFindJobsRequest): Promise<JobExportResponse[] | undefined> {
this.logger.debug({ ...queryParams }, `Getting jobs that match these parameters`);
Expand Down
4 changes: 1 addition & 3 deletions src/common/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ export interface IArtifactDefinition {
type: ArtifactType;
}

/**
* ROI INTERNAL API - will be deprecated on future by shared exporter
*/
//ROI INTERNAL API - will be deprecated on future by shared exporter
export interface ILinkDefinition {
dataURI: string;
metadataURI: string;
Expand Down
6 changes: 3 additions & 3 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ export const generateGeoIdentifier = (geo: FeatureCollection): string => {
export function createSpanMetadata(
functionName?: string,
spanKind?: SpanKind,
context?: { traceId: string; spanId: string }
parentContext?: { traceId: string; spanId: string }
): { traceContext: SpanContext | undefined; spanOptions: SpanOptions | undefined } {
if (!context) {
if (!parentContext) {
return { spanOptions: undefined, traceContext: undefined };
}
const traceContext: SpanContext = {
...context,
...parentContext,
traceFlags: FLAG_SAMPLED,
};
const spanOptions: SpanOptions = {
Expand Down
16 changes: 3 additions & 13 deletions src/createPackage/models/createPackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,7 @@ import { sep } from 'node:path';
import { Logger } from '@map-colonies/js-logger';
import { SpanContext, SpanKind, Tracer, context, trace } from '@opentelemetry/api';
import { withSpanAsyncV4 } from '@map-colonies/telemetry';
import type {
Polygon,
MultiPolygon,
BBox,
// bbox as PolygonBbox,
// intersect,
// combine as featureCombine,
FeatureCollection,
Feature,
Geometry,
} from '@turf/helpers';
import type { Polygon, MultiPolygon, BBox, FeatureCollection, Feature, Geometry } from '@turf/helpers';
import intersect from '@turf/intersect';
import PolygonBbox from '@turf/bbox';
import featureCombine from '@turf/combine';
Expand Down Expand Up @@ -139,7 +129,7 @@ export class CreatePackageManager {
const layerMetadata = layer.metadata;

const { spanOptions } = createSpanMetadata('createPackageRoi', SpanKind.PRODUCER);
const mainSpan = this.tracer.startSpan('jobManager.job create', spanOptions);
const mainSpan = this.tracer.startSpan('exportPackage create', spanOptions);
trace.setSpan(context.active(), mainSpan);
const mainTraceIds: SpanContext = {
traceId: mainSpan.spanContext().traceId,
Expand Down Expand Up @@ -381,7 +371,7 @@ export class CreatePackageManager {
if (intersaction === null) {
return null;
}
const sanitized = snapBBoxToTileGrid(PolygonBbox(intersaction) as BBox2d, zoom) as BBox2d;
const sanitized = snapBBoxToTileGrid(PolygonBbox(intersaction), zoom) as BBox2d;
return sanitized;
} catch (error) {
throw new Error(`Error occurred while trying to sanitized bbox: ${JSON.stringify(error)}`);
Expand Down
6 changes: 4 additions & 2 deletions src/finalizationManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import config from 'config';
import { inject, singleton } from 'tsyringe';
import { Logger } from '@map-colonies/js-logger';
import { Context, context, propagation, Span, SpanKind, Tracer } from '@opentelemetry/api';
import { Context, context, propagation, Span, SpanKind, trace, Tracer } from '@opentelemetry/api';
import { ITaskResponse, OperationStatus } from '@map-colonies/mc-priority-queue';
import { getUTCDate } from '@map-colonies/mc-utils';
// import { getInitialSpanOption } from './common/utils';
import { withSpanAsyncV4 } from '@map-colonies/telemetry';
import { SERVICES } from './common/constants';
import { TasksManager } from './tasks/models/tasksManager';
Expand Down Expand Up @@ -73,6 +72,9 @@ export class FinalizationManager {
return false;
}

const span = trace.getActiveSpan();
span?.addEvent('export.start.finalize', { finalizeJobFound: true });

return this.runFinalize(finalizeTask);
}

Expand Down
21 changes: 2 additions & 19 deletions tests/mocks/clients/jobManagerWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import { JobManagerWrapper } from '../../../src/clients/jobManagerWrapper';

const findCompletedJobMock = jest.fn();
const findInProgressJobMock = jest.fn();
const findPendingJobMock = jest.fn();
const createMock = jest.fn();
const createExportMock = jest.fn();
const createJobMock = jest.fn();
const getInProgressJobsMock = jest.fn();
const updateJobMock = jest.fn();
const validateAndUpdateExpirationMock = jest.fn();
const getExportJobsMock = jest.fn();
const findExportJobMock = jest.fn();
const deleteTaskByIdMock = jest.fn();

const jobManagerWrapperMock = {
createJob: createJobMock,
findCompletedJob: findCompletedJobMock,
findInProgressJob: findInProgressJobMock,
findPendingJob: findPendingJobMock,
findExportJob: findExportJobMock,
create: createMock,
validateAndUpdateExpirationMock,
createExport: createExportMock,
getInProgressJobs: getInProgressJobsMock,
updateJob: updateJobMock,
getExportJobs: getExportJobsMock,
validateAndUpdateExpiration: validateAndUpdateExpirationMock,
Expand All @@ -30,15 +19,9 @@ const jobManagerWrapperMock = {

export {
jobManagerWrapperMock,
createMock,
validateAndUpdateExpirationMock,
createExportMock,
createJobMock,
findCompletedJobMock,
findInProgressJobMock,
findPendingJobMock,
findExportJobMock,
validateAndUpdateExpirationMock,
getInProgressJobsMock as getInProgressJobsMock,
updateJobMock,
getExportJobsMock,
deleteTaskByIdMock,
Expand Down
23 changes: 1 addition & 22 deletions tests/mocks/clients/packageManager.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
import { CreatePackageManager } from '../../../src/createPackage/models/createPackageManager';

const createPackageMock = jest.fn();
const createJsonMetadataMock = jest.fn();
const createExportJsonMetadataMock = jest.fn();
const getSeparatorMock = jest.fn();
const sanitizeBboxMock = jest.fn();
const checkForDuplicateMock = jest.fn();
const checkForCompletedMock = jest.fn();

const packageManagerMock = {
createPackage: createPackageMock,
createJsonMetadata: createJsonMetadataMock,
createExportJsonMetadata: createExportJsonMetadataMock,
getSeparator: getSeparatorMock,
sanitizeBbox: sanitizeBboxMock,
checkForDuplicate: checkForDuplicateMock,
checkForCompleted: checkForCompletedMock,
} as unknown as CreatePackageManager;

export {
packageManagerMock,
createPackageMock,
createJsonMetadataMock,
getSeparatorMock,
sanitizeBboxMock,
checkForDuplicateMock,
checkForCompletedMock,
createExportJsonMetadataMock,
};
export { packageManagerMock, createExportJsonMetadataMock };
9 changes: 0 additions & 9 deletions tests/mocks/clients/taskManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import { TasksManager } from '../../../src/tasks/models/tasksManager';

const getFinalizeJobByIdMock = jest.fn();
const getExportJobsByTaskStatusMock = jest.fn();
const getTaskStatusByJobIdMock = jest.fn();
const sendCallbacksMock = jest.fn();
const sendExportCallbacksMock = jest.fn();
const finalizeJobMock = jest.fn();
const finalizeGPKGSuccessMock = jest.fn();
const finalizeGPKGFailureMock = jest.fn();
Expand All @@ -14,9 +11,6 @@ const deleteTaskByIdMock = jest.fn();
const taskManagerMock = {
getFinalizeJobById: getFinalizeJobByIdMock,
getExportJobsByTaskStatus: getExportJobsByTaskStatusMock,
getTaskStatusByJobId: getTaskStatusByJobIdMock,
sendCallbacks: sendCallbacksMock,
sendExportCallbacks: sendExportCallbacksMock,
finalizeJob: finalizeJobMock,
finalizeGPKGSuccess: finalizeGPKGSuccessMock,
finalizeGPKGFailure: finalizeGPKGFailureMock,
Expand All @@ -28,9 +22,6 @@ export {
taskManagerMock,
getFinalizeJobByIdMock,
getExportJobsByTaskStatusMock,
getTaskStatusByJobIdMock,
sendCallbacksMock,
sendExportCallbacksMock,
finalizeJobMock,
finalizeGPKGSuccessMock,
finalizeGPKGFailureMock,
Expand Down

0 comments on commit 7378fa6

Please sign in to comment.