Skip to content
Snippets Groups Projects
Commit 34bb9db7 authored by Edward Welch's avatar Edward Welch
Browse files

using an environment variable passed into an arg instead of reading the pod...

using an environment variable passed into an arg instead of reading the pod name from a file and the downardApi
added a makefile
parent 50ff10df
No related branches found
No related tags found
No related merge requests found
loki-canary
\ No newline at end of file
Makefile 0 → 100644
.PHONY: all build test clean build-image push-image
.DEFAULT_GOAL := all
IMAGE_PREFIX ?= grafana
IMAGE_TAG := $(shell ./tools/image-tag)
all: test build-image
build:
go build -o loki-canary -v cmd/loki-canary/main.go
test:
go test -v ./...
clean:
rm -f ./loki-canary
go clean ./...
build-image:
docker build -t $(IMAGE_PREFIX)/loki-canary .
docker tag $(IMAGE_PREFIX)/loki-canary $(IMAGE_PREFIX)/loki-canary:$(IMAGE_TAG)
push-image:
docker push $(IMAGE_PREFIX)/loki-canary:$(IMAGE_TAG)
docker push $(IMAGE_PREFIX)/loki-canary:latest
\ No newline at end of file
......@@ -3,7 +3,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
......@@ -22,7 +21,6 @@ func main() {
lName := flag.String("labelname", "name", "The label name for this instance of loki-canary to use in the log selector")
lVal := flag.String("labelvalue", "loki-canary", "The unique label value for this instance of loki-canary to use in the log selector")
usePodName := flag.Bool("usepod", false, "If true, loki-canary will read the pod name from /etc/loki-canary/pod_name as the unique label value")
port := flag.Int("port", 3500, "Port which loki-canary should expose metrics")
addr := flag.String("addr", "", "The Loki server URL:Port, e.g. loki:3100")
tls := flag.Bool("tls", false, "Does the loki connection use TLS?")
......@@ -34,17 +32,9 @@ func main() {
wait := flag.Duration("wait", 60*time.Second, "Duration to wait for log entries before reporting them lost")
flag.Parse()
val := *lVal
if *usePodName {
data, err := ioutil.ReadFile("/etc/loki-canary/name")
if err != nil {
panic(err)
}
val = string(data)
}
if *addr == "" {
panic("Must specify a Loki address with -addr")
_, _ = fmt.Fprintf(os.Stderr, "Must specify a Loki address with -addr\n")
os.Exit(1)
}
var ui *url.Userinfo
......@@ -62,10 +52,10 @@ func main() {
Host: *addr,
User: ui,
Path: "/api/prom/tail",
RawQuery: "query=" + url.QueryEscape(fmt.Sprintf("{stream=\"stdout\",%v=\"%v\"}", *lName, val)),
RawQuery: "query=" + url.QueryEscape(fmt.Sprintf("{stream=\"stdout\",%v=\"%v\"}", *lName, *lVal)),
}
_, _ = fmt.Fprintf(os.Stderr, "Connecting to loki at %v, querying for label '%v' with value '%v'\n", u.String(), *lName, val)
_, _ = fmt.Fprintf(os.Stderr, "Connecting to loki at %v, querying for label '%v' with value '%v'\n", u.String(), *lName, *lVal)
c := comparator.NewComparator(os.Stderr, *wait, 1*time.Second)
w := writer.NewWriter(os.Stdout, c, *interval, *size)
......
......@@ -3,10 +3,12 @@ local k = import 'ksonnet-util/kausal.libsonnet';
k {
local container = $.core.v1.container,
loki_canary_args:: {},
loki_canary_args:: {
labelvalue: "$(POD_NAME)",
},
_images+:: {
loki_canary: 'loki-canary:latest',
loki_canary: 'grafana/loki-canary:latest',
},
loki_canary_container::
......@@ -15,32 +17,11 @@ k {
container.withArgsMixin($.util.mapToFlags($.loki_canary_args)) +
container.withEnv([
container.envType.fromFieldPath('HOSTNAME', 'spec.nodeName'),
container.envType.fromFieldPath('POD_NAME', 'metadata.name'),
]),
local daemonSet = $.extensions.v1beta1.daemonSet,
local downwardApiMount(name, path, volumeMountMixin={}) =
local container = $.core.v1.container,
deployment = $.extensions.v1beta1.deployment,
volumeMount = $.core.v1.volumeMount,
volume = $.core.v1.volume,
addMount(c) = c + container.withVolumeMountsMixin(
volumeMount.new(name, path) +
volumeMountMixin,
);
deployment.mapContainers(addMount) +
deployment.mixin.spec.template.spec.withVolumesMixin([
volume.withName(name) +
volume.mixin.downwardApi.withItems([
{
path: "name",
fieldRef: { fieldPath: "metadata.name" },
},
]),
]),
loki_canary_daemonset:
daemonSet.new('loki-canary', [$.loki_canary_container]) +
downwardApiMount('pod-name', '/etc/loki-canary'),
daemonSet.new('loki-canary', [$.loki_canary_container]),
}
\ No newline at end of file
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
WORKING_SUFFIX=$(if git status --porcelain | grep -qE '^(?:[^?][^ ]|[^ ][^?])\s'; then echo "-WIP"; else echo ""; fi)
BRANCH_PREFIX=$(git rev-parse --abbrev-ref HEAD)
echo "${BRANCH_PREFIX//\//-}-$(git rev-parse --short HEAD)$WORKING_SUFFIX"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment