Skip to content

Commit aa8514e

Browse files
authored
feat: detiler compitability (#26)
* fix: multiple bugs and unexpected behaviors caused by syncing upstream * fix: multiple bugs * fix: env variables compatible with osm2pgsql v1.6.0 * feat: added application metrics * fix: added metrics helm values * fix: minor tweaks * feat: detiler compitability * fix: dockerfile osm2pgsql commit sha * fix(configurations): dockerfile library dependency * fix: integration bugs
1 parent 802ae61 commit aa8514e

File tree

7 files changed

+43
-13
lines changed

7 files changed

+43
-13
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM ubuntu:20.04 as build
44

55
ENV DEBIAN_FRONTEND=noninteractive
66
ARG OSM2PGSQL_REPOSITORY=https://github.com/MapColonies/osm2pgsql.git
7-
ARG OSM2PGSQL_COMMIT_SHA=6c68ead630575bc2545cd668c6e6dc7b6d4772f9
7+
ARG OSM2PGSQL_COMMIT_SHA=078884e01c1dc3c9c20c85cf9e57436b294e7e65
88
ARG OSMIUM_TOOL_TAG=v1.16.0
99
ARG PROTOZERO_TAG=v1.7.1
1010
ARG LIBOSMIUM_TAG=v2.20.0
@@ -74,7 +74,7 @@ RUN ln -s /osm2pgsql/osm2pgsql /bin/osm2pgsql && ln -s /osmium-tool/build/osmium
7474
RUN apt-get update \
7575
&& apt-get -yq install curl \
7676
&& curl -L https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash \
77-
&& apt-get -yq install nodejs libboost-filesystem-dev libpq-dev libproj-dev liblua5.3-dev libboost-program-options-dev
77+
&& apt-get -yq install nodejs libboost-filesystem-dev libpq-dev libproj-dev liblua5.3-dev libboost-program-options-dev libexpat1-dev
7878

7979
COPY ./package*.json ./
8080

src/cli/commands/append/appendFactory.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ export const appendCommandFactory: FactoryFunction<CommandModule<GlobalArguments
4545
})
4646
.option('uploadTargets', {
4747
alias: ['u', 'upload-targets'],
48-
type: 'string',
48+
type: 'array',
4949
describe: 'upload expired tiles to the selected sources',
5050
choices: ['s3', 'queue'],
51-
array: true,
51+
string: true,
5252
default: [] as string[],
53+
coerce: (targetsString: string) => {
54+
return targetsString[0] ? targetsString[0].split(',') : [];
55+
},
5356
})
5457
.option('name', {
5558
alias: ['queue-name'],
@@ -89,7 +92,7 @@ export const appendCommandFactory: FactoryFunction<CommandModule<GlobalArguments
8992
const configContent = await fsPromises.readFile(config, 'utf-8');
9093
const appendEntities = JSON.parse(configContent) as AppendEntity[];
9194

92-
logger.debug({ msg: 'append configuration', projectId: s3ProjectId, entitiesCount: appendEntities.length });
95+
logger.info({ msg: 'append configuration', projectId: s3ProjectId, entitiesCount: appendEntities.length, uploadTargets });
9396

9497
await manager.prepareManager(s3ProjectId, appendEntities, uploadTargets as ExpireTilesUploadTarget[]);
9598

src/cli/commands/append/appendManager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ export class AppendManager {
146146
try {
147147
await this.appendNextState(replicationUrl);
148148

149+
await this.stateTracker.updateRemoteTimestamp();
150+
149151
if (this.shouldGenerateExpireOutput) {
150152
await this.uploadExpired();
151153
}
@@ -204,6 +206,8 @@ export class AppendManager {
204206
try {
205207
await this.appendNextState(replicationUrl);
206208

209+
await this.stateTracker.updateRemoteTimestamp();
210+
207211
if (this.shouldGenerateExpireOutput) {
208212
await this.uploadExpired();
209213
}
@@ -351,6 +355,7 @@ export class AppendManager {
351355
entityId: entity.id,
352356
localExpireTilesListPath,
353357
expireListCount: expireList.length,
358+
state: this.stateTracker.nextState,
354359
});
355360

356361
for await (const target of this.uploadTargets) {
@@ -412,6 +417,7 @@ export class AppendManager {
412417
const payload: TileRequestQueuePayload = {
413418
items: expiredTilesBbox.map((bbox) => ({ area: bbox, minZoom, maxZoom })),
414419
source: 'expiredTiles',
420+
state: this.stateTracker.nextState,
415421
};
416422

417423
await this.pushPayloadToQueue(payload);

src/cli/commands/append/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ export interface TileRequestQueuePayloadItem<A = BoundingBox | Feature> extends
3131
export interface TileRequestQueuePayload<A = BoundingBox | Feature> {
3232
items: TileRequestQueuePayloadItem<A>[];
3333
source: 'expiredTiles';
34+
state?: number;
35+
force?: boolean;
3436
}

src/cli/commands/append/stateTracker.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { join } from 'path';
22
import { inject, singleton } from 'tsyringe';
33
import { Logger } from '@map-colonies/js-logger';
4-
import { DATA_DIR, DEFAULT_SEQUENCE_NUMBER, SEQUENCE_NUMBER_REGEX, SERVICES, STATE_FILE } from '../../../common/constants';
4+
import { DATA_DIR, DEFAULT_SEQUENCE_NUMBER, SEQUENCE_NUMBER_REGEX, SERVICES, STATE_FILE, TIMESTAMP_REGEX } from '../../../common/constants';
55
import { BucketDoesNotExistError, InvalidStateFileError } from '../../../common/errors';
66
import { createDirectory, fetchSequenceNumber, streamToString } from '../../../common/util';
77
import { ReplicationClient } from '../../../httpClient/replicationClient';
@@ -95,6 +95,29 @@ export class StateTracker {
9595
this.totalAppends++;
9696
}
9797

98+
public async updateRemoteTimestamp(): Promise<void> {
99+
const updatedTimestamp = new Date()
100+
.toISOString()
101+
.replace(/\.\d+Z$/, 'Z')
102+
.replace(/:/g, '\\:');
103+
104+
this.logger.info({
105+
msg: 'attempting to update remote timestamp on configured bucket',
106+
projectId: this.projectId,
107+
currentState: this.current,
108+
toState: this.nextState,
109+
bucketName: this.s3Client.bucketName,
110+
acl: this.s3Client.acl,
111+
updatedTimestamp,
112+
});
113+
114+
stateContent = stateContent.replace(TIMESTAMP_REGEX, `timestamp=${updatedTimestamp}`);
115+
const stateBuffer = Buffer.from(stateContent, 'utf-8');
116+
const stateKey = join(this.projectId, STATE_FILE);
117+
118+
await this.s3Client.putObjectWrapper(stateKey, stateBuffer);
119+
}
120+
98121
private fetchSequenceNumberSafely(content: string): number {
99122
try {
100123
return fetchSequenceNumber(content);

src/cli/middlewares/index.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ type RegisterOnContainerMiddlewareFactory<T> = (container: DependencyContainer)
1818

1919
export const s3RegistrationMiddlewareFactory: RegisterOnContainerMiddlewareFactory<GlobalArguments> = (dependencyContainer) => {
2020
const middleware = (args: Arguments<GlobalArguments>): void => {
21-
const { s3Endpoint, s3BucketName } = args;
21+
const { s3Endpoint, s3BucketName, s3Acl } = args;
2222

2323
const configStore = dependencyContainer.resolve<ConfigStore>(SERVICES.CONFIG_STORE);
24-
configStore.set('s3', { bucketName: s3BucketName });
24+
configStore.set('s3', { bucketName: s3BucketName, acl: s3Acl });
2525

2626
const client = new S3Client({
2727
endpoint: s3Endpoint,
@@ -89,11 +89,6 @@ export const uploadTargetsRegistrationMiddlewareFactory: RegisterOnContainerMidd
8989
},
9090
]);
9191
}
92-
93-
if (uploadTargetsSet.has('s3')) {
94-
const { s3Acl } = args;
95-
configStore.set('s3.acl', s3Acl);
96-
}
9792
}
9893
};
9994

src/common/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const DEFAULT_SEQUENCE_NUMBER = -1;
5353
export const DEFAULT_PROJECT_CREATION_STATE = 1;
5454
export const SEQUENCE_NUMBER = 'sequenceNumber';
5555
export const SEQUENCE_NUMBER_REGEX = /sequenceNumber=\d+/;
56+
export const TIMESTAMP_REGEX = /timestamp=\d{4}-\d{2}-\d{2}T\d{2}\\?:\d{2}\\?:\d{2}Z/;
5657
export const SEQUENCE_NUMBER_PADDING_AMOUNT = 3;
5758
export const DIFF_TOP_DIR_DIVIDER = 1000000;
5859
export const DIFF_BOTTOM_DIR_DIVIDER = 1000;

0 commit comments

Comments
 (0)