Skip to content

Instantly share code, notes, and snippets.

View lawrencejones's full-sized avatar

Lawrence Jones lawrencejones

View GitHub Profile
@lawrencejones
lawrencejones / config.libsonnet
Last active November 12, 2019 17:25
external-dsn jsonnet module
{
_images+:: {
external_dns: "registry.opensource.zalan.do/teapot/external-dns:v0.5.17",
},
_config+:: {
external_dns: {
namespace: "external-dns",
domain_filter: [
"lawrjone.xyz",
],
@lawrencejones
lawrencejones / logger.rb
Created September 6, 2019 10:26
Simple logfmt logger in Ruby
# frozen_string_literal: true
require "logger"
require "values"
module App
module Logger
class ContextualLogger < Value.new(:logger, :context)
def log(**kwargs)
logger.info(context.merge(kwargs))
@lawrencejones
lawrencejones / 11
Last active May 17, 2019 10:46
Stolon sentinel locking up due to etcd
λ (lab) ~> kl stolon-main-sentinel-backend-stolon-main-sentinel-78d4d597c2lsv -f
2019-05-16T02:57:57.750Z INFO cmd/sentinel.go:1962 sentinel uid {"uid": "f3e6c1b3"}
2019-05-16T02:57:57.850Z INFO cmd/sentinel.go:80 Trying to acquire sentinels leadership
2019-05-16T07:19:41.806Z ERROR cmd/sentinel.go:100 election loop error {"error": "lost watcher waiting for delete"}
2019-05-16T07:19:51.806Z INFO cmd/sentinel.go:80 Trying to acquire sentinels leadership
2019-05-16T07:25:43.371Z ERROR cmd/sentinel.go:1815 error retrieving cluster data {"error": "context deadline exceeded"}
SIGQUIT: quit
PC=0x45ae01 m=0 sigcode=0
@lawrencejones
lawrencejones / 01-disable.bash
Last active May 2, 2019 15:23
Upgrade process for PG9.4 -> 11
#!/usr/bin/env bash
all-databases() {
cd /tmp && sudo -u postgres psql -U pgbouncer pgbouncer -c 'show databases;' -p 6432 | grep -Po '^ gc_\S+'
}
disable-databases() {
xargs -n1 -I _DATABASE_ sudo -u postgres psql -U pgbouncer pgbouncer -p 6432 -c 'disable _DATABASE_;'
}
@lawrencejones
lawrencejones / verify_commit.go
Created March 28, 2019 20:24
Script to verify no data loss with a HA PG cluster
package main
import (
"context"
"fmt"
"os"
"os/signal"
"sync"
"sync/atomic"
"syscall"
@lawrencejones
lawrencejones / create-database
Created January 18, 2019 08:45
Create a MySQL replica from external host in GCP
#!/usr/bin/env bash
ACCESS_TOKEN="$(gcloud auth print-access-token)"
PROJECT="gc-prd-effc"
# Parameters
REGION="europe-west1" # "europe-west4"
DATABASE_VERSION="MYSQL_5_6"
DATABASE_TIER="D2" # "db-n1-standard-2"
CERTIFICATE_FILE="rds-ca-2015-root.pem"
@lawrencejones
lawrencejones / output
Last active January 14, 2019 17:15
Example of exporting Route53
λ (lab) ~> aws route53 list-resource-record-sets --hosted-zone-id Z1B93ASNBC3G25
{
"ResourceRecordSets": [
...,
{
"Name": "something.directli.co.uk.",
"Type": "A",
"TTL": 300,
"ResourceRecords": [
{
@lawrencejones
lawrencejones / main.go
Created January 9, 2019 16:48
Annotate configmaps with author
package main
import (
"context"
"net/http"
"os"
kitlog "github.com/go-kit/kit/log"
"github.com/lawrencejones/theatre/pkg/signals"
@lawrencejones
lawrencejones / looker.bash
Last active March 26, 2020 16:16
Looker API helper
# Source this file ($ source <file-namne>) in your terminal to load all the
# functions.
# First run the looker-login using the client ID and client secret to generate
# an API token. Once you have your API token, run:
#
# $ export LOOKER_API_TOKEN=<your-token>
#
# This will enable use of looker-curl.