Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move schema files to centralized catalog #774

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@
}
},
"composed_of": [
"aws_vpc_flow",
"aws/vpc_flow",
"cloud",
"communication",
"s3"
"aws/s3"
],
"version": 1,
"_meta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"displayName": "AWS VPC Flow",
"description": "AWS VPC Flow log collector",
"license": "Apache-2.0",
"type": "logs",
"type": "logs_vpc",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the logs index based integrations should use the same index template names logs
the only dynamic things that should be integration specific are:

  • index alias
  • composed_of component list

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed that we need to work with these duplicates for now to account for multiple component configs. Let's work on fixing it later, as a hacky solution I can try setting the composed_of list dynamically, but I want to keep this PR small

"catalog_dir": "observability/logs",
"author": "Haidong Wang",
"sourceUrl": "https://github.com/opensearch-project/dashboards-observability/tree/main/server/adaptors/integrations/__data__/repository/aws_vpc_flow/info",
"statics": {
Expand All @@ -21,7 +22,7 @@
},
"components": [
{
"name": "aws_vpc_flow",
"name": "aws/vpc_flow",
"version": "1.0.0"
},
{
Expand All @@ -37,7 +38,7 @@
"version": "1.0.0"
},
{
"name": "s3",
"name": "aws/s3",
"version": "1.0.0"
}
],
Expand Down

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Nginx HTTP server collector",
"license": "Apache-2.0",
"type": "logs",
"link": "https://www.nginx.com/",
"catalog_dir": "observability/logs",
"author": "OpenSearch",
"sourceUrl": "https://github.com/opensearch-project/dashboards-observability/tree/main/server/adaptors/integrations/__data__/repository/nginx/info",
"statics": {
Expand Down Expand Up @@ -39,6 +39,8 @@
"name": "nginx",
"version": "1.0.0"
}
},
"sampleData": {
"path": "sample.json"
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ describe('Integration', () => {
};
integration.getConfig = jest.fn().mockResolvedValue(sampleConfig);

const mappingFile1 = 'component1-1.0.0.mapping.json';
const mappingFile2 = 'component2-2.0.0.mapping.json';

jest
.spyOn(fs, 'readFile')
.mockResolvedValueOnce(JSON.stringify({ mapping: 'mapping1' }))
Expand All @@ -193,11 +190,11 @@ describe('Integration', () => {
});

expect(fs.readFile).toHaveBeenCalledWith(
path.join(integration.directory, 'schemas', mappingFile1),
path.join(integration.directory, '../../catalog/component1-1.0.0.mapping.json'),
{ encoding: 'utf-8' }
);
expect(fs.readFile).toHaveBeenCalledWith(
path.join(integration.directory, 'schemas', mappingFile2),
path.join(integration.directory, '../../catalog/component2-2.0.0.mapping.json'),
{ encoding: 'utf-8' }
);
});
Expand All @@ -219,6 +216,40 @@ describe('Integration', () => {

await expect(integration.getSchemas()).rejects.toThrowError('Could not load schema');
});

it('should utilize the catalog path when finding components', async () => {
const sampleConfig = {
catalog_dir: 'foo/bar',
components: [
{ name: 'component1', version: '1.0.0' },
{ name: 'component2', version: '2.0.0' },
],
};
integration.getConfig = jest.fn().mockResolvedValue(sampleConfig);

jest
.spyOn(fs, 'readFile')
.mockResolvedValueOnce(JSON.stringify({ mapping: 'mapping1' }))
.mockResolvedValueOnce(JSON.stringify({ mapping: 'mapping2' }));

const result = await integration.getSchemas();

expect(result).toEqual({
mappings: {
component1: { mapping: 'mapping1' },
component2: { mapping: 'mapping2' },
},
});

expect(fs.readFile).toHaveBeenCalledWith(
path.join(integration.directory, '../../catalog/foo/bar/component1-1.0.0.mapping.json'),
{ encoding: 'utf-8' }
);
expect(fs.readFile).toHaveBeenCalledWith(
path.join(integration.directory, '../../catalog/foo/bar/component2-2.0.0.mapping.json'),
{ encoding: 'utf-8' }
);
});
});

describe('getStatic', () => {
Expand Down
17 changes: 12 additions & 5 deletions server/adaptors/integrations/repository/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,19 @@ export class Integration {
};
try {
for (const component of config.components) {
const schemaFile = `${component.name}-${component.version}.mapping.json`;
const rawSchema = await fs.readFile(path.join(this.directory, 'schemas', schemaFile), {
encoding: 'utf-8',
});
const rawSchema = await fs.readFile(
path.join(
this.directory,
'../../catalog',
config.catalog_dir ?? '.',
`${component.name}-${component.version}.mapping.json`
),
{
encoding: 'utf-8',
}
);
const parsedSchema = JSON.parse(rawSchema);
result.mappings[component.name] = parsedSchema;
result.mappings[component.name.split('/').pop() as string] = parsedSchema;
}
} catch (err: any) {
// It's not clear that an invalid schema can be recovered from.
Expand Down
1 change: 1 addition & 0 deletions server/adaptors/integrations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface IntegrationTemplate {
displayName?: string;
license: string;
type: string;
catalog_dir?: string;
author?: string;
description?: string;
sourceUrl?: string;
Expand Down
1 change: 1 addition & 0 deletions server/adaptors/integrations/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const templateSchema: JSONSchemaType<IntegrationTemplate> = {
displayName: { type: 'string', nullable: true },
license: { type: 'string' },
type: { type: 'string' },
catalog_dir: { type: 'string', nullable: true },
author: { type: 'string', nullable: true },
description: { type: 'string', nullable: true },
sourceUrl: { type: 'string', nullable: true },
Expand Down
Loading