Skip to content

Commit d720e47

Browse files
kamilkisielan1ru4l
authored andcommitted
wip
1 parent 7e753a5 commit d720e47

24 files changed

+5155
-34
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM scratch AS config
2+
3+
COPY builder-config.yaml .
4+
5+
FROM golang:1.23.7-bookworm AS builder
6+
7+
ARG OTEL_VERSION=0.122.0
8+
9+
WORKDIR /build
10+
11+
RUN go install go.opentelemetry.io/collector/cmd/builder@v${OTEL_VERSION}
12+
13+
# Copy the manifest file and other necessary files
14+
COPY --from=config builder-config.yaml .
15+
16+
# Build the custom collector
17+
RUN CGO_ENABLED=0 builder --config=/build/builder-config.yaml
18+
19+
# Stage 2: Final Image
20+
FROM alpine:3.14
21+
22+
WORKDIR /app
23+
24+
# Copy the generated collector binary from the builder stage
25+
COPY --from=builder /build/otelcol-custom .
26+
27+
# Expose necessary ports
28+
EXPOSE 4317/tcp 4318/tcp 13133/tcp
29+
30+
# Set the default command
31+
CMD ["./otelcol-custom", "--config=/etc/otel-config.yaml"]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
dist:
2+
version: 0.122.0
3+
name: otelcol-custom
4+
description: Custom OTel Collector distribution
5+
output_path: ./otelcol-custom
6+
7+
receivers:
8+
- gomod: go.opentelemetry.io/collector/receiver/otlpreceiver v0.122.0
9+
10+
processors:
11+
- gomod: go.opentelemetry.io/collector/processor/batchprocessor v0.122.0
12+
- gomod:
13+
github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor
14+
v0.122.0
15+
16+
exporters:
17+
- gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.122.0
18+
- gomod:
19+
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter v0.122.0
20+
21+
extensions:
22+
- gomod:
23+
github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension
24+
v0.122.0
25+
- gomod:
26+
github.com/graphql-hive/opentelemetry-collector-contrib/extension/hiveauthextension cd0c57cf22
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
extensions:
2+
hiveauth:
3+
endpoint: ${HIVE_OTEL_AUTH_ENDPOINT}
4+
receivers:
5+
otlp:
6+
protocols:
7+
grpc:
8+
include_metadata: true
9+
endpoint: '0.0.0.0:4317'
10+
auth:
11+
authenticator: hiveauth
12+
http:
13+
cors:
14+
allowed_origins: ['*']
15+
allowed_headers: ['*']
16+
include_metadata: true
17+
endpoint: '0.0.0.0:4318'
18+
auth:
19+
authenticator: hiveauth
20+
processors:
21+
batch:
22+
timeout: 5s
23+
send_batch_size: 100000
24+
attributes:
25+
actions:
26+
- key: hive.target_id
27+
from_context: auth.targetId
28+
action: insert
29+
exporters:
30+
# debug:
31+
# verbosity: detailed
32+
# sampling_initial: 5
33+
# sampling_thereafter: 200
34+
clickhouse:
35+
endpoint: tcp://clickhouse:9000?dial_timeout=10s&compress=lz4
36+
database: default
37+
async_insert: true
38+
username: test
39+
password: test
40+
create_schema: true
41+
ttl: 720h
42+
compress: lz4
43+
logs_table_name: otel_logs
44+
traces_table_name: otel_traces
45+
metrics_table_name: otel_metrics
46+
timeout: 5s
47+
retry_on_failure:
48+
enabled: true
49+
initial_interval: 5s
50+
max_interval: 30s
51+
max_elapsed_time: 300s
52+
service:
53+
extensions:
54+
- hiveauth
55+
telemetry:
56+
logs:
57+
level: INFO
58+
encoding: json
59+
output_paths: ['stdout']
60+
error_output_paths: ['stderr']
61+
pipelines:
62+
traces:
63+
receivers: [otlp]
64+
processors: [attributes, batch]
65+
exporters: [clickhouse]

docker/docker-compose.dev.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ services:
1616
POSTGRES_PASSWORD: postgres
1717
POSTGRES_DB: registry
1818
PGDATA: /var/lib/postgresql/data
19+
HIVE_OTEL_AUTH_ENDPOINT: 'http://host.docker.internal:3001/otel-auth'
1920
volumes:
2021
- ./.hive-dev/postgresql/db:/var/lib/postgresql/data
2122
ports:
@@ -176,5 +177,21 @@ services:
176177
networks:
177178
- 'stack'
178179

180+
otel-collector:
181+
depends_on:
182+
clickhouse:
183+
condition: service_healthy
184+
build:
185+
context: ./configs/otel-collector
186+
dockerfile: Dockerfile
187+
volumes:
188+
- ./configs/otel-collector/builder-config.yaml:/builder-config.yaml
189+
- ./configs/otel-collector/config.yaml:/etc/otel-config.yaml
190+
ports:
191+
- '4317:4317'
192+
- '4318:4318'
193+
networks:
194+
- 'stack'
195+
179196
networks:
180197
stack: {}

docker/docker.hcl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ target "router-base" {
8282
}
8383
}
8484

