Skip to content

Commit

Permalink
Backwards compatibility fix for teraslice (#998)
Browse files Browse the repository at this point in the history
This PR makes the following changes:

- Introduces backwards compatibility for teraslice versions before
`v1.4.0`
- This fixes an issue where using a teraslice version older than version
`v1.4.0` would throw `TypeError: this.promMetrics.addGauge is not a
function`
- Bump **file-assets** to `v2.11.1`
- Updates the following dependencies:
  - **@terascope/job-components** from `v0.74.2` to `v0.75.0`

ref: terascope/teraslice#3625
  • Loading branch information
sotojn authored May 24, 2024
1 parent f40ff3f commit 43d6822
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion asset/asset.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "file",
"version": "2.11.0",
"version": "2.11.1",
"description": "A set of processors for working with files"
}
4 changes: 2 additions & 2 deletions asset/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "file",
"displayName": "Asset",
"version": "2.11.0",
"version": "2.11.1",
"private": true,
"description": "A set of processors for working with files",
"repository": {
Expand All @@ -21,7 +21,7 @@
},
"dependencies": {
"@terascope/file-asset-apis": "^0.13.0",
"@terascope/job-components": "^0.74.2",
"@terascope/job-components": "^0.75.0",
"csvtojson": "^2.0.10",
"fs-extra": "^11.2.0",
"json2csv": "5.0.7",
Expand Down
26 changes: 14 additions & 12 deletions asset/src/s3_exporter/processor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BatchProcessor, DataEntity } from '@terascope/job-components';
import { BatchProcessor, DataEntity, isPromAvailable } from '@terascope/job-components';
import { S3Sender } from '@terascope/file-asset-apis';
import { S3ExportConfig } from './interfaces';
import { S3SenderFactoryAPI } from '../s3_sender_api/interfaces';
Expand All @@ -15,17 +15,19 @@ export default class S3Batcher extends BatchProcessor<S3ExportConfig> {
this.api = await apiManager.create(apiName, { dynamic_routing: false });
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
await this.context.apis.foundation.promMetrics.addGauge(
'records_written_to_s3',
'Number of records written into s3',
['op_name'],
async function collect() {
const labels = {
op_name: 's3_exporter',
...self.context.apis.foundation.promMetrics.getDefaultLabels()
};
this.set(labels, self.getTotalWrittenS3Records());
});
if (isPromAvailable(this.context)) {
await this.context.apis.foundation.promMetrics.addGauge(
'records_written_to_s3',
'Number of records written into s3',
['op_name'],
async function collect() {
const labels = {
op_name: 's3_exporter',
...self.context.apis.foundation.promMetrics.getDefaultLabels()
};
this.set(labels, self.getTotalWrittenS3Records());
});
}
}

async onBatch(slice: DataEntity[]): Promise<DataEntity[]> {
Expand Down
26 changes: 14 additions & 12 deletions asset/src/s3_reader/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fetcher, DataEntity } from '@terascope/job-components';
import { Fetcher, DataEntity, isPromAvailable } from '@terascope/job-components';
import { FileSlice, S3TerasliceAPI } from '@terascope/file-asset-apis';
import { S3ReaderConfig } from './interfaces';
import { S3ReaderFactoryAPI } from '../s3_reader_api/interfaces';
Expand All @@ -14,17 +14,19 @@ export default class S3Fetcher extends Fetcher<S3ReaderConfig> {
this.api = await apiManager.create(apiName, {} as any);
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
await this.context.apis.foundation.promMetrics.addGauge(
'records_read_from_s3',
'Number of records read from s3',
['op_name'],
async function collect() {
const labels = {
op_name: 's3_reader',
...self.context.apis.foundation.promMetrics.getDefaultLabels()
};
this.set(labels, self.getTotalReadS3Records());
});
if (isPromAvailable(this.context)) {
await this.context.apis.foundation.promMetrics.addGauge(
'records_read_from_s3',
'Number of records read from s3',
['op_name'],
async function collect() {
const labels = {
op_name: 's3_reader',
...self.context.apis.foundation.promMetrics.getDefaultLabels()
};
this.set(labels, self.getTotalReadS3Records());
});
}
}

async fetch(slice: FileSlice): Promise<DataEntity[]> {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "file-assets-bundle",
"displayName": "File Assets Bundle",
"version": "2.11.0",
"version": "2.11.1",
"private": true,
"description": "A set of processors for working with files",
"repository": "https://github.com/terascope/file-assets.git",
Expand Down Expand Up @@ -31,7 +31,7 @@
"devDependencies": {
"@terascope/eslint-config": "^0.8.0",
"@terascope/file-asset-apis": "^0.13.0",
"@terascope/job-components": "^0.74.2",
"@terascope/job-components": "^0.75.0",
"@terascope/scripts": "^0.77.2",
"@types/fs-extra": "^11.0.2",
"@types/jest": "^29.5.12",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1890,12 +1890,12 @@
progress "^2.0.3"
yargs "^17.2.1"

"@terascope/job-components@^0.74.2":
version "0.74.2"
resolved "https://registry.yarnpkg.com/@terascope/job-components/-/job-components-0.74.2.tgz#de875f792644abf3324f74d98e6b7daa046d7fff"
integrity sha512-FEliIWkcK43Q+kiONkwutXgV/f9qQMGUjesmJq9IyqYswOd7ZHtlXCjBUziKqdUWZ01OZ3YDzFxeuufJoLflUg==
"@terascope/job-components@^0.75.0":
version "0.75.0"
resolved "https://registry.yarnpkg.com/@terascope/job-components/-/job-components-0.75.0.tgz#03739729d7d7aee722b6291418987084cf65aaa9"
integrity sha512-QbIAKfbjX5Wj8A/hZvjE0E8y9hvW9QecQIw6eMwTRneudx2OPQcissCCYNlxBpfP13dK/U85BIqOVFZRTh8KcA==
dependencies:
"@terascope/utils" "^0.59.1"
"@terascope/utils" "^0.59.2"
convict "^6.2.4"
convict-format-with-moment "^6.2.0"
convict-format-with-validator "^6.2.0"
Expand Down

0 comments on commit 43d6822

Please sign in to comment.