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 5 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,7 +220,7 @@
}
},
"composed_of": [
"aws_vpc_flow",
"vpc_flow",
Swiddis marked this conversation as resolved.
Show resolved Hide resolved
"cloud",
"communication",
"s3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"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

"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,22 +21,27 @@
},
"components": [
{
"name": "aws_vpc_flow",
"catalog_dir": "observability/logs/aws",
"name": "vpc_flow",
"version": "1.0.0"
},
{
"catalog_dir": "observability/logs",
"name": "cloud",
"version": "1.0.0"
},
{
"catalog_dir": "observability/logs",
"name": "communication",
"version": "1.0.0"
},
{
"catalog_dir": "observability/logs",
"name": "logs_vpc",
"version": "1.0.0"
},
{
"catalog_dir": "observability/logs/aws",
"name": "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,6 @@
"description": "Nginx HTTP server collector",
"license": "Apache-2.0",
"type": "logs",
"link": "https://www.nginx.com/",
"author": "OpenSearch",
"sourceUrl": "https://github.com/opensearch-project/dashboards-observability/tree/main/server/adaptors/integrations/__data__/repository/nginx/info",
"statics": {
Expand All @@ -22,14 +21,17 @@
},
"components": [
{
"catalog_dir": "observability/logs",
Swiddis marked this conversation as resolved.
Show resolved Hide resolved
"name": "communication",
"version": "1.0.0"
},
{
"catalog_dir": "observability/logs",
"name": "http",
"version": "1.0.0"
},
{
"catalog_dir": "observability/logs",
"name": "logs",
"version": "1.0.0"
}
Expand All @@ -39,6 +41,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,39 @@ describe('Integration', () => {

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

it('should utilize the catalog path when finding components', async () => {
const sampleConfig = {
components: [
{ name: 'component1', version: '1.0.0', catalog_dir: 'one/two' },
{ name: 'component2', version: '2.0.0', catalog_dir: 'three' },
],
};
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/one/two/component1-1.0.0.mapping.json'),
{ encoding: 'utf-8' }
);
expect(fs.readFile).toHaveBeenCalledWith(
path.join(integration.directory, '../../catalog/three/component2-2.0.0.mapping.json'),
{ encoding: 'utf-8' }
);
});
});

describe('getStatic', () => {
Expand Down
14 changes: 10 additions & 4 deletions server/adaptors/integrations/repository/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,16 @@ 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 schemaFile = path.join(
component.catalog_dir ?? '.',
`${component.name}-${component.version}.mapping.json`
);
const rawSchema = await fs.readFile(
path.join(this.directory, '../../catalog', schemaFile),
{
encoding: 'utf-8',
}
);
const parsedSchema = JSON.parse(rawSchema);
result.mappings[component.name] = parsedSchema;
}
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 @@ -38,6 +38,7 @@ interface StaticAsset {
interface IntegrationComponent {
name: string;
version: string;
catalog_dir?: string;
}

interface DisplayAsset {
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 @@ -46,6 +46,7 @@ const templateSchema: JSONSchemaType<IntegrationTemplate> = {
properties: {
name: { type: 'string' },
version: { type: 'string' },
catalog_dir: { type: 'string', nullable: true },
},
required: ['name', 'version'],
},
Expand Down
Loading