85+
target "otel-collector-base" {
86+
dockerfile = "${PWD}/docker/otel-collector.dockerfile"
87+
args = {
88+
RELEASE = "${RELEASE}"
89+
}
90+
}
91+
8592
target "cli-base" {
8693
dockerfile = "${PWD}/docker/cli.dockerfile"
8794
args = {
@@ -370,6 +377,23 @@ target "apollo-router" {
370377
]
371378
}
372379

380+
target "otel-collector" {
381+
inherits = ["otel-collector-base", get_target()]
382+
contexts = {
383+
config = "${PWD}/docker/configs/otel-collector"
384+
}
385+
args = {
386+
IMAGE_TITLE = "graphql-hive/otel-collector"
387+
IMAGE_DESCRIPTION = "OTEL Collector for GraphQL Hive."
388+
}
389+
tags = [
390+
local_image_tag("otel-collector"),
391+
stable_image_tag("otel-collector"),
392+
image_tag("otel-collector", COMMIT_SHA),
393+
image_tag("otel-collector", BRANCH_NAME)
394+
]
395+
}
396+
373397
target "cli" {
374398
inherits = ["cli-base", get_target()]
375399
context = "${PWD}/packages/libraries/cli"
@@ -426,6 +450,12 @@ group "apollo-router-hive-build" {
426450
]
427451
}
428452

453+
group "otel-collector-hive-build" {
454+
targets = [
455+
"otel-collector"
456+
]
457+
}
458+
429459
group "cli" {
430460
targets = [
431461
"cli"

docker/otel-collector.dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM golang:1.23.7-bookworm AS builder
2+
3+
ARG OTEL_VERSION=0.122.0
4+
5+
WORKDIR /build
6+
7+
RUN go install go.opentelemetry.io/collector/cmd/builder@v${OTEL_VERSION}
8+
9+
# Copy the manifest file and other necessary files
10+
COPY --from=config builder-config.yaml .
11+
12+
# Build the custom collector
13+
RUN builder --config=/build/builder-config.yaml
14+
15+
# Stage 2: Final Image
16+
FROM alpine:3.14
17+
18+
WORKDIR /app
19+
20+
# Copy the generated collector binary from the builder stage
21+
COPY --from=builder /build/otelcol-custom .
22+
23+
# Expose necessary ports
24+
EXPOSE 4317/tcp 4318/tcp 13133/tcp
25+
26+
# Set the default command
27+
CMD ["./otelcol-custom", "--config=/etc/otel-config.yaml"]

packages/services/server/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import { env } from './environment';
6666
import { graphqlHandler } from './graphql-handler';
6767
import { clickHouseElapsedDuration, clickHouseReadDuration } from './metrics';
6868
import { createPublicGraphQLHandler } from './public-graphql-handler';
69+
import { createOtelAuthEndpoint } from './otel-auth-endpoint';
6970
import { initSupertokens, oidcIdLookup } from './supertokens';
7071

7172
export async function main() {
@@ -592,6 +593,8 @@ export async function main() {
592593
return;
593594
});
594595

596+
createOtelAuthEndpoint(server);
597+
595598
if (env.cdn.providers.api !== null) {
596599
const s3 = {
597600
client: new AwsClient({
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { FastifyInstance } from 'fastify';
2+
3+
export function createOtelAuthEndpoint(server: FastifyInstance) {
4+
server.get('/otel-auth', (req, res) => {
5+
const authHeader = req.headers.authorization;
6+
const targetRefHeader = req.headers['x-hive-target-ref'];
7+
req.log.info('request! ' + authHeader);
8+
9+
if (authHeader === 'Bearer 123') {
10+
if (targetRefHeader !== 'target-1') {
11+
// No access to target-1
12+
res.status(403).send({
13+
message: 'Forbidden access to the target',
14+
});
15+
return;
16+
}
17+
18+
res.status(200).send({
19+
message: 'Authenticated',
20+
targetId: targetRefHeader,
21+
});
22+
} else {
23+
res.status(401).send({
24+
message: 'Unauthorized',
25+
});
26+
}
27+
});
28+
}

packages/web/app/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@
8181
"@urql/exchange-auth": "2.2.0",
8282
"@urql/exchange-graphcache": "7.1.0",
8383
"@vitejs/plugin-react": "4.3.4",
84+
"@xyflow/react": "12.4.4",
8485
"autoprefixer": "10.4.20",
8586
"class-variance-authority": "0.7.1",
8687
"clsx": "2.1.1",
8788
"cmdk": "0.2.1",
8889
"crypto-js": "^4.2.0",
8990
"date-fns": "4.1.0",
91+
"date-fns-tz": "3.2.0",
9092
"dompurify": "3.2.4",
9193
"dotenv": "16.4.7",
9294
"echarts": "5.6.0",
@@ -112,13 +114,15 @@
112114
"react-highlight-words": "0.20.0",
113115
"react-hook-form": "7.54.2",
114116
"react-icons": "5.4.0",
117+
"react-resizable-panels": "2.1.7",
115118
"react-select": "5.9.0",
116119
"react-string-replace": "1.1.1",
117120
"react-textarea-autosize": "8.5.9",
118121
"react-toastify": "10.0.6",
119122
"react-virtualized-auto-sizer": "1.0.25",
120123
"react-virtuoso": "4.12.3",
121124
"react-window": "1.8.11",
125+
"recharts": "2.15.1",
122126
"regenerator-runtime": "0.14.1",
123127
"snarkdown": "2.0.0",
124128
"storybook": "8.4.7",

0 commit comments

Comments
 (0)