Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit 5d98787

Browse files
authored
Emitting Otel traces when the database syncs (#3)
This is a very simple span, but it gives us insight into if/when syncs are occurring.
1 parent 3fbada4 commit 5d98787

9 files changed

+45
-6
lines changed

.dockerignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
*
2-
!docker-build-resources/
2+
!docker-build-resources/etc
3+
!docker-build-resources/opentelemetry-shell/library
4+
!docker-build-resources/sync.sh

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "docker-build-resources/opentelemetry-shell"]
2+
path = docker-build-resources/opentelemetry-shell
3+
url = https://github.com/voriteam/opentelemetry-shell.git

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ENV LITEFS_DB_DIRECTORY=/litefs
2626
ENV LITEFS_INTERNAL_DATA_DIRECTORY=/var/lib/litefs
2727

2828
WORKDIR /
29+
COPY docker-build-resources/opentelemetry-shell /opentelemetry-shell
2930
COPY docker-build-resources/sync.sh /sync.sh
3031

3132
ENTRYPOINT litefs mount

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ docker buildx build --platform linux/amd64,linux/arm64 -t us-docker.pkg.dev/vori
5858
```
5959

6060
### Homebrew
61-
The POS machines run a service installed via Homebrew. Create a release on GitHub, and follow the instructions at
62-
https://github.com/voriteam/homebrew-voripos to update the tap with the latest version.
61+
1. Update `VORIPOS_DOMAIN_SYNC_VERSION`.
62+
2. Create a release on GitHub.
63+
3. Follow the instructions at https://github.com/voriteam/homebrew-voripos to update the tap with the latest version.

docker-build-resources/etc/litefs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ lease:
1919
# and false on the replicas.
2020
candidate: $IS_PRIMARY
2121

22-
exec: "sh sync.sh"
22+
exec: "bash sync.sh"

docker-build-resources/sync.sh

+21-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ set -e
44
set +v
55
set +x
66

7+
# OpenTelemetry setup
8+
export OTEL_EXPORTER_OTEL_ENDPOINT="http://host.docker.internal:4318"
9+
export OTEL_SH_LIB_PATH="opentelemetry-shell/library"
10+
service_version=$OTEL_SERVICE_VERSION
11+
. opentelemetry-shell/library/otel_traces.sh
12+
713
Normal='\033[0m'
814
Underline='\033[4m'
915

@@ -40,7 +46,21 @@ sync_database() {
4046
if test -s $sourcePath; then
4147
# NOTE: We execute the restore in the container since it is more performant than restoring on a host volume.
4248
echo -e "${Yellow}Copying $sourcePath to $destPath...${Normal}"
43-
time cp $sourcePath $destPath
49+
50+
# Create an Otel span
51+
generatedAt=$(sqlite3 $sourcePath "SELECT generated_at FROM metadata;")
52+
schemaVersion=$(sqlite3 $sourcePath "SELECT schema_version FROM metadata;")
53+
local span_name="Copy domain data to host"
54+
local custom_resource_attributes=(
55+
"domain_data_generated_at:$generatedAt"
56+
"domain_data_schema_version:$schemaVersion"
57+
)
58+
local linkedTraceId=$(sqlite3 $sourcePath "SELECT linked_trace_id FROM metadata;")
59+
local linkedTraceState=$(sqlite3 $sourcePath "SELECT linked_trace_state FROM metadata;")
60+
local linkedSpanId=$(sqlite3 $sourcePath "SELECT linked_span_id FROM metadata;")
61+
echo "[Linked Span Data] linkedTraceId: $linkedTraceId, linkedTraceState: $linkedTraceState, linkedSpanId: $linkedSpanId"
62+
local linked_span=("$linkedTraceId" "$linkedSpanId" "$linkedTraceState")
63+
otel_trace_start_parent_span cp $sourcePath $destPath
4464

4565
echo -e "${Green}Successfully copied ${name} to ${destPath}$Normal"
4666
sqlite3 $destPath ".mode table" "SELECT * FROM metadata;"

docker-compose.yml

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ services:
1414
LITEFS_CLOUD_TOKEN: ${LITEFS_CLOUD_TOKEN}
1515
FILE_RETENTION_COUNT: ${FILE_RETENTION_COUNT}
1616
DOMAIN_DB_NAME: Domain.sqlite3
17+
OTEL_EXPORTER_OTEL_ENDPOINT: "http://host.docker.internal:4318"
18+
OTEL_SERVICE_NAME: voripos-domain-sync
19+
OTEL_SERVICE_VERSION: ${VORIPOS_DOMAIN_SYNC_VERSION}
20+
OTEL_LOG_LEVEL: debug
1721
volumes:
1822
# Bind mounts help decrease data transfer latency. We no longer perform SQLite restores but,
1923
# when we tested them with bind mounts, the bind mount dropped restore time from 4 minutes down to 20 seconds.

voripos-domain-sync.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
#!/bin/bash
22

3+
set -e
4+
set +v
5+
set +x
6+
37
# This is needed to locate the Docker executable
48
export PATH="/usr/local/bin:$PATH"
59

10+
export VORIPOS_DOMAIN_SYNC_VERSION=0.4.0
11+
612
# NOTE: Bash must be given Full Disk Access in order to read the user defaults.
713
# See https://www.kith.org/jed/2022/02/15/launchctl-scheduling-shell-scripts-on-macos-and-full-disk-access/.
8-
export LITEFS_CLOUD_TOKEN=$(defaults read com.vori.VoriPOS provisioned_litefsCloudToken)
14+
LITEFS_CLOUD_TOKEN=$(defaults read com.vori.VoriPOS provisioned_litefsCloudToken)
15+
export LITEFS_CLOUD_TOKEN
916
export VORIPOS_DATA_DIR="$HOME/Library/Containers/com.vori.VoriPOS/Data/Library/Application Support/Domain"
1017

1118
# Keep the most-recent 100 files to ensure we (a) don't fill the disk while

0 commit comments

Comments
 (0)