Skip to content

Commit

Permalink
misc: finalized config files
Browse files Browse the repository at this point in the history
  • Loading branch information
sheensantoscapadngan committed Jun 5, 2024
1 parent 6089553 commit 33b49f4
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ CLIENT_SECRET_GITHUB_LOGIN=
CLIENT_ID_GITLAB_LOGIN=
CLIENT_SECRET_GITLAB_LOGIN=

TELEMETRY_EXPORT_URL=
OTEL_COLLECTOR_OTLP_URL=
17 changes: 17 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@opentelemetry/api": "^1.8.0",
"@opentelemetry/auto-instrumentations-node": "^0.46.1",
"@opentelemetry/exporter-metrics-otlp-proto": "^0.51.1",
"@opentelemetry/exporter-prometheus": "^0.51.1",
"@opentelemetry/instrumentation": "^0.51.1",
"@opentelemetry/resources": "^1.24.1",
"@opentelemetry/sdk-metrics": "^1.24.1",
Expand Down
2 changes: 1 addition & 1 deletion backend/src/lib/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const envSchema = z
.optional(),
INFISICAL_CLOUD: zodStrBool.default("false"),
MAINTENANCE_MODE: zodStrBool.default("false"),
TELEMETRY_EXPORT_URL: zpStr(z.string().optional())
OTEL_COLLECTOR_OTLP_URL: zpStr(z.string().optional())
})
.transform((data) => ({
...data,
Expand Down
33 changes: 21 additions & 12 deletions backend/src/lib/telemetry/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
import opentelemetry from "@opentelemetry/api";
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-proto";
import { PrometheusExporter } from "@opentelemetry/exporter-prometheus";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { Resource } from "@opentelemetry/resources";
import { AggregationTemporality, MeterProvider, PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
import { SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_SERVICE_VERSION } from "@opentelemetry/semantic-conventions";

export const initTelemetry = (exportURL: string) => {
export const initTelemetry = async ({ otlpURL }: { otlpURL?: string }) => {
const resource = Resource.default().merge(
new Resource({
[SEMRESATTRS_SERVICE_NAME]: "infisical-server",
[SEMRESATTRS_SERVICE_VERSION]: "0.1.0"
})
);

const metricExporter = new OTLPMetricExporter({
url: `${exportURL}/v1/metrics`,
temporalityPreference: AggregationTemporality.DELTA
});
const metricReaders = [];
if (otlpURL) {
const otlpExporter = new OTLPMetricExporter({
url: `${otlpURL}/v1/metrics`,
temporalityPreference: AggregationTemporality.DELTA
});

const metricReader = new PeriodicExportingMetricReader({
exporter: metricExporter,
exportIntervalMillis: 30000
});
metricReaders.push(
new PeriodicExportingMetricReader({
exporter: otlpExporter,
exportIntervalMillis: 30000
})
);
} else {
const promExporter = new PrometheusExporter();
metricReaders.push(promExporter);
}

const myServiceMeterProvider = new MeterProvider({
const meterProvider = new MeterProvider({
resource,
readers: [metricReader]
readers: metricReaders
});

opentelemetry.metrics.setGlobalMeterProvider(myServiceMeterProvider);
opentelemetry.metrics.setGlobalMeterProvider(meterProvider);

registerInstrumentations({
instrumentations: [getNodeAutoInstrumentations()]
Expand Down
4 changes: 1 addition & 3 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ const run = async () => {
const logger = await initLogger();
const appCfg = initEnvConfig(logger);

if (appCfg.TELEMETRY_EXPORT_URL) {
initTelemetry(appCfg.TELEMETRY_EXPORT_URL);
}
await initTelemetry({ otlpURL: appCfg.OTEL_COLLECTOR_OTLP_URL });

const db = initDbConnection({
dbConnectionUri: appCfg.DB_CONNECTION_URI,
Expand Down
201 changes: 201 additions & 0 deletions docker-compose.dev.observable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
version: "3.9"

services:
nginx:
container_name: infisical-dev-nginx
image: nginx
restart: always
ports:
- 8080:80
volumes:
- ./nginx/default.dev.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- backend
- frontend

db:
image: postgres:14-alpine
ports:
- "5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: infisical
POSTGRES_USER: infisical
POSTGRES_DB: infisical

redis:
image: redis
container_name: infisical-dev-redis
environment:
- ALLOW_EMPTY_PASSWORD=yes
ports:
- 6379:6379
volumes:
- redis_data:/data

redis-commander:
container_name: infisical-dev-redis-commander
image: rediscommander/redis-commander
restart: always
depends_on:
- redis
environment:
- REDIS_HOSTS=local:redis:6379
ports:
- "8085:8081"

db-test:
profiles: ["test"]
image: postgres:14-alpine
ports:
- "5430:5432"
environment:
POSTGRES_PASSWORD: infisical
POSTGRES_USER: infisical
POSTGRES_DB: infisical-test

db-migration:
container_name: infisical-db-migration
depends_on:
- db
build:
context: ./backend
dockerfile: Dockerfile.dev
env_file: .env
environment:
- DB_CONNECTION_URI=postgres://infisical:infisical@db/infisical?sslmode=disable
command: npm run migration:latest
volumes:
- ./backend/src:/app/src

backend:
container_name: infisical-dev-api
build:
context: ./backend
dockerfile: Dockerfile.dev
depends_on:
db:
condition: service_started
redis:
condition: service_started
db-migration:
condition: service_completed_successfully
env_file:
- .env
ports:
- 4000:4000
- 9464:9464 # for OTEL collection of Prometheus metrics
environment:
- NODE_ENV=development
- DB_CONNECTION_URI=postgres://infisical:infisical@db/infisical?sslmode=disable
- TELEMETRY_ENABLED=false
volumes:
- ./backend/src:/app/src
extra_hosts:
- "host.docker.internal:host-gateway"

frontend:
container_name: infisical-dev-frontend
restart: unless-stopped
depends_on:
- backend
build:
context: ./frontend
dockerfile: Dockerfile.dev
volumes:
- ./frontend/src:/app/src/ # mounted whole src to avoid missing reload on new files
- ./frontend/public:/app/public
env_file: .env
environment:
- NEXT_PUBLIC_ENV=development
- INFISICAL_TELEMETRY_ENABLED=false

pgadmin:
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: pass
ports:
- 5050:80
depends_on:
- db

smtp-server:
container_name: infisical-dev-smtp-server
image: lytrax/mailhog:latest # https://github.com/mailhog/MailHog/issues/353#issuecomment-821137362
restart: always
logging:
driver: "none" # disable saving logs
ports:
- 1025:1025 # SMTP server
- 8025:8025 # Web UI

openldap: # note: more advanced configuration is available
image: osixia/openldap:1.5.0
restart: always
environment:
LDAP_ORGANISATION: Acme
LDAP_DOMAIN: acme.com
LDAP_ADMIN_PASSWORD: admin
ports:
- 389:389
- 636:636
volumes:
- ldap_data:/var/lib/ldap
- ldap_config:/etc/ldap/slapd.d
profiles: [ldap]

phpldapadmin: # username: cn=admin,dc=acme,dc=com, pass is admin
image: osixia/phpldapadmin:latest
restart: always
environment:
- PHPLDAPADMIN_LDAP_HOSTS=openldap
- PHPLDAPADMIN_HTTPS=false
ports:
- 6433:80
depends_on:
- openldap
profiles: [ldap]

otel-collector:
image: otel/opentelemetry-collector-contrib
volumes:
- ./otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml
ports:
- 1888:1888 # pprof extension
- 8888:8888 # Prometheus metrics exposed by the Collector
- 8889:8889 # Prometheus exporter metrics
- 13133:13133 # health_check extension
- 4317:4317 # OTLP gRPC receiver
- 4318:4318 # OTLP http receiver
- 55679:55679 # zpages extension

prometheus:
image: prom/prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
command:
- "--config.file=/etc/prometheus/prometheus.yml"

grafana:
image: grafana/grafana
container_name: grafana
restart: unless-stopped
environment:
- GF_LOG_LEVEL=debug
ports:
- "3000:3000"
volumes:
- "grafana_storage:/var/lib/grafana"
volumes:
postgres-data:
driver: local
redis_data:
driver: local
ldap_data:
ldap_config:
grafana_storage:
33 changes: 0 additions & 33 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,43 +158,10 @@ services:
- openldap
profiles: [ldap]

otel-collector:
image: otel/opentelemetry-collector-contrib
volumes:
- ./otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml
ports:
- 1888:1888 # pprof extension
- 8888:8888 # Prometheus metrics exposed by the Collector
- 8889:8889 # Prometheus exporter metrics
- 13133:13133 # health_check extension
- 4317:4317 # OTLP gRPC receiver
- 4318:4318 # OTLP http receiver
- 55679:55679 # zpages extension

prometheus:
image: prom/prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
command:
- "--config.file=/etc/prometheus/prometheus.yml"

grafana:
image: grafana/grafana
container_name: grafana
restart: unless-stopped
environment:
- GF_LOG_LEVEL=debug
ports:
- "3000:3000"
volumes:
- "grafana_storage:/var/lib/grafana"
volumes:
postgres-data:
driver: local
redis_data:
driver: local
ldap_data:
ldap_config:
grafana_storage:
12 changes: 11 additions & 1 deletion otel-collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ receivers:
protocols:
http:
endpoint: 0.0.0.0:4318
prometheus:
config:
scrape_configs:
- job_name: otel-collector
scrape_interval: 30s
static_configs:
- targets: [backend:9464]
metric_relabel_configs:
- action: labeldrop
regex: "service_instance_id|service_name"
processors:
batch:

Expand All @@ -20,6 +30,6 @@ service:
extensions: [health_check, pprof, zpages]
pipelines:
metrics:
receivers: [otlp]
receivers: [otlp, prometheus]
processors: [batch]
exporters: [prometheus]

0 comments on commit 33b49f4

Please sign in to comment.