Skip to content

Commit

Permalink
Merge branch 'main' of github.com:dash0hq/otelbin into selectable-err…
Browse files Browse the repository at this point in the history
…or-validation-console-texts
  • Loading branch information
Roshan Ghojoghi committed Nov 9, 2023
2 parents cad5584 + 1a13eba commit af89103
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 17 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
3 changes: 0 additions & 3 deletions packages/otelbin/src/components/AppHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { LogIn } from "lucide-react";
import { Share } from "~/components/share/Share";
import { SignedIn, SignedOut, SignInButton, UserButton } from "@clerk/nextjs";
import { Button } from "~/components/button";
import InfoBox from "./validation-type/InfoBox";
import ValidationType from "./validation-type/ValidationType";

export default function AppHeader() {
Expand All @@ -21,8 +20,6 @@ export default function AppHeader() {
<div className="w-px bg-neutral-350 h-full">&nbsp;</div>

<ValidationType />

<InfoBox />
</div>
<div className="flex gap-x-2">
<Share />
Expand Down
32 changes: 18 additions & 14 deletions packages/otelbin/src/components/validation-type/ValidationType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ValidationTypeContent from "./ValidationTypeContent";
import { useDistributions } from "../validation/useDistributions";
import { useUrlState } from "~/lib/urlState/client/useUrlState";
import { distroBinding, distroVersionBinding } from "../validation/binding";
import InfoBox from "./InfoBox";

export interface ICurrentDistro {
distro: string;
Expand All @@ -28,19 +29,22 @@ export default function ValidationType() {
: undefined;

return (
<Popover open={open} onOpenChange={setOpen} modal={true}>
<PopoverTrigger asChild>
<Button size="xs" variant="cta">
Validation:{" "}
<strong>{`${currentDistro?.provider ?? "Browser-only"} ${currentDistro ? " – " : ""} ${
currentDistro ? currentDistro.version : ""
}`}</strong>{" "}
<Down />
</Button>
</PopoverTrigger>
<PopoverContent align="start" className="p-0 max-w-[480px] overflow-y-auto max-h-[90vh]">
<ValidationTypeContent currentDistro={currentDistro} data={data} setOpen={setOpen} />
</PopoverContent>
</Popover>
<div className="flex items-center gap-x-4">
<Popover open={open} onOpenChange={setOpen} modal={true}>
<PopoverTrigger asChild>
<Button size="xs" variant="cta">
Validation:{" "}
<strong>{`${currentDistro?.provider ?? "Browser-only"} ${currentDistro ? " – " : ""} ${
currentDistro ? currentDistro.version : ""
}`}</strong>{" "}
<Down />
</Button>
</PopoverTrigger>
<PopoverContent align="start" className="p-0 max-w-[480px] overflow-y-auto max-h-[90vh]">
<ValidationTypeContent currentDistro={currentDistro} data={data} setOpen={setOpen} />
</PopoverContent>
</Popover>
{distro === null && distroVersion === null && <InfoBox />}
</div>
);
}

0 comments on commit af89103

Please sign in to comment.