diff --git a/library/loki/2.9/.dockerignore b/library/loki/2.9/.dockerignore new file mode 100644 index 00000000..e5c80993 --- /dev/null +++ b/library/loki/2.9/.dockerignore @@ -0,0 +1,6 @@ +.git +.gitignore +/Makefile.uk +/.unikraft/ +/.config* +README.md diff --git a/library/loki/2.9/.gitignore b/library/loki/2.9/.gitignore new file mode 100644 index 00000000..a154b6ff --- /dev/null +++ b/library/loki/2.9/.gitignore @@ -0,0 +1,3 @@ +/Makefile.uk +/.unikraft/ +/.config* diff --git a/library/loki/2.9/Dockerfile b/library/loki/2.9/Dockerfile new file mode 100644 index 00000000..cda8ac1f --- /dev/null +++ b/library/loki/2.9/Dockerfile @@ -0,0 +1,55 @@ +FROM golang:1.22-alpine AS loki-build + +WORKDIR /loki + +# Dependencies +RUN set -xe; \ + apk --no-cache add \ + gcc \ + make \ + musl-dev \ + wget \ + git \ + linux-headers \ + upx \ + binutils \ + ; \ + update-ca-certificates; + +# Build Loki as static PIE +RUN set -xe; \ + git clone https://github.com/grafana/loki.git .; \ + git checkout v2.9.8; \ + CGO_ENABLED=1 \ + go build -v \ + -buildmode=pie \ + -ldflags "-linkmode external -extldflags '-static-pie' -s -w" \ + -tags 'osusergo netgo static_build' \ + -trimpath \ + -o /usr/local/bin/loki \ + ./cmd/loki; \ + strip /usr/local/bin/loki; \ + upx --best --lzma /usr/local/bin/loki + +FROM alpine:3 AS sys + +RUN set -xe; \ + mkdir -p /target/etc; \ + mkdir -p /target/tmp/loki/chunks; \ + mkdir -p /target/tmp/loki/rules; \ + mkdir -p /target/etc/loki; \ + mkdir -p /blank; \ + apk --no-cache add \ + ca-certificates \ + ; \ + update-ca-certificates; + +FROM scratch + +COPY --from=sys /target/etc /etc +COPY --from=sys /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=sys /blank /tmp +COPY --from=sys /target/tmp /tmp + +COPY --from=loki-build /usr/local/bin/loki /usr/local/bin/loki +COPY loki-local-config.yaml /etc/loki/loki-local-config.yaml diff --git a/library/loki/2.9/Kraftfile b/library/loki/2.9/Kraftfile new file mode 100644 index 00000000..e1af64e0 --- /dev/null +++ b/library/loki/2.9/Kraftfile @@ -0,0 +1,134 @@ +spec: v0.6 + +name: loki + +rootfs: ./Dockerfile + +cmd: ["/usr/local/bin/loki", "-config.file=/etc/loki/loki-local-config.yaml"] + +template: + source: https://github.com/unikraft/app-elfloader.git + version: staging + +unikraft: + source: https://github.com/unikraft/unikraft.git + version: staging + kconfig: + # Configurations options for app-elfloader + # (they can't be part of the template atm) + CONFIG_LIBPOSIX_PROCESS_ARCH_PRCTL: 'y' + CONFIG_APPELFLOADER_BRK: 'y' + CONFIG_APPELFLOADER_CUSTOMAPPNAME: 'y' + CONFIG_APPELFLOADER_STACK_NBPAGES: 128 + CONFIG_APPELFLOADER_VFSEXEC_EXECBIT: 'n' + CONFIG_APPELFLOADER_ENFORCE_PIE: 'n' + CONFIG_APPELFLOADER_VFSEXEC: 'y' + CONFIG_APPELFLOADER_AUTOGEN_REPLACEEXIST: 'y' + # Unikraft options + CONFIG_HAVE_PAGING_DIRECTMAP: 'y' + CONFIG_HAVE_PAGING: 'y' + CONFIG_I8042: 'y' + CONFIG_LIBDEVFS_AUTOMOUNT: 'y' + CONFIG_LIBDEVFS_DEV_NULL: 'y' + CONFIG_LIBDEVFS_DEV_STDOUT: 'y' + CONFIG_LIBDEVFS_DEV_ZERO: 'y' + CONFIG_LIBDEVFS: 'y' + CONFIG_LIBPOSIX_ENVIRON_ENVP0: "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + CONFIG_LIBPOSIX_ENVIRON_ENVP1: "LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib" + CONFIG_LIBPOSIX_ENVIRON_ENVP2: "HOME=/" + CONFIG_LIBPOSIX_ENVIRON: 'y' + CONFIG_LIBPOSIX_ENVIRON_LIBPARAM: 'y' + CONFIG_LIBPOSIX_ENVIRON_LIBPARAM_MAXCOUNT: '64' + CONFIG_LIBPOSIX_EVENTFD: 'y' + CONFIG_LIBPOSIX_FDIO: 'y' + CONFIG_LIBPOSIX_FDTAB: 'y' + CONFIG_LIBPOSIX_FUTEX: 'y' + CONFIG_LIBPOSIX_MMAP: 'y' + CONFIG_LIBPOSIX_PIPE: 'y' + CONFIG_LIBPOSIX_POLL: 'y' + CONFIG_LIBPOSIX_PROCESS: 'y' + CONFIG_LIBPOSIX_PROCESS_MULTITHREADING: 'y' + CONFIG_LIBPOSIX_SOCKET: 'y' + CONFIG_LIBPOSIX_SYSINFO: 'y' + CONFIG_LIBPOSIX_TIME: 'y' + CONFIG_LIBPOSIX_TIMERFD: 'y' + CONFIG_LIBPOSIX_UNIXSOCKET: 'y' + CONFIG_LIBPOSIX_USER_GID: 0 + CONFIG_LIBPOSIX_USER_GROUPNAME: "root" + CONFIG_LIBPOSIX_USER_UID: 0 + CONFIG_LIBPOSIX_USER_USERNAME: "root" + CONFIG_LIBPOSIX_USER: 'y' + CONFIG_LIBRAMFS: 'y' + CONFIG_LIBSYSCALL_SHIM_HANDLER_ULTLS: 'y' + CONFIG_LIBSYSCALL_SHIM_HANDLER: 'y' + CONFIG_LIBSYSCALL_SHIM_LEGACY_VERBOSE: 'y' + CONFIG_LIBSYSCALL_SHIM: 'y' + CONFIG_LIBUKALLOCPOOL: 'y' + CONFIG_LIBUKBLKDEV_MAXNBQUEUES: '1' + CONFIG_LIBUKBLKDEV_DISPATCHERTHREADS: 'y' + CONFIG_LIBUKBLKDEV_SYNC_IO_BLOCKED_WAITING: 'y' + CONFIG_LIBUKBLKDEV: 'y' + CONFIG_LIBUKBOOT_BANNER_MINIMAL: 'y' + CONFIG_LIBUKBOOT_HEAP_BASE: '0x400000000' + CONFIG_LIBUKBOOT_MAINTHREAD: 'y' + CONFIG_LIBUKBOOT_SHUTDOWNREQ_HANDLER: 'y' + CONFIG_LIBUKCPIO: 'y' + CONFIG_LIBUKDEBUG_CRASH_SCREEN: 'y' + CONFIG_LIBUKDEBUG_ENABLE_ASSERT: 'y' + CONFIG_LIBUKDEBUG_PRINT_SRCNAME: 'n' + CONFIG_LIBUKDEBUG_PRINT_TIME: 'y' + CONFIG_LIBUKDEBUG_PRINTK_ERR: 'y' + CONFIG_LIBUKDEBUG_PRINTK: 'y' + CONFIG_LIBUKDEBUG: 'y' + CONFIG_LIBUKFALLOC: 'y' + CONFIG_LIBUKMPI: 'n' + CONFIG_LIBUKSIGNAL: 'y' + CONFIG_LIBUKRANDOM_DEVFS: 'y' + CONFIG_LIBUKRANDOM: 'y' + CONFIG_LIBUKRANDOM_GETRANDOM: 'y' + CONFIG_LIBUKVMEM_DEFAULT_BASE: '0x0000001000000000' + CONFIG_LIBUKVMEM_DEMAND_PAGE_IN_SIZE: 12 + CONFIG_LIBUKVMEM_PAGEFAULT_HANDLER_PRIO: 4 + CONFIG_LIBUKVMEM: 'y' + CONFIG_LIBVFSCORE_AUTOMOUNT_CI: 'y' + CONFIG_LIBVFSCORE_AUTOMOUNT_CI_EINITRD: 'y' + CONFIG_LIBVFSCORE_NONLARGEFILE: 'y' + CONFIG_LIBVFSCORE: 'y' + CONFIG_OPTIMIZE_DEADELIM: 'y' + CONFIG_OPTIMIZE_LTO: 'y' + CONFIG_PAGING: 'y' + CONFIG_STACK_SIZE_PAGE_ORDER: 4 # 128 * 4K = 512K + CONFIG_UKPLAT_MEMREGION_MAX_COUNT: 64 + CONFIG_LIBUKNETDEV_EINFO_LIBPARAM: 'y' + + # Debug options + # CONFIG_LIBUKDEBUG_PRINTD: 'y' + # CONFIG_LIBUKDEBUG_PRINTK_INFO: 'y' + # CONFIG_LIBSYSCALL_SHIM_STRACE: 'y' + # CONFIG_LIBSYSCALL_SHIM_DEBUG: 'y' + +libraries: + lwip: + source: https://github.com/unikraft/lib-lwip.git + version: staging + kconfig: + CONFIG_LWIP_TCP: 'y' + CONFIG_LWIP_UDP: 'y' + CONFIG_LWIP_RAW: 'y' + CONFIG_LWIP_WND_SCALE: 'y' + CONFIG_LWIP_TCP_KEEPALIVE: 'y' + CONFIG_LWIP_THREADS: 'y' + CONFIG_LWIP_HEAP: 'y' + CONFIG_LWIP_SOCKET: 'y' + CONFIG_LWIP_AUTOIFACE: 'y' + CONFIG_LWIP_NUM_TCPCON: 64 + CONFIG_LWIP_NUM_TCPLISTENERS: 64 + CONFIG_LWIP_ICMP: 'y' + CONFIG_LWIP_DHCP: 'y' + CONFIG_LWIP_DNS: 'n' + libelf: + source: https://github.com/unikraft/lib-libelf.git + version: staging + +targets: +- qemu/x86_64 diff --git a/library/loki/2.9/README.md b/library/loki/2.9/README.md new file mode 100644 index 00000000..a099173b --- /dev/null +++ b/library/loki/2.9/README.md @@ -0,0 +1,75 @@ +# Loki + +This directory contains the [Loki](https://grafana.com/oss/loki/) log aggregation system on Unikraft, in binary compatibility mode. +It implements a Loki instance running on Unikraft. + +## Run and Use + +Use `kraft` to run the image and start a Unikraft instance: + +```bash +kraft run --rm -M 2048M -p 3100:3100 --plat qemu --arch x86_64 unikraft.org/loki:2.9 +``` + +If the `--plat` argument is left out, it defaults to `qemu`. +If the `--arch` argument is left out, it defaults to your system's CPU architecture. + +Once executed, it will open port `3100` and wait for connections. +To test it, you can use `curl`: + +```bash +curl localhost:3100/ready +``` + +You should see "ready" response from Loki. + +## Push Logs + +To push logs to Loki, you can use the following curl command: + +```bash +curl -v -H "Content-Type: application/json" -XPOST "http://localhost:3100/loki/api/v1/push" --data-raw \ + '{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1570818238000000000", "fizzbuzz" ] ] }]}' +``` + +## Query Logs + +To query logs from Loki: + +```bash +curl -G -s "http://localhost:3100/loki/api/v1/query" --data-urlencode 'query={foo="bar2"}' | jq +``` + +## Inspect and Close + +To list information about the Unikraft instance, use: + +```bash +kraft ps +``` + +To close the Unikraft instance, close the `kraft` process (e.g., via `Ctrl+c`) or run: + +```bash +kraft rm +``` + +## Build and Run Locally + +To build a local image, clone this repository and `cd` into this directory. +Then use `kraft` to build an image locally: + +```bash +kraft build --no-cache --no-update --plat qemu --arch x86_64 +``` + +In order to run the locally built image, use `.` as the final argument: + +```bash +kraft run --rm -M 2048M -p 3100:3100 --plat qemu --arch x86_64 . +``` + +## Learn More + +- [How to run unikernels locally](https://unikraft.org/docs/cli/running) +- [Loki Documentation](https://grafana.com/docs/loki/latest/) diff --git a/library/loki/2.9/loki-local-config.yaml b/library/loki/2.9/loki-local-config.yaml new file mode 100644 index 00000000..9ed8ab3d --- /dev/null +++ b/library/loki/2.9/loki-local-config.yaml @@ -0,0 +1,79 @@ +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: + instance_addr: 127.0.0.1 + kvstore: + store: inmemory + +ingester: + lifecycler: + address: 127.0.0.1 + ring: + kvstore: + store: inmemory + replication_factor: 1 + final_sleep: 0s + chunk_idle_period: 1h + max_chunk_age: 1h + chunk_target_size: 1048576 + chunk_retain_period: 30s + +query_range: + results_cache: + cache: + embedded_cache: + enabled: true + max_size_mb: 100 + +schema_config: + configs: + - from: 2020-10-24 + store: boltdb-shipper + object_store: filesystem + schema: v11 + index: + prefix: index_ + period: 24h + +storage_config: + boltdb_shipper: + active_index_directory: /tmp/loki/boltdb-shipper-active + cache_location: /tmp/loki/boltdb-shipper-cache + shared_store: filesystem + filesystem: + directory: /tmp/loki/chunks + +limits_config: + reject_old_samples: true + reject_old_samples_max_age: 168h + +chunk_store_config: + max_look_back_period: 0s + +table_manager: + retention_deletes_enabled: false + retention_period: 0s + +ruler: + storage: + type: local + local: + directory: /tmp/loki/rules + rule_path: /tmp/loki/rules-temp + alertmanager_url: http://localhost:9093 + ring: + kvstore: + store: inmemory + enable_api: true