Created
December 24, 2020 12:29
-
-
Save PeterGriffitz/172aa57cbdb40677cd6839bbc6c42236 to your computer and use it in GitHub Desktop.
Floitet-Patroni-Zookeeper-Part2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM alpine:3.10 | |
RUN apk add --no-cache curl jq bash | |
CMD ["/bin/sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.7" | |
networks: | |
patroni_patroni: | |
external: true | |
services: | |
haproxy: | |
image: haproxy-patroni | |
networks: | |
- patroni_patroni | |
ports: | |
- 5000:5000 | |
- 7000:7000 | |
hostname: haproxy | |
deploy: | |
mode: replicated | |
replicas: 1 | |
placement: | |
constraints: [node.hostname == floitet] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM haproxy:1.7 | |
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg | |
RUN mkdir /run/haproxy &&\ | |
apt-get update -y &&\ | |
apt-get install -y hatop &&\ | |
apt-get clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global | |
maxconn 100 | |
stats socket /run/haproxy/haproxy.sock | |
stats timeout 2m # Wait up to 2 minutes for input | |
defaults | |
log global | |
mode tcp | |
retries 2 | |
timeout client 30m | |
timeout connect 4s | |
timeout server 30m | |
timeout check 5s | |
listen stats | |
mode http | |
bind *:7000 | |
stats enable | |
stats uri / | |
listen postgres | |
bind *:5000 | |
option httpchk | |
http-check expect status 200 | |
default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions | |
server patroni1 patroni1:5432 maxconn 100 check port 8091 | |
server patroni2 patroni2:5432 maxconn 100 check port 8091 | |
server patroni3 patroni3:5432 maxconn 100 check port 8091 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "patroni-test/bin/Debug/net5.0/Npgsql.dll" | |
open System | |
open Npgsql | |
open System.Threading | |
open System.Diagnostics | |
let connStrignEntryPoint = "Host=haproxy;Port=5000;Username=approle;Password=appass;Database=postgres" | |
let dbName = "patronitestdb" | |
// time you want the scipt to be up writing to database | |
let testTimeLenght = TimeSpan.FromMinutes(5.) | |
let CreateDbIfNotPresent (conStr: string, dbName: string) = | |
use conn = new NpgsqlConnection(connStrignEntryPoint) | |
use command = new NpgsqlCommand(sprintf @"SELECT DATNAME FROM pg_catalog.pg_database WHERE DATNAME = '%s'" dbName, conn) | |
conn.Open() | |
let createDb () = | |
use cmd = new NpgsqlCommand( sprintf "CREATE DATABASE %s" dbName, conn) | |
cmd.ExecuteNonQuery() |> ignore | |
try | |
command.ExecuteScalar().ToString() |> ignore | |
conn.Close() | |
with | |
| :? System.NullReferenceException as ex -> createDb(); conn.Close() | |
CreateDbIfNotPresent(connStrignEntryPoint, dbName) | |
let connStringFinal = connStrignEntryPoint.Replace("postgres", dbName) | |
let WriteToTableForSetTime (connStr: string) = | |
use conn = new NpgsqlConnection(connStr) | |
conn.Open() | |
use cmd = new NpgsqlCommand(@"create table if not exists records (time time not null)", conn) | |
cmd.ExecuteNonQuery() |> ignore | |
conn.Close() | |
let mutable flag = true | |
let stopwatch = Stopwatch() | |
stopwatch.Start() | |
let writeTime () = | |
try | |
conn.Open() | |
use cmd = new NpgsqlCommand( @"insert into records values (@p)", conn) | |
let time = DateTimeOffset.Now | |
printfn "%O" time | |
cmd.Parameters.AddWithValue("p", time) |> ignore | |
cmd.ExecuteNonQuery() |> ignore | |
conn.Close() | |
with _ -> printfn "Error"; conn.Close() | |
while (flag) do | |
Thread.Sleep(1000) | |
writeTime() |> ignore | |
if (stopwatch.Elapsed > testTimeLenght) then flag <- false | |
stopwatch.Stop() | |
WriteToTableForSetTime(connStringFinal) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment