Skip to content

Commit

Permalink
feat(experimental): kick off inventory project
Browse files Browse the repository at this point in the history
Track projects and their licenses
Docker compose configuration for dev with logging tracing and metrics (mostly done)
CRUD for mongo
  • Loading branch information
06kellyjac committed Dec 6, 2024
1 parent f696fd4 commit 3296303
Show file tree
Hide file tree
Showing 25 changed files with 9,488 additions and 0 deletions.
1 change: 1 addition & 0 deletions experimental/license-inventory/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
43 changes: 43 additions & 0 deletions experimental/license-inventory/dev/grafana/datasources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: 1

datasources:
- name: Loki
type: loki
uid: loki
access: proxy
url: http://loki:3100
basicAuth: false
version: 1
editable: false
isDefault: true

- name: Prometheus
type: prometheus
uid: prometheus
access: proxy
orgId: 1
url: http://prometheus:9090
basicAuth: false
isDefault: false
version: 1
editable: false
jsonData:
httpMethod: GET

- name: Tempo
type: tempo
uid: tempo
access: proxy
orgId: 1
url: http://tempo:3200
basicAuth: false
isDefault: false
version: 1
editable: false
jsonData:
tracesToLogsV2:
datasourceUid: loki
filterByTraceID: true
filterBySpanID: true
tracesToMetrics:
datasourceUid: prometheus
49 changes: 49 additions & 0 deletions experimental/license-inventory/dev/loki.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
auth_enabled: false

server:
http_listen_port: 3100
grpc_listen_port: 9096

common:
instance_addr: 127.0.0.1
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory

frontend:
max_outstanding_per_tenant: 2048

pattern_ingester:
enabled: true

limits_config:
max_global_streams_per_user: 0
ingestion_rate_mb: 50000
ingestion_burst_size_mb: 50000
volume_enabled: true

query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 100

schema_config:
configs:
- from: 2020-10-24
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h

analytics:
reporting_enabled: false
52 changes: 52 additions & 0 deletions experimental/license-inventory/dev/otel-collector-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
extensions:
health_check:
pprof:
endpoint: 127.0.0.1:1777
zpages:
endpoint: 127.0.0.1:55679

receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318

# collect own metrics
prometheus:
config:
scrape_configs:
- job_name: otel-collector
scrape_interval: 10s
static_configs:
- targets:
- 127.0.0.1:8888

exporters:
loki:
endpoint: http://loki:3100/loki/api/v1/push
prometheus:
endpoint: 127.0.0.1:8889
namespace: otel-collector
send_timestamps: true
metric_expiration: 180m
enable_open_metrics: true
add_metric_suffixes: false
resource_to_telemetry_conversion:
enabled: true
otlphttp:
endpoint: http://tempo:4318

processors:
batch:

service:
pipelines:
traces:
receivers: [otlp]
exporters: [otlphttp]
metrics:
receivers: [otlp]
exporters: [prometheus]
logs:
receivers: [otlp]
exporters: [loki]
20 changes: 20 additions & 0 deletions experimental/license-inventory/dev/prometheus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
global:
scrape_interval: 15s
evaluation_interval: 15s

scrape_configs:
- job_name: prometheus
static_configs:
- targets: [ 'localhost:9090' ]
- job_name: tempo
static_configs:
- targets: [ 'tempo:3200' ]
- job_name: promtail
static_configs:
- targets: [ 'promtail:9080' ]
- job_name: otel-collector
static_configs:
- targets: [ 'otel-collector:8889' ]
- job_name: otel-collector-meta
static_configs:
- targets: [ 'otel-collector:8888' ]
14 changes: 14 additions & 0 deletions experimental/license-inventory/dev/promtail.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
positions:
filename: /tmp/positions.yaml

clients:
- url: http://loki:3100/loki/api/v1/push

scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: mongo
__path__: /var/log-mongo/mongo.log*
40 changes: 40 additions & 0 deletions experimental/license-inventory/dev/tempo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
stream_over_http_enabled: true
server:
http_listen_port: 3200

distributor:
receivers:
otlp:
protocols:
http:

compactor:
compaction:
block_retention: 1h

metrics_generator:
registry:
external_labels:
source: tempo
cluster: docker-compose
storage:
path: /var/tempo/generator/wal
remote_write:
- url: http://prometheus:9090/api/v1/write
send_exemplars: true
traces_storage:
path: /var/tempo/generator/traces

storage:
trace:
backend: local
wal:
path: /var/tempo/wal
local:
path: /var/tempo/blocks

overrides:
defaults:
metrics_generator:
processors: [service-graphs, span-metrics, local-blocks]
generate_native_histograms: both
132 changes: 132 additions & 0 deletions experimental/license-inventory/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
services:
init:
image: alpine:3.20
init: true
volumes:
- mongo-logs:/var/log-mongo
- tempo-data:/var/tempo
command: >
chmod 777 /var/log-mongo && chown -R 10001:10001 /var/tempo
app:
container_name: license-inventory
image: node:23-alpine
# ensure colours show
tty: true
command: >
sh -c "npm install --include=optional && npm run dev"
environment:
MONGO_URI: mongodb://mongo:27017/inventory
OTEL_TRACES_EXPORTER: otlp
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
OTEL_SERVICE_NAME: license-inventory
OTEL_RESOURCE_ATTRIBUTES: service.version=0.0.0
NODE_OPTIONS: --require @opentelemetry/auto-instrumentations-node/register
ports:
- 3000:3000
working_dir: /usr/src/app
volumes:
- .:/usr/src/app
# have a separate node dependencies
# avoids permissions conflicts
- node-deps:/usr/src/app/node_modules
depends_on:
- mongo
- otel-collector

mongo:
image: mongo:8.0.3
command: --logpath=/var/log/mongo.log
ports:
- 27017:27017
volumes:
- mongo-data:/data/db
- mongo-logs:/var/log
depends_on:
- init

otel-collector:
image: otel/opentelemetry-collector-contrib:0.114.0
volumes:
- ./dev/otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml
depends_on:
- loki
- tempo

promtail:
image: grafana/promtail:3.3.0
command:
- -config.file=/etc/promtail/config.yaml
- -log.level=warn
volumes:
- ./dev/promtail.yaml:/etc/promtail/config.yaml
- mongo-logs:/var/log-mongo
depends_on:
- loki

# traces
tempo:
image: grafana/tempo:2.6.1
command:
- -config.file=/etc/tempo.yaml
- -log.level=warn
volumes:
- ./dev/tempo.yaml:/etc/tempo.yaml
- tempo-data:/var/tempo
depends_on:
- init
- prometheus

# metrics
prometheus:
image: prom/prometheus:v3.0.0
command:
- --config.file=/etc/prometheus.yaml
- --enable-feature=exemplar-storage
- --enable-feature=native-histograms
- --web.enable-remote-write-receiver
- --enable-feature=otlp-write-receive
- --web.enable-otlp-receiver
- --log.level=warn
volumes:
- ./dev/prometheus.yaml:/etc/prometheus.yaml
ports:
- 9090:9090

# logs
loki:
image: grafana/loki:3.3.0
command:
- -config.file=/etc/loki/loki.yaml
- -log.level=warn
ports:
- 3100:3100
volumes:
- ./dev/loki.yaml:/etc/loki/loki.yaml

# everything dashboard
grafana:
image: grafana/grafana:11.3.1
ports:
- 3001:3000
volumes:
- ./dev/grafana/datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml
environment:
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
- GF_AUTH_DISABLE_LOGIN_FORM=true
- GF_FEATURE_TOGGLES_ENABLE=traceqlEditor metricsSummary
- GF_INSTALL_PLUGINS=grafana-lokiexplore-app,grafana-exploretraces-app
# seem to get auth warnings even though we're on anonymous auth
- GF_LOG_LEVEL=error
depends_on:
- loki
- tempo
- prometheus

volumes:
mongo-logs:
mongo-data:
tempo-data:
node-deps:
12 changes: 12 additions & 0 deletions experimental/license-inventory/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";


/** @type {import('eslint').Linter.Config[]} */
export default [
{files: ["**/*.{js,mjs,cjs,ts}"]},
{languageOptions: { globals: globals.node }},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
];
6 changes: 6 additions & 0 deletions experimental/license-inventory/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watch": ["src", ".env"],
"ext": "js,ts,json",
"ignore": ["src/**/*.{spec,test}.ts"],
"exec": "ts-node -r tsconfig-paths/register --transpile-only src/server.ts | pino-pretty"
}
Loading

0 comments on commit 3296303

Please sign in to comment.