Skip to content

Commit 7c3ece7

Browse files
committed
feat(library): Introduce Loki 2.9 as library
Add Loki 2.9 as library for log collection and querying README.md: Instructions for using Loki library in the project loki-local-config.yml: Sample configuration for Loki Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>
1 parent 5a22d73 commit 7c3ece7

File tree

6 files changed

+352
-0
lines changed

6 files changed

+352
-0
lines changed

library/loki/2.9/.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.git
2+
.gitignore
3+
/Makefile.uk
4+
/.unikraft/
5+
/.config*
6+
README.md

library/loki/2.9/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/Makefile.uk
2+
/.unikraft/
3+
/.config*

library/loki/2.9/Dockerfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
FROM golang:1.22-alpine AS loki-build
2+
3+
WORKDIR /loki
4+
5+
# Dependencies
6+
RUN set -xe; \
7+
apk --no-cache add \
8+
gcc \
9+
make \
10+
musl-dev \
11+
wget \
12+
git \
13+
linux-headers \
14+
upx \
15+
binutils \
16+
; \
17+
update-ca-certificates;
18+
19+
# Build Loki as static PIE with size optimizations
20+
RUN set -xe; \
21+
git clone https://github.com/grafana/loki.git .; \
22+
git checkout v2.9.8; \
23+
CGO_ENABLED=1 \
24+
go build -v \
25+
-buildmode=pie \
26+
-ldflags "-linkmode external -extldflags '-static-pie' -s -w" \
27+
-tags 'osusergo netgo static_build' \
28+
-trimpath \
29+
-o /usr/local/bin/loki \
30+
./cmd/loki; \
31+
strip /usr/local/bin/loki; \
32+
upx --best --lzma /usr/local/bin/loki
33+
34+
FROM alpine:3 AS sys
35+
36+
RUN set -xe; \
37+
mkdir -p /target/etc; \
38+
mkdir -p /target/tmp/loki/chunks; \
39+
mkdir -p /target/tmp/loki/rules; \
40+
mkdir -p /target/etc/loki; \
41+
mkdir -p /blank; \
42+
apk --no-cache add \
43+
ca-certificates \
44+
; \
45+
update-ca-certificates;
46+
47+
FROM scratch
48+
49+
COPY --from=sys /target/etc /etc
50+
COPY --from=sys /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
51+
COPY --from=sys /blank /tmp
52+
COPY --from=sys /target/tmp /tmp
53+
54+
COPY --from=loki-build /usr/local/bin/loki /usr/local/bin/loki
55+
COPY loki-local-config.yaml /etc/loki/loki-local-config.yaml

