Skip to content

Commit

Permalink
chore: move error parsing backend-side and return error path to front…
Browse files Browse the repository at this point in the history
…end (#189)

* chore: move error parsing backend-side and return error path to frontend

* fix: do not include trailing ':' in error path, do not modify error message

* chore: remove debug output

* chore: minor refactoring for understandability

* fix: error path as array, support named pipelines in error path extraction
  • Loading branch information
mmanciop authored Nov 9, 2023
1 parent 30a048a commit 1a13eba
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/otelbin-validation-image/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ export const validateOtelCol = async (otelcolRealPath: string, configPath: strin
});
};

const extractErrorPath = (errorMessage: string) => {
const errorPathMatch = errorMessage.match(/^((?:(?:[\w\/]+)(?:\:\:)?)+):[^:]/);
if (errorPathMatch) {
// We have a prefix for the error that specified a path
return errorPathMatch[1]?.split('::');
}
};

export const handler = async (event: APIGatewayEvent): Promise<APIGatewayProxyResult> => {
const config = event.body;

Expand Down Expand Up @@ -170,10 +178,13 @@ export const handler = async (event: APIGatewayEvent): Promise<APIGatewayProxyRe
error = error.substring(defaultErrorPrefix.length);
}

const path = extractErrorPath(error);

return {
statusCode: 200,
// Unfortunately the collector returns one validation error at the time
body: JSON.stringify({
path,
message: 'The provided configuration is invalid',
error,
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Learn more about the OpenTelemetry Collector via
# https://opentelemetry.io/docs/collector/

receivers:
otlp:
protocols:
grpc:
http:

processors:
batch:

exporters:
otlp:
endpoint: otelcol:4317

extensions:
health_check:
pprof:
zpages:

service:
extensions: [health_check, pprof, zpages]
pipelines:
traces/dash0:
receivers: [jaeger]
processors: [batch]
exporters: [otlp]
metrics/dash0:
receivers: [otlp]
processors: [batch]
exporters: [otlp]
logs/dash0:
receivers: [otlp]
processors: [batch]
exporters: [otlp]
19 changes: 19 additions & 0 deletions packages/otelbin-validation/test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const otelcolConfigValid = readConfig('config-default.yaml');
const otelcolConfigInvalidNoReceivers = readConfig('config-no-receivers.yaml');
const otelcolConfigInvalidUndeclaredExtension = readConfig('config-undeclared-extension.yaml');
const otelcolConfigInvalidUndeclaredReceiver = readConfig('config-undeclared-receiver.yaml');
const otelcolConfigInvalidUndeclaredReceiverNamedPipeline = readConfig('config-undeclared-receiver-named-pipelines.yaml');

describe.each(enumerateTestCases())('Validation API', (distributionName, release) => {

Expand Down Expand Up @@ -153,12 +154,29 @@ describe.each(enumerateTestCases())('Validation API', (distributionName, release
})).resolves.toMatchObject({
status: 200,
data: {
path: ['service', 'pipelines', 'traces'],
message: 'The provided configuration is invalid',
error: 'service::pipelines::traces: references receiver "jaeger" which is not configured',
},
});
}, defaultTimeout);

test('rejects configuration with undeclared receiver in named pipeline', async () => {
await expect(axios.post(validationUrl, otelcolConfigInvalidUndeclaredReceiverNamedPipeline, {
headers: {
'Content-Type': 'application/yaml',
'X-Api-Key': apiKey,
},
})).resolves.toMatchObject({
status: 200,
data: {
path: ['service', 'pipelines', 'traces/dash0'],
message: 'The provided configuration is invalid',
error: 'service::pipelines::traces/dash0: references receiver "jaeger" which is not configured',
},
});
}, defaultTimeout);

test('rejects configuration with undeclared extension', async () => {
await expect(axios.post(validationUrl, otelcolConfigInvalidUndeclaredExtension, {
headers: {
Expand All @@ -168,6 +186,7 @@ describe.each(enumerateTestCases())('Validation API', (distributionName, release
})).resolves.toMatchObject({
status: 200,
data: {
path: ['service', 'extensions'],
message: 'The provided configuration is invalid',
error: 'service::extensions: references extension "health_check" which is not configured',
},
Expand Down

0 comments on commit 1a13eba

Please sign in to comment.