Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for using the OpenTelemetry chloggen tool #923

Merged
merged 13 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .chloggen/TEMPLATE.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type:
# The name of the component, or a single word describing the area of concern, (e.g. agent, clusterReceiver, gateway, networkExplorer, operator, chart, other)
component:
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note:
# One or more tracking issues related to the change
issues: []
# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
12 changes: 12 additions & 0 deletions .chloggen/migrate-to-otel-by-default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement
# The name of the component, or a single word describing the area of concern, (e.g. agent, clusterReceiver, gateway, networkExplorer, operator, chart, other)
component: agent
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Change the default logs collection engine (`logsEngine`) to the native OpenTelemetry logs collection (`otel`)
# One or more tracking issues related to the change
issues: [934]
# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: If you want to keep using Fluentd sidecar for the logs collection, set `logsEngine' to 'fluentd` in your values.yaml
12 changes: 12 additions & 0 deletions .chloggen/otl-add-chloggen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement
# The name of the component, or a single word describing the area of concern, (e.g. agent, clusterReceiver, gateway, networkExplorer, operator, chart, other)
component: chart
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add support for OpenTelemetry CHANGELOG.md generator tool, see [chloggen](https://github.com/open-telemetry/opentelemetry-operator/tree/main/.chloggen)
# One or more tracking issues related to the change
issues: [923]
# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
20 changes: 14 additions & 6 deletions .github/workflows/validate-changelog.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
name: Ensure valid and up-to-date Changelog

# Description: Automates the validation of .chloggen (CHANGELOG.md) entries ensuring:
# 1. All entries are valid.
# 2. A new entry is added for updates to chart templates or rendered example content.
# 3. Bypass validation with a 'Skip Changelog' label or a PR title containing '[chore]' (case insensitive).

on: pull_request

jobs:
validate-changelog:
if: ${{ !contains(toLower(github.event.pull_request.labels.*.name), 'skip changelog') && !contains(toLower(github.event.pull_request.title), '[chore]') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Lint changelog file
uses: avto-dev/markdown-lint@v1
with:
rules: /lint/rules/changelog.js
config: /lint/config/changelog.yml
args: ./CHANGELOG.md
- name: Set up Go
uses: actions/setup-go@v4

- name: Install chloggen
run: go install go.opentelemetry.io/build-tools/chloggen@latest

- name: Run make chlog-validate
run: make chlog-validate

- name: Read current version of the Chart
id: read-chart
Expand Down
657 changes: 326 additions & 331 deletions CHANGELOG.md

Large diffs are not rendered by default.

35 changes: 32 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,45 @@ To send us a pull request, please:
reformat all the code, it will be hard for us to focus on your change.
3. Please follow the versioning instructions found in the [RELEASE.md](https://github.com/signalfx/splunk-otel-collector-chart/blob/main/RELEASE.md).
4. Ensure local tests pass and add new tests related to the contribution.
5. Commit to your fork using clear commit messages.
6. Send us a pull request, answering any default questions in the pull request
5. Add a CHANGLOG.md entry (make chlog-new) if the behavior of this chart is altered, see [Changelog Guidelines](https://signalfx/splunk-otel-collector-chart/blob/main/CONTRIBUTING.md#changelog-guidelines).
jvoravong marked this conversation as resolved.
Show resolved Hide resolved
6. Render example documentation (make render) if chart templates are updated.
7. Commit to your fork using clear commit messages.
8. Send us a pull request, answering any default questions in the pull request
interface.
7. Pay attention to any automated CI failures reported in the pull request, and
9. Pay attention to any automated CI failures reported in the pull request, and
stay involved in the conversation.

GitHub provides additional documentation on [forking a
repository](https://help.github.com/articles/fork-a-repo/) and [creating a pull
request](https://help.github.com/articles/creating-a-pull-request/).

## Changelog Guidelines

### When to Add an Entry

Include a changelog entry for pull requests affecting:

1. Collector configuration or behavior
2. Telemetry data output

**Exceptions:**

- Documentation-only changes
- Minor, non-impactful updates (e.g., code cleanup)

### Adding an Entry

**Quick Guide:**

1. **Create File:** Run `make chlog-new` to generate a `.yaml` in `./.chloggen`.
2. **Edit File:** Update the `.yaml` with relevant info.
3. **Validate:** Use `make chlog-validate` to check format.
4. **Commit:** Add the `.yaml` to your pull request.

**Manual Option:**

- Copy `./.chloggen/TEMPLATE.yaml` or create a unique `.yaml` file.

## Finding contributions to work on

Looking at the existing issues is a great way to find something to contribute
Expand Down
98 changes: 85 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,97 @@
.PHONY: render
render: repo-update dep-build
bash ./examples/render-examples.sh
##@ General
# The general settings and variables for the project
SHELL := /bin/bash

# TODO: Move CHART_FILE_PATH and VALUES_FILE_PATH here, currently set in multiple places
# The version of the splunk-otel-collector chart
VERSION := $(shell grep "^version:" helm-charts/splunk-otel-collector/Chart.yaml | awk '{print $$2}')

## Location for GO resources
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
CHLOGGEN ?= $(LOCALBIN)/chloggen

# The help target as provided
.PHONY: help
help: ## Display Makefile help information for all actions
@awk 'BEGIN {FS = ":.*##"; \
printf "\nUsage:\n make \033[36m<target>\033[0m\n"} \
/^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } \
/^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) }' \
$(MAKEFILE_LIST)

##@ Initialization
# Tasks for setting up the project environment

.PHONY: install-tools
install-tools: ## Install tools (macOS/Linux)
LOCALBIN=$(LOCALBIN) GOBIN=$(LOCALBIN) ci_scripts/install-tools.sh || exit 1

##@ Build
# Tasks related to building the Helm chart

.PHONY: repo-update
repo-update:
repo-update: ## Update Helm repositories to latest
@{ \
if ! (helm repo list | grep -q open-telemetry) ; then \
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts ;\
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts || exit 1; \
fi ;\
if ! (helm repo list | grep -q jetstack) ; then \
helm repo add jetstack https://charts.jetstack.io ;\
helm repo add jetstack https://charts.jetstack.io || exit 1; \
fi ;\
helm repo update open-telemetry jetstack ;\
helm repo update open-telemetry jetstack || exit 1; \
jvoravong marked this conversation as resolved.
Show resolved Hide resolved
}

.PHONY: dep-build
dep-build:
dep-build: ## Build the Helm chart with latest dependencies from the current Helm repositories
@{ \
OK=true ;\
DIR=helm-charts/splunk-otel-collector ;\
if ! helm dependencies list $$DIR | grep open-telemetry | grep -q ok ; then OK=false ; fi ;\
if ! helm dependencies list $$DIR | grep jetstack | grep -q ok ; then OK=false ; fi ;\
if ! $$OK ; then helm dependencies build $$DIR ; fi ;\
DEP_OK=true ;\
DIR=helm-charts/splunk-otel-collector ;\
if ! helm dependencies list $$DIR | grep open-telemetry | grep -q ok ; then DEP_OK=false ; fi ;\
if ! helm dependencies list $$DIR | grep jetstack | grep -q ok ; then DEP_OK=false ; fi ;\
if [ "$$DEP_OK" = "false" ] ; then helm dependencies build $$DIR || exit 1; fi ;\
jvoravong marked this conversation as resolved.
Show resolved Hide resolved
}

.PHONY: render
render: repo-update dep-build ## Render the Helm chart with the examples as input
examples/render-examples.sh || exit 1

##@ Changelog
# Tasks related to changelog management

.PHONY: chlog-available
chlog-available: ## Validate the chloggen tool is available
@if [ -z "$(CHLOGGEN)" ]; then \
echo "Error: chloggen is not available. Please run 'make install-tools' to install it."; \
jvoravong marked this conversation as resolved.
Show resolved Hide resolved
exit 1; \
fi

# Example Usage:
# make chlog-new CHANGE_TYPE=enhancement COMPONENT=agent NOTE="Add X" ISSUES='[42]'
# make chlog-new [CHANGE_TYPE=enhancement] [COMPONENT=agent] [NOTE="Add X"] [ISSUES='[42]'] [FILENAME=add-x] [SUBTEXT="Add Y"]
.PHONY: chlog-new
chlog-new: chlog-available ## Creates or updates a YAML file under .chloggen
ci_scripts/chloggen-new.sh || exit 1

.PHONY: chlog-validate
chlog-validate: chlog-available ## Validates changelog requirements for pull requests
$(CHLOGGEN) validate || exit 1
ci_scripts/chloggen-pr-validate.sh || exit 1

.PHONY: chlog-preview
chlog-preview: chlog-validate ## Provide a preview of the generated CHANGELOG.md file for a release
$(CHLOGGEN) update --dry || exit 1

# Example Usage: make chlog-update
.PHONY: chlog-update
chlog-update: chlog-validate ## Creates an update to CHANGELOG.md for a release entry from content in .chloggen
$(CHLOGGEN) update --version "[$(VERSION)] - $$(date +'%Y-%m-%d')" || exit 1; \
ci_scripts/chloggen-update.sh || exit 1
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ of `version` field.
To make a new release of the helm chart:
1. Bump the chart `version` in [Chart.yaml](helm-charts/splunk-otel-collector/Chart.yaml)
1. Run `make render` to update Helm dependencies and render all the examples with the latest changes.
1. Run `make chlog-update` to update CHANGELOG.md for the release.
1. Create PR and request review from the team.
1. When the PR gets merged, the release will automatically be made and the helm repo updated.
1. Release notes are not populated automatically. So make sure to update them manually using the notes from [CHANGELOG](./CHANGELOG.md).
59 changes: 59 additions & 0 deletions ci_scripts/chloggen-new.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
# Purpose: Automates the creation or update of changelog entries based on input parameters.
# Notes:
# - Should be executed via the `make chlog-new` command.
# - Facilitates the automation of changelog entry creation.
# - Intended to be used with the `make chlog-new` command.
#
# Optional Parameters:
# - CHANGE_TYPE: Type of change (e.g., 'enhancement', 'bug_fix')
# - COMPONENT: Component affected by the change (e.g., 'operator')
# - NOTE: Brief description of the change
# - ISSUES: List of related issues or PRs
# - SUBCONTEXT: Additional information for the changelog entry
# - FILENAME: Name of the file to create or update, defaults to git branch name
# - DEBUG_MODE: Can be enabled for debugging

# Include the base utility functions for setting and debugging variables
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$SCRIPT_DIR/base_util.sh"

# ---- Initialize Variables ----
if [[ -z "$FILENAME" ]]; then
setd "FILENAME" $(git branch --show-current | tr -d '[:space:][:punct:]')
fi

# ---- Changelog Entry Validation ----
# Check for the existence of TEMPLATE.yaml
if [ ! -f ".chloggen/TEMPLATE.yaml" ]; then
echo "Error: .chloggen/TEMPLATE.yaml not found. Ensure it exists."
exit 1
fi

# ---- Changelog Entry Update ----
# Check if a changelog entry with the given filename already exists
if [ -f ".chloggen/${FILENAME}.yaml" ]; then
echo "Changelog entry ${FILENAME}.yaml already exists. Updating."
else
echo "Creating new changelog entry ${FILENAME}.yaml."
cp .chloggen/TEMPLATE.yaml .chloggen/${FILENAME}.yaml
fi

# Update fields only if the argument was passed
[[ ! -z "$CHANGE_TYPE" ]] && yq eval -i ".change_type = \"$CHANGE_TYPE\"" .chloggen/${FILENAME}.yaml
[[ ! -z "$COMPONENT" ]] && yq eval -i ".component = \"$COMPONENT\"" .chloggen/${FILENAME}.yaml
[[ ! -z "$NOTE" ]] && yq eval -i ".note = \"$NOTE\"" .chloggen/${FILENAME}.yaml
[[ ! -z "$SUBTEXT" ]] && yq eval -i ".subtext = \"$SUBTEXT\"" .chloggen/${FILENAME}.yaml
# Extend the list of issue IDs rather than overwriting them
if [ ! -z "$ISSUES" ]; then
# Extend the .issues field and update it
setd "OLD_ISSUES" "$(yq eval '.issues' ".chloggen/${FILENAME}.yaml")"
# Combine the old and new issues and deduplicate them
setd "NEW_ISSUES" "'$(echo "$OLD_ISSUES" "$ISSUES" | jq -sc 'add | unique')'"
echo "Resulting issues: $NEW_ISSUES"
yq eval -i ".issues = ${NEW_ISSUES//\'/} | .issues style=\"flow\" " ".chloggen/${FILENAME}.yaml"
fi


echo "${FILENAME}.yaml has been created or updated."
exit 0
69 changes: 69 additions & 0 deletions ci_scripts/chloggen-pr-validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
# Purpose: Validates the presence of a changelog entry based on file changes.
# Notes:
# - Should be executed via the `make chlog-validate` command.
# - Checks if certain types of files have been modified to require a changelog entry.
# - Designed to be a local check or to be used within a CI/CD pipeline.
# - Finds the last common commit with the main branch.
# - Checks for changes in specific directories and files:
# 1. Helm chart templates in 'helm-charts/splunk-otel-collector/templates/*'
# 2. Rendered manifests in 'examples/*/rendered_manifests/*'
# - Requires a '.chloggen' file if any of the above conditions is met.

# Include the base utility functions for setting and debugging variables
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$SCRIPT_DIR/base_util.sh"

# ---- Initialize Variables ----
# Get the current branch name
setd "CURRENT_BRANCH" $(git rev-parse --abbrev-ref HEAD)
# Get the last common commit with the main branch
setd "LAST_COMMON_COMMIT" $(git merge-base $CURRENT_BRANCH main)
# Initialize variables to keep track of changes
setd "HELM_CHART_UPDATED" 0
setd "RENDERED_MANIFESTS_UPDATED" 0
setd "CHLOGGEN_FILE_PRESENT" 0
# Get a list of all changed files since the last common commit with main
setd "COMMITTED_CHANGED_FILES" $(git diff --name-only $LAST_COMMON_COMMIT HEAD)
# Include uncommitted changes
setd "UNCOMMITTED_CHANGED_FILES" $(git diff --name-only)
# Combine both lists
setd "CHANGED_FILES" "$COMMITTED_CHANGED_FILES $UNCOMMITTED_CHANGED_FILES"

# ---- File Change Analysis ----
# Assess each modified file to determine if a changelog entry is required
for file in $CHANGED_FILES; do
# Monitor changes within the Helm chart templates
if [[ "$file" == helm-chart/splunk-otel-collector/templates* ]]; then
setd "HELM_CHART_UPDATED" 1
fi

# Monitor changes within the rendered manifests
if [[ "$file" == examples/*/rendered_manifests* ]]; then
setd "RENDERED_MANIFESTS_UPDATED" 1
fi

# Track the presence of a .chloggen file indicating a changelog entry
if [[ "$file" == *.chloggen ]]; then
setd "CHLOGGEN_FILE_PRESENT" 1
fi
done

# ---- Changelog Entry Validation ----
# Ensure that if critical files are modified, a corresponding changelog entry exists
if [[ $HELM_CHART_UPDATED -eq 1 ]] || [[ $RENDERED_MANIFESTS_UPDATED -eq 1 ]]; then
if [[ $CHLOGGEN_FILE_PRESENT -eq 0 ]]; then
echo "A changelog entry (.chloggen) is required for this commit. Reason:"
if [[ $HELM_CHART_UPDATED -eq 1 ]]; then
echo "- Updates to files under helm-chart/splunk-otel-collector/templates "
fi
if [[ $RENDERED_MANIFESTS_UPDATED -eq 1 ]]; then
echo "- Updates to files under examples/*/rendered_manifests"
fi
exit 1
fi
fi

# This format matches the chloggen tool format
echo "PASS: all changelog entries required for PR are valid"
exit 0
Loading