library/loki/2.9/Kraftfile

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
spec: v0.6
2+
3+
name: loki
4+
5+
rootfs: ./Dockerfile
6+
7+
cmd: ["/usr/local/bin/loki", "-config.file=/etc/loki/loki-local-config.yaml"]
8+
9+
template:
10+
source: https://github.com/unikraft/app-elfloader.git
11+
version: staging
12+
13+
unikraft:
14+
source: https://github.com/unikraft/unikraft.git
15+
version: staging
16+
kconfig:
17+
# Configurations options for app-elfloader
18+
# (they can't be part of the template atm)
19+
CONFIG_LIBPOSIX_PROCESS_ARCH_PRCTL: 'y'
20+
CONFIG_APPELFLOADER_BRK: 'y'
21+
CONFIG_APPELFLOADER_CUSTOMAPPNAME: 'y'
22+
CONFIG_APPELFLOADER_STACK_NBPAGES: 128
23+
CONFIG_APPELFLOADER_VFSEXEC_EXECBIT: 'n'
24+
CONFIG_APPELFLOADER_ENFORCE_PIE: 'n'
25+
CONFIG_APPELFLOADER_VFSEXEC: 'y'
26+
CONFIG_APPELFLOADER_AUTOGEN_REPLACEEXIST: 'y'
27+
# Unikraft options
28+
CONFIG_HAVE_PAGING_DIRECTMAP: 'y'
29+
CONFIG_HAVE_PAGING: 'y'
30+
CONFIG_I8042: 'y'
31+
CONFIG_LIBDEVFS_AUTOMOUNT: 'y'
32+
CONFIG_LIBDEVFS_DEV_NULL: 'y'
33+
CONFIG_LIBDEVFS_DEV_STDOUT: 'y'
34+
CONFIG_LIBDEVFS_DEV_ZERO: 'y'
35+
CONFIG_LIBDEVFS: 'y'
36+
CONFIG_LIBPOSIX_ENVIRON_ENVP0: "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
37+
CONFIG_LIBPOSIX_ENVIRON_ENVP1: "LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib"
38+
CONFIG_LIBPOSIX_ENVIRON_ENVP2: "HOME=/"
39+
CONFIG_LIBPOSIX_ENVIRON: 'y'
40+
CONFIG_LIBPOSIX_ENVIRON_LIBPARAM: 'y'
41+
CONFIG_LIBPOSIX_ENVIRON_LIBPARAM_MAXCOUNT: '64'
42+
CONFIG_LIBPOSIX_EVENTFD: 'y'
43+
CONFIG_LIBPOSIX_FDIO: 'y'
44+
CONFIG_LIBPOSIX_FDTAB: 'y'
45+
CONFIG_LIBPOSIX_FUTEX: 'y'
46+
CONFIG_LIBPOSIX_MMAP: 'y'
47+
CONFIG_LIBPOSIX_PIPE: 'y'
48+
CONFIG_LIBPOSIX_POLL: 'y'
49+
CONFIG_LIBPOSIX_PROCESS: 'y'
50+
CONFIG_LIBPOSIX_PROCESS_MULTITHREADING: 'y'
51+
CONFIG_LIBPOSIX_SOCKET: 'y'
52+
CONFIG_LIBPOSIX_SYSINFO: 'y'
53+
CONFIG_LIBPOSIX_TIME: 'y'
54+
CONFIG_LIBPOSIX_TIMERFD: 'y'
55+
CONFIG_LIBPOSIX_UNIXSOCKET: 'y'
56+
CONFIG_LIBPOSIX_USER_GID: 0
57+
CONFIG_LIBPOSIX_USER_GROUPNAME: "root"
58+
CONFIG_LIBPOSIX_USER_UID: 0
59+
CONFIG_LIBPOSIX_USER_USERNAME: "root"
60+
CONFIG_LIBPOSIX_USER: 'y'
61+
CONFIG_LIBRAMFS: 'y'
62+
CONFIG_LIBSYSCALL_SHIM_HANDLER_ULTLS: 'y'
63+
CONFIG_LIBSYSCALL_SHIM_HANDLER: 'y'
64+
CONFIG_LIBSYSCALL_SHIM_LEGACY_VERBOSE: 'y'
65+
CONFIG_LIBSYSCALL_SHIM: 'y'
66+
CONFIG_LIBUKALLOCPOOL: 'y'
67+
CONFIG_LIBUKBLKDEV_MAXNBQUEUES: '1'
68+
CONFIG_LIBUKBLKDEV_DISPATCHERTHREADS: 'y'
69+
CONFIG_LIBUKBLKDEV_SYNC_IO_BLOCKED_WAITING: 'y'
70+
CONFIG_LIBUKBLKDEV: 'y'
71+
CONFIG_LIBUKBOOT_BANNER_MINIMAL: 'y'
72+
CONFIG_LIBUKBOOT_HEAP_BASE: '0x400000000'
73+
CONFIG_LIBUKBOOT_MAINTHREAD: 'y'
74+
CONFIG_LIBUKBOOT_SHUTDOWNREQ_HANDLER: 'y'
75+
CONFIG_LIBUKCPIO: 'y'
76+
CONFIG_LIBUKDEBUG_CRASH_SCREEN: 'y'
77+
CONFIG_LIBUKDEBUG_ENABLE_ASSERT: 'y'
78+
CONFIG_LIBUKDEBUG_PRINT_SRCNAME: 'n'
79+
CONFIG_LIBUKDEBUG_PRINT_TIME: 'y'
80+
CONFIG_LIBUKDEBUG_PRINTK_ERR: 'y'
81+
CONFIG_LIBUKDEBUG_PRINTK: 'y'
82+
CONFIG_LIBUKDEBUG: 'y'
83+
CONFIG_LIBUKFALLOC: 'y'
84+
CONFIG_LIBUKMPI: 'n'
85+
CONFIG_LIBUKSIGNAL: 'y'
86+
CONFIG_LIBUKRANDOM_DEVFS: 'y'
87+
CONFIG_LIBUKRANDOM: 'y'
88+
CONFIG_LIBUKRANDOM_GETRANDOM: 'y'
89+
CONFIG_LIBUKVMEM_DEFAULT_BASE: '0x0000001000000000'
90+
CONFIG_LIBUKVMEM_DEMAND_PAGE_IN_SIZE: 12
91+
CONFIG_LIBUKVMEM_PAGEFAULT_HANDLER_PRIO: 4
92+
CONFIG_LIBUKVMEM: 'y'
93+
CONFIG_LIBVFSCORE_AUTOMOUNT_CI: 'y'
94+
CONFIG_LIBVFSCORE_AUTOMOUNT_CI_EINITRD: 'y'
95+
CONFIG_LIBVFSCORE_NONLARGEFILE: 'y'
96+
CONFIG_LIBVFSCORE: 'y'
97+
CONFIG_OPTIMIZE_DEADELIM: 'y'
98+
CONFIG_OPTIMIZE_LTO: 'y'
99+
CONFIG_PAGING: 'y'
100+
CONFIG_STACK_SIZE_PAGE_ORDER: 4 # 128 * 4K = 512K
101+
CONFIG_UKPLAT_MEMREGION_MAX_COUNT: 64
102+
CONFIG_LIBUKNETDEV_EINFO_LIBPARAM: 'y'
103+
104+
# Debug options
105+
# CONFIG_LIBUKDEBUG_PRINTD: 'y'
106+
# CONFIG_LIBUKDEBUG_PRINTK_INFO: 'y'
107+
# CONFIG_LIBSYSCALL_SHIM_STRACE: 'y'
108+
# CONFIG_LIBSYSCALL_SHIM_DEBUG: 'y'
109+
110+
libraries:
111+
lwip:
112+
source: https://github.com/unikraft/lib-lwip.git
113+
version: staging
114+
kconfig:
115+
CONFIG_LWIP_TCP: 'y'
116+
CONFIG_LWIP_UDP: 'y'
117+
CONFIG_LWIP_RAW: 'y'
118+
CONFIG_LWIP_WND_SCALE: 'y'
119+
CONFIG_LWIP_TCP_KEEPALIVE: 'y'
120+
CONFIG_LWIP_THREADS: 'y'
121+
CONFIG_LWIP_HEAP: 'y'
122+
CONFIG_LWIP_SOCKET: 'y'
123+
CONFIG_LWIP_AUTOIFACE: 'y'
124+
CONFIG_LWIP_NUM_TCPCON: 64
125+
CONFIG_LWIP_NUM_TCPLISTENERS: 64
126+
CONFIG_LWIP_ICMP: 'y'
127+
CONFIG_LWIP_DHCP: 'y'
128+
CONFIG_LWIP_DNS: 'n'
129+
libelf:
130+
source: https://github.com/unikraft/lib-libelf.git
131+
version: staging
132+
133+
targets:
134+
- qemu/x86_64

