• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created about 9 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go program to move data in and out of Consul's KV store.

kvexpress

wercker status

Why?

Small Go utility to:

  1. Put data into Consul's KV store.
  2. Pull data out of Consul's KV store and write it to a file.

Why a dedicated utility though? Can't I just do it with curl?

Yes you can - but we kept wanting to:

  1. Make sure the file was long enough. 0-length configuration files are bad.
  2. Load the file from some other custom templating process - not just from straight KV files.
  3. Put the file into any location in the filesystem.
  4. Restart/reload/stop/start daemon after writing the file.
  5. Run some other custom command after writing the file.
  6. Verify that the file we put into the KV was the same file that was written on the other end.
  7. Stop the process on all nodes - in or out - if we want everything to stay as it is for the moment.

We did this at first with some custom Ruby scripts - but the pattern was apparent and could be applied to many other files as well.

This replaces our previous custom Ruby/shell scripts with a single Go binary we can use to get data in and out of Consul's KV store.

How does it work? - 1000 foot view

There's an introductory blog post available that shows how it can be used.

In

kvexpress in --key hosts --file /etc/consul-template/output/hosts.consul --length 100 --sorted=true

  1. Check that at least --file and --key are passed along with the command. Quit if they're not present - there are no safe defaults for those flags.
  2. Check for the existence of a stop key - if it's there - stop and exit.
  3. Read the file into a string, and sort the string if requested.
  4. Check if the file is long enough - if not - stop and exit.
  5. Save the file to a .compare file - we will use this data from now on.
  6. Check for the existence of a .last file - if it's not there - create it.
  7. Are the .compare and .last files blank? If not - let's continue.
  8. Compare the checksums of the .compare and .last files - if they're different - continue.
  9. Grab the checksum from Consul and compare with the .compare file - if it's different - then let's update. This is to guard against it running on multiple server nodes that might have different .last files.
  10. Save data, and checksum keys.
  11. Copy .compare to .last
  12. If --exec is passed - run that command.

Out

kvexpress out -k hosts -f /etc/hosts.consul -l 100 -e 'sudo pkill -HUP dnsmasq'

  1. Check that at least --file and --key are passed along with the command. Quit if they're not present - there are no safe defaults for those flags.
  2. Check for the existence of a stop key - if it's there - stop and exit.
  3. Pull the data and checksum keys out of Consul.
  4. If data is long enough and the checksum as computed on this side matches the checksum key - then continue.
  5. Write the contents of data to the passed --file location.
  6. If --exec is passed - run that command.

Where can I get it?

Build instructions are available below.

Debian packages for Ubuntu can be downloaded from packagecloud.

Additional binaries can be downloaded from the releases page.

A Chef cookbook is available as well.

How to use it with Consul watches.

Instructions are available here.

Ad-Hoc Usage with Consul exec

If you want to push a file to all nodes in your Consul cluster quickly - you can use Consul and kvexpress.

kvexpress in --prefix tmp --key config --length 5 --url https://git.io/vzz5P

This places the file and checksum in:

tmp/config/data
tmp/config/checksum

To get the file on every node:

consul exec "sudo kvexpress out --prefix tmp --key config --length 5 -f /etc/file.conf -e 'sudo restart something here'"

If you're not seeing it work the way you expect - you can always add --verbose to the kvexpress command - that will add lots of additional output.

Commands Available

A detailed list of commands is available here.

Consul KV Structure

How are keys organized in Consul's KV store to work with kvexpress?

Underneath a global prefix /kvexpress/ - each directory represents a specific file we are distributing through the KV store.

Each directory is named for the unique key and has the following keys underneath it:

  1. data - where the configuration file is stored.
  2. checksum - where the SHA256 of the data is stored.

For example - the hosts file is arranged like this:

/kvexpress/hosts/data
/kvexpress/hosts/checksum

There is an optional stop key - that if present - will cause all in and out processes to stop before writing anything. Allows us to freeze the automatic process if we need to.

Logging

All logs are sent to syslog and are tagged with kvexpress. To enable debug logs, please export KVEXPRESS_DEBUG=1

Build

Can be built with the standard go toolchain: go get -u -v github.com/DataDog/kvexpress

To build manually - clone the repo then: make deps && make

To run integration tests: make deps && make && make test - it will spin up an empty Consul and kill it after the run.

Because we use user.Current() - you can't cross compile this. If you want to build for Linux - you must build on Linux. Closed Issue

To install Consul - there are instructions here.

To launch an empty Consul instance: make consul

Contributing

We love pull requests from anyone. Details are available here.

Code of Conduct

This project adheres to the [Open Code of Conduct][code-of-conduct]. By participating, you are expected to honor this code. [code-of-conduct]: http://todogroup.org/opencodeofconduct/#kvexpress/[email protected]

More Repositories

1

go-profiler-notes

felixge's notes on the various go profiling methods that are available.
Jupyter Notebook
3,255
star
2

glommio

Glommio is a thread-per-core crate that makes writing highly parallel asynchronous applications in a thread-per-core architecture easier for rustaceans.
Rust
3,076
star
3

datadog-agent

Main repository for Datadog Agent
Go
2,859
star
4

stratus-red-team

☁️ ⚡ Granular, Actionable Adversary Emulation for the Cloud
Go
1,752
star
5

dd-agent

Datadog Agent Version 5
Python
1,291
star
6

integrations-core

Core integrations of the Datadog Agent
Python
917
star
7

KubeHound

Tool for building Kubernetes attack paths
Go
737
star
8

zstd

Zstd wrapper for Go
C
732
star
9

dd-trace-go

Datadog Go Library including APM tracing, profiling, and security monitoring.
Go
659
star
10

dd-trace-js

JavaScript APM Tracer
JavaScript
636
star
11

the-monitor

Markdown files for Datadog's longform blog posts: https://www.datadoghq.com/blog/
Python
613
star
12

guarddog

🐍 🔍 GuardDog is a CLI tool to Identify malicious PyPI and npm packages
Python
588
star
13

datadogpy

The Datadog Python library
Python
575
star
14

dd-trace-py

Datadog Python APM Client
Python
519
star
15

dd-trace-java

Datadog APM client for Java
Java
500
star
16

yubikey

YubiKey at Datadog
Shell
494
star
17

dd-trace-php

Datadog PHP Clients
PHP
491
star
18

kafka-kit

Kafka storage rebalancing, automated replication throttle, cluster API and more
Go
485
star
19

documentation

The source for Datadog's documentation site.
HTML
471
star
20

dd-trace-dotnet

.NET Client Library for Datadog APM
C#
443
star
21

security-labs-pocs

Proof of concept code for Datadog Security Labs referenced exploits.
Shell
355
star
22

go-python3

Go bindings to the CPython-3 API
Go
344
star
23

helm-charts

Helm charts for Datadog products
Go
344
star
24

datadog-go

go dogstatsd client library for datadog
Go
332
star
25

terraform-provider-datadog

Terraform Datadog provider
Go
329
star
26

datadog-serverless-functions

Repo of AWS Lambda and Azure Functions functions that process streams and send data to Datadog
Python
326
star
27

docker-dd-agent

Datadog Agent Dockerfile for Trusted Builds.
Roff
302
star
28

browser-sdk

Datadog Browser SDK
TypeScript
302
star
29

datadog-operator

Kubernetes Operator for Datadog Resources
Go
301
star
30

ansible-datadog

Ansible role for Datadog Agent
Jinja
299
star
31

dd-trace-rb

Datadog Tracing Ruby Client
Ruby
261
star
32

threatest

Threatest is a CLI and Go framework for end-to-end testing threat detection rules.
Go
260
star
33

integrations-extras

Community developed integrations and plugins for the Datadog Agent.
Python
252
star
34

watermarkpodautoscaler

Custom controller that extends the Horizontal Pod Autoscaler
Go
210
star
35

pupernetes

Spin up a full fledged Kubernetes environment designed for local development & CI
Go
201
star
36

Miscellany

Miscellaneous scripts and tools
Python
197
star
37

dd-sdk-ios

Datadog SDK for iOS - Swift and Objective-C.
Swift
195
star
38

php-datadogstatsd

A PHP client for DogStatsd
PHP
185
star
39

java-dogstatsd-client

Java statsd client library
Java
175
star
40

sketches-go

Go implementations of the distributed quantile sketch algorithm DDSketch
Go
167
star
41

dogstatsd-ruby

A Ruby client for DogStatsd
Ruby
166
star
42

dd-sdk-android

Datadog SDK for Android (Compatible with Kotlin and Java)
Kotlin
150
star
43

chaos-controller

🐒 🔥 Datadog Failure Injection System for Kubernetes
C
142
star
44

HASH

HASH (HTTP Agnostic Software Honeypot)
JavaScript
128
star
45

malicious-software-packages-dataset

An open-source dataset of malicious software packages found in the wild, 100% vetted by humans.
Python
125
star
46

ebpf-manager

This manager helps handle the life cycle of your eBPF programs
Go
118
star
47

docker-compose-example

A working example of using Docker Compose with Datadog
Python
116
star
48

orchestrion

Automatic compile-time instrumentation of Go code
Go
115
star
49

dd-sdk-reactnative

Datadog SDK for ReactNative
TypeScript
115
star
50

trace-examples

trace sample apps
Python
113
star
51

sketches-java

DDSketch: A Fast and Fully-Mergeable Quantile Sketch with Relative-Error Guarantees.
Java
113
star
52

datadog-lambda-js

The Datadog AWS Lambda Library for Node
TypeScript
105
star
53

gohai

System information collector
Go
102
star
54

build-plugins

A set of universal bundler plugins to interact with Datadog directly from your builds.
TypeScript
101
star
55

jmxfetch

Export JMX metrics
Java
98
star
56

chef-datadog

Chef cookbook for Datadog Agent & Integrations
Ruby
97
star
57

piecewise

Functions for piecewise regression on time series data
Python
96
star
58

extendeddaemonset

Kubernetes Extended Daemonset controller
Go
96
star
59

datadog-static-analyzer

Datadog Static Analyzer
Rust
96
star
60

datadog-api-client-go

Golang client for the Datadog API
Go
95
star
61

ansible-datadog-callback

Ansible callback to get stats & events directly into Datadog http://datadoghq.com
Python
94
star
62

dogstatsd-csharp-client

A DogStatsD client for C#/.NET
C#
94
star
63

gostackparse

Package gostackparse parses goroutines stack traces as produced by panic() or debug.Stack() at ~300 MiB/s.
Go
94
star
64

dogapi-rb

Ruby client for Datadog's API
Ruby
92
star
65

redux-doghouse

Scoping helpers for building reusable components with Redux
JavaScript
90
star
66

ecommerce-workshop

Example eCommerce App for workshops and observability
Ruby
89
star
67

serverless-plugin-datadog

Serverless plugin to automagically instrument your Lambda functions with Datadog
TypeScript
87
star
68

ebpfbench

## Auto-archived due to inactivity. ## profile eBPF programs from Go
Go
87
star
69

datadog-ci

Use Datadog from your CI.
TypeScript
85
star
70

sketches-py

Python implementations of the distributed quantile sketch algorithm DDSketch
Python
83
star
71

datadog-lambda-python

The Datadog AWS Lambda Layer for Python
Python
83
star
72

ddqa

Datadog's QA manager for releases of GitHub repositories
Python
82
star
73

datadog-api-client-typescript

Typescript client for the Datadog API
TypeScript
77
star
74

dirtypipe-container-breakout-poc

Container Excape PoC for CVE-2022-0847 "DirtyPipe"
77
star
75

datadog-trace-agent

Datadog Trace Agent archive (pre-6.10.0)
70
star
76

heroku-buildpack-datadog

Heroku Buildpack to run the Datadog Agent in a Dyno
Shell
69
star
77

datadog-lambda-extension

Rust
68
star
78

datadog-api-client-python

Python client for the Datadog API
Python
68
star
79

datadog-cdk-constructs

CDK construct library to automagically instrument your Lambda functions with Datadog
TypeScript
65
star
80

lading

A suite of data generation and load testing tools
Rust
64
star
81

jsonapi

A marshaler/unmarshaler for JSON:API.
Go
62
star
82

datadog-api-client-java

Java client for the Datadog API
Java
61
star
83

managed-kubernetes-auditing-toolkit

All-in-one auditing toolkit for identifying common security issues in managed Kubernetes environments. Currently supports AWS EKS.
Go
60
star
84

datadog-lambda-go

The Datadog AWS Lambda package for Go
Go
59
star
85

serilog-sinks-datadog-logs

Serilog Sink that sends log events to Datadog https://www.datadoghq.com/
C#
53
star
86

puppet-datadog-agent

Puppet module to install the Datadog agent
Ruby
50
star
87

effective-dashboards

A curated list of useful Datadog dashboards and Dashboard design best practices
47
star
88

opencensus-go-exporter-datadog

Datadog exporter for OpenCensus metrics
Go
47
star
89

gello

## Auto-archived due to inactivity. ## :octocat: A self-hosted server for managing Trello cards based on GitHub webhook events
Python
45
star
90

datadog-cloudformation-resources

Python
44
star
91

ebpf-training

Go
44
star
92

dd-sdk-flutter

Flutter bindings and tools for utilizing Datadog Mobile SDKs
Dart
43
star
93

jenkins-datadog-plugin

ARCHIVED: Current repository is now located https://github.com/jenkinsci/datadog-plugin
Java
42
star
94

synthetics-ci-github-action

Use Browser and API tests in your CI/CD with Datadog Continuous Testing
TypeScript
41
star
95

dd-opentracing-cpp

Datadog Opentracing C++ Client
C++
40
star
96

rum-react-integration-examples

rum-react-integration
TypeScript
39
star
97

fluent-plugin-datadog

Fluentd output plugin for Datadog: https://www.datadog.com
Ruby
38
star
98

datadog-sync-cli

Datadog cli tool to sync resources across organizations.
Python
38
star
99

ddprof

The Datadog Native Profiler for Linux
C++
36
star
100

cloudformation-template

Easily set up the Datadog AWS integration using CloudFormation
Shell
34
star