|
| 1 | +.DEFAULT_GOAL := help |
| 2 | +SHELL := /bin/bash |
| 3 | +M = $(shell printf "\033[34;1m>>\033[0m") |
| 4 | +rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d)) |
| 5 | + |
| 6 | +TARGET_NAME = $(firstword $(MAKECMDGOALS)) |
| 7 | +RUN_ARGS = $(filter-out $@, $(MAKEOVERRIDES) $(MAKECMDGOALS)) |
| 8 | +OS := $(shell uname -s) |
| 9 | +TOOLS_DIR ?= .tools |
| 10 | +SUDO_PASSWORD ?= human |
| 11 | + |
| 12 | +VECTOR_VERSION ?= 0.35.0 |
| 13 | +# если установлен в системе, то доступен как команда в /usr/bin/vector |
| 14 | +VECTOR_BINARY ?= $(TOOLS_DIR)/vector_$(VECTOR_VERSION)_$(OS)_amd64 |
| 15 | +VECTOR_CONFIG_DIR ?= $(PWD)/.generated/vector_config |
| 16 | +YQ_VERSION ?= 4.30.5 |
| 17 | +JV_VERSION ?= 0.4.0 |
| 18 | + |
| 19 | + |
| 20 | +ifeq ($(OS), Darwin) |
| 21 | + VECTOR_TAR_URL := https://packages.timber.io/vector/$(VECTOR_VERSION)/vector-$(VECTOR_VERSION)-x86_64-apple-darwin.tar.gz |
| 22 | + VECTOR_TAR_BIN_PATH := ./vector-x86_64-apple-darwin/bin/vector |
| 23 | +else |
| 24 | + VECTOR_TAR_URL := https://packages.timber.io/vector/$(VECTOR_VERSION)/vector-$(VECTOR_VERSION)-x86_64-unknown-linux-gnu.tar.gz |
| 25 | + VECTOR_TAR_BIN_PATH := ./vector-x86_64-unknown-linux-gnu/bin/vector |
| 26 | +endif |
| 27 | + |
| 28 | +YQ_BINARY := $(TOOLS_DIR)/yq_$(YQ_VERSION)_$(OS)_amd64 |
| 29 | +JV_BINARY := $(TOOLS_DIR)/jv_$(JV_VERSION)_$(OS)_amd64 |
| 30 | + |
| 31 | +YQ_BINARY_URL := https://github.com/mikefarah/yq/releases/download/v$(YQ_VERSION)/yq_$(OS)_amd64 |
| 32 | + |
| 33 | + |
| 34 | +.PHONY: install-dependencies |
| 35 | +install-dependencies: ## Install required dependencies |
| 36 | + mkdir -p $(TOOLS_DIR) |
| 37 | +ifeq (,$(wildcard $(YQ_BINARY))) |
| 38 | + wget -qO $(YQ_BINARY) $(YQ_BINARY_URL) --show-progress && chmod +x $(YQ_BINARY) |
| 39 | +endif |
| 40 | +ifeq (,$(wildcard $(JV_BINARY))) |
| 41 | + $(info $(M) Building jv from source...) |
| 42 | + GO111MODULE="on" GOBIN=$(shell realpath $(TOOLS_DIR)) go install github.com/santhosh-tekuri/jsonschema/cmd/jv@v$(JV_VERSION) |
| 43 | + mv $(TOOLS_DIR)/jv $(JV_BINARY) |
| 44 | +endif |
| 45 | + |
| 46 | + |
| 47 | +.PHONY: install-dev-dependencies |
| 48 | +install-dev-dependencies: ## Install required dev tools |
| 49 | + $(info $(M) Install required dev tools...) |
| 50 | +ifneq ($(CI), true) |
| 51 | +# Local environment as GitLab CI/CD environment var not definded or != true |
| 52 | + @echo "Check if python installed" |
| 53 | + @command -v pip >/dev/null 2>&1 && echo "OK" || { \ |
| 54 | + echo "$(M) Installing python3 pip..."; \ |
| 55 | + echo "$(M) You may be prompted for sudo password..."; \ |
| 56 | + if [ "$(OS)" = "Darwin" ]; then \ |
| 57 | + brew install python3 && (curl https://bootstrap.pypa.io/get-pip.py | python3) \ |
| 58 | + else \ |
| 59 | + sudo apt-get update && (sudo apt-get install python3 && curl https://bootstrap.pypa.io/get-pip.py | python3) \ |
| 60 | + fi; \ |
| 61 | + } |
| 62 | +endif |
| 63 | + python3 -m pip install -r ./dev-requirements.txt |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +.PHONY: download-vector-bin |
| 68 | +download-vector-bin: ## Download vector.dev binary |
| 69 | +ifeq (,$(wildcard $(VECTOR_BINARY))) |
| 70 | + $(info $(M) Download vector.dev $(VECTOR_BINARY) binary...) |
| 71 | + @wget -qO- https://packages.timber.io/vector/$(VECTOR_VERSION)/vector-$(VECTOR_VERSION)-x86_64-unknown-linux-gnu.tar.gz --show-progress \ |
| 72 | + | tar xvzf - -C $(TOOLS_DIR) "$(VECTOR_TAR_BIN_PATH)" --strip-components=3 \ |
| 73 | + && chmod +x $(TOOLS_DIR)/vector && mv $(TOOLS_DIR)/vector $(VECTOR_BINARY) |
| 74 | +endif |
| 75 | + |
| 76 | + |
| 77 | +.PHONY: validate-metrics-catalog-spec |
| 78 | +validate-metrics-catalog-spec: ## Validates metrics-catalog.yml |
| 79 | + $(info $(M) Validate vars/metric-catalog.yml with json-schema...) |
| 80 | + $(JV_BINARY) ./schema/vectordev-metrics-catalog.json ./ansible-playbook/vars/metrics-catalog.yml |
| 81 | + |
| 82 | + |
| 83 | +.PHONY: lint-vector-config |
| 84 | +lint-vector-config: ## Check vector files for invalid or deprecated functions |
| 85 | + $(info $(M) Check for deprecated functions vector.dev...) |
| 86 | + @FOUND_FILES=$$(grep -r -l "to_timestamp" files/); \ |
| 87 | + if [ -n "$$FOUND_FILES" ]; then \ |
| 88 | + echo "ERROR: Some files contain deprecated to_timestamp func, replace with parse_timestamp (see https://vector.dev/highlights/2023-08-15-0-32-0-upgrade-guide/#deprecations)"; \ |
| 89 | + echo "$$FOUND_FILES"; \ |
| 90 | + exit 1; \ |
| 91 | + else \ |
| 92 | + echo "OK"; \ |
| 93 | + exit 0; \ |
| 94 | + fi |
| 95 | + |
| 96 | +.PHONY: generate-vector-conf |
| 97 | +generate-vector-conf: | validate-metrics-catalog-spec lint-vector-config ## Generate vector.dev at localhost |
| 98 | + @mkdir -p $(VECTOR_CONFIG_DIR) |
| 99 | + $(info $(M) Ansible generates vector.dev config for localhost...) |
| 100 | + $(eval $@_tmpfile := $(shell mktemp ansible-playbook/playbook.tmpXXX)) |
| 101 | + @$(YQ_BINARY) ea '.[0].hosts = "127.0.0.1", .[0].connection = "local"' ./ansible-playbook/playbook.yml > $($@_tmpfile) |
| 102 | + @$(YQ_BINARY) -i ea 'del(.[0].roles)' $($@_tmpfile) |
| 103 | + |
| 104 | + @echo Build and copy config files... |
| 105 | + VECTOR_KAFKA_PASSWORD=fake \ |
| 106 | + VECTOR_KAFKA_USERNAME=fake \ |
| 107 | + ansible-playbook -connection=local --inventory localhost, $($@_tmpfile) \ |
| 108 | + --tags aggregator \ |
| 109 | + --extra-vars "development_mode=true" \ |
| 110 | + --extra-vars "ansible_sudo_pass=$(SUDO_PASSWORD)" \ |
| 111 | + --extra-vars "local_build=true" \ |
| 112 | + --extra-vars "vector_config_dir=$(VECTOR_CONFIG_DIR)" \ |
| 113 | + --extra-vars "vector_kafka_bootstrap_servers=FAKE_KAFKA_SERVER" \ |
| 114 | + --extra-vars "vector_kafka_topics=FAKE_KAFKA_TOPIC" \ |
| 115 | + --skip-tags install,setup |
| 116 | + @rm -rf $($@_tmpfile) |
| 117 | +# popd |
| 118 | + |
| 119 | +.PHONY: validate-vector-conf |
| 120 | +validate-vector-conf: generate-vector-conf ## Validate current vector.dev config |
| 121 | + $(info $(M) Validate vector config at $(VECTOR_CONFIG_DIR)...) |
| 122 | + $(VECTOR_BINARY) validate -C $(VECTOR_CONFIG_DIR) --no-environment |
| 123 | + |
| 124 | +.PHONY: test-vector-transfroms |
| 125 | +test-vector-transfroms: | generate-vector-conf validate-vector-conf ## Run vector.dev transform tests |
| 126 | + $(info $(M) Run transforms tests with config $(VECTOR_CONFIG_DIR)...) |
| 127 | + $(VECTOR_BINARY) test $(VECTOR_CONFIG_DIR)/*_sources_*.toml $(VECTOR_CONFIG_DIR)/*transforms_*.toml $(VECTOR_CONFIG_DIR)/*_tests_*.toml |
| 128 | + |
| 129 | +.PHONY: test-vector-transfrom |
| 130 | +test-vector-transfrom: ## Run vector.dev test for a specifed test file |
| 131 | +ifndef file |
| 132 | + @echo "To run use file=testfile make ..." |
| 133 | +else |
| 134 | + $(info $(M) Run a transform test with config $(VECTOR_CONFIG_DIR)...) |
| 135 | + @echo Test file: $(file) |
| 136 | + $(VECTOR_BINARY) test $(VECTOR_CONFIG_DIR)/*_sources_*.toml $(VECTOR_CONFIG_DIR)/*transforms_*.toml $(file) |
| 137 | +endif |
| 138 | + |
| 139 | +help: ## Show this help |
| 140 | + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
| 141 | + |
| 142 | +%: |
| 143 | + @: |
0 commit comments