library/loki/2.9/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Loki
2+
3+
This directory contains the [Loki](https://grafana.com/oss/loki/) log aggregation system on Unikraft, in binary compatibility mode.
4+
It implements a Loki instance running on Unikraft.
5+
6+
## Run and Use
7+
8+
Use `kraft` to run the image and start a Unikraft instance:
9+
10+
```bash
11+
kraft run --rm -M 2048M -p 3100:3100 --plat qemu --arch x86_64 unikraft.org/loki:2.9
12+
```
13+
14+
If the `--plat` argument is left out, it defaults to `qemu`.
15+
If the `--arch` argument is left out, it defaults to your system's CPU architecture.
16+
17+
Once executed, it will open port `3100` and wait for connections.
18+
To test it, you can use `curl`:
19+
20+
```bash
21+
curl localhost:3100/ready
22+
```
23+
24+
You should see "ready" response from Loki.
25+
26+
## Push Logs
27+
28+
To push logs to Loki, you can use the following curl command:
29+
30+
```bash
31+
curl -v -H "Content-Type: application/json" -XPOST "http://localhost:3100/loki/api/v1/push" --data-raw \
32+
'{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1570818238000000000", "fizzbuzz" ] ] }]}'
33+
```
34+
35+
## Query Logs
36+
37+
To query logs from Loki:
38+
39+
```bash
40+
curl -G -s "http://localhost:3100/loki/api/v1/query" --data-urlencode 'query={foo="bar2"}' | jq
41+
```
42+
43+
## Inspect and Close
44+
45+
To list information about the Unikraft instance, use:
46+
47+
```bash
48+
kraft ps
49+
```
50+
51+
To close the Unikraft instance, close the `kraft` process (e.g., via `Ctrl+c`) or run:
52+
53+
```bash
54+
kraft rm <instance_name>
55+
```
56+
57+
## Build and Run Locally
58+
59+
To build a local image, clone this repository and `cd` into this directory.
60+
Then use `kraft` to build an image locally:
61+
62+
```bash
63+
kraft build --no-cache --no-update --plat qemu --arch x86_64
64+
```
65+
66+
In order to run the locally built image, use `.` as the final argument:
67+
68+
```bash
69+
kraft run --rm -M 2048M -p 3100:3100 --plat qemu --arch x86_64 .
70+
```
71+
72+
## Learn More
73+
74+
- [How to run unikernels locally](https://unikraft.org/docs/cli/running)
75+
- [Loki Documentation](https://grafana.com/docs/loki/latest/)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
auth_enabled: false
2+
3+
server:
4+
http_listen_port: 3100
5+
grpc_listen_port: 9096
6+
7+
common:
8+
instance_addr: 127.0.0.1
9+
path_prefix: /tmp/loki
10+
storage:
11+
filesystem:
12+
chunks_directory: /tmp/loki/chunks
13+
rules_directory: /tmp/loki/rules
14+
replication_factor: 1
15+
ring:
16+
instance_addr: 127.0.0.1
17+
kvstore:
18+
store: inmemory
19+
20+
ingester:
21+
lifecycler:
22+
address: 127.0.0.1
23+
ring:
24+
kvstore:
25+
store: inmemory
26+
replication_factor: 1
27+
final_sleep: 0s
28+
chunk_idle_period: 1h
29+
max_chunk_age: 1h
30+
chunk_target_size: 1048576
31+
chunk_retain_period: 30s
32+
33+
query_range:
34+
results_cache:
35+
cache:
36+
embedded_cache:
37+
enabled: true
38+
max_size_mb: 100
39+
40+
schema_config:
41+
configs:
42+
- from: 2020-10-24
43+
store: boltdb-shipper
44+
object_store: filesystem
45+
schema: v11
46+
index:
47+
prefix: index_
48+
period: 24h
49+
50+
storage_config:
51+
boltdb_shipper:
52+
active_index_directory: /tmp/loki/boltdb-shipper-active
53+
cache_location: /tmp/loki/boltdb-shipper-cache
54+
shared_store: filesystem
55+
filesystem:
56+
directory: /tmp/loki/chunks
57+
58+
limits_config:
59+
reject_old_samples: true
60+
reject_old_samples_max_age: 168h
61+
62+
chunk_store_config:
63+
max_look_back_period: 0s
64+
65+
table_manager:
66+
retention_deletes_enabled: false
67+
retention_period: 0s
68+
69+
ruler:
70+
storage:
71+
type: local
72+
local:
73+
directory: /tmp/loki/rules
74+
rule_path: /tmp/loki/rules-temp
75+
alertmanager_url: http://localhost:9093
76+
ring:
77+
kvstore:
78+
store: inmemory
79+
enable_api: true

0 commit comments

Comments
 (0)