Skip to content

Commit 644f1b6

Browse files
crobert-1Fiery-Fenix
authored andcommitted
[chore][ping code owners] Attempt to match component and label identically when possible (open-telemetry#39145)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description The logic for pinging code owners where multiple labels matched a given component returned the first in alphabetical order. This worked generally as the first alphabetical response was the minimal matching value, as shown in open-telemetry#38844. However, this breaks on the kafka receiver labels. The component labels are sorted in alphabetical order by the full component name. This means `receiver/kafkametricsreceiver` is before `receiver/kafkareceiver` in the list. When the `receiver/kafka` component is referenced, the `receiver/kafkametrics` label is returned as it's the first matching label in alphabetical order. This change is to try to match component and label identically. If there's no identical match, return the first label in alphabetical order. Existing logic has been broken out into a separate script to avoid duplicating the logic. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Unexpected behavior was found in open-telemetry#39129. `receiver/kafka` was the component, the label `receiver/kafkametrics` was added incorrectly, and the code owners were pinged for `receiver/kafka` correctly. When I removed the `receiver/kafkametrics` label and added `receiver/kafka`, the code owners were pinged for `receiver/kafkametrics` incorrectly. <!--Describe what testing was performed and which tests were added.--> #### Testing ``` # Testing issue where bug was detected $ .github/workflows/scripts/ping-codeowners-on-new-issue.sh No related components were given Adding the following labels: receiver/kafka Pinging code owners: - receiver/kafka: @pavolloffay @MovieStoreGuy @axw See [Adding Labels via Comments](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#adding-labels-via-comments) if you do not have permissions to add labels yourself. # Testing other components $ export COMPONENT="os:windows" $ .github/workflows/scripts/get-label-from-component.sh $ export COMPONENT="receiver/hostmetrics" $ .github/workflows/scripts/get-label-from-component.sh receiver/hostmetrics $ export COMPONENT="receiver/kafka" $ .github/workflows/scripts/get-label-from-component.sh receiver/kafka $ export COMPONENT="receiver/kafkametrics" $ .github/workflows/scripts/get-label-from-component.sh receiver/kafkametrics $ export COMPONENT="extension/encoding" $ .github/workflows/scripts/get-label-from-component.sh extension/encoding $ export ISSUE=39129 $ COMPONENT="receiver/kafka" $ .github/workflows/scripts/ping-codeowners-issues.sh Pinging code owners for receiver/kafka: @pavolloffay @MovieStoreGuy @axw. See [Adding Labels via Comments](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#adding-labels-via-comments) if you do not have permissions to add labels yourself. For example, comment '/label priority:p2 -needs-triaged' to set the priority and remove the needs-triaged label. $ COMPONENT="receiver/kafkametrics" $ .github/workflows/scripts/ping-codeowners-issues.sh Pinging code owners for receiver/kafkametrics: @dmitryax. See [Adding Labels via Comments](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#adding-labels-via-comments) if you do not have permissions to add labels yourself. For example, comment '/label priority:p2 -needs-triaged' to set the priority and remove the needs-triaged label. ```
1 parent b9d14b3 commit 644f1b6

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright The OpenTelemetry Authors
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# This script is used to get the component label from a given COMPONENT.
7+
# The key here is to match a single component based on the input component,
8+
# and match it exactly.
9+
#
10+
11+
set -euo pipefail
12+
13+
get_label() {
14+
MATCHING_LABELS=$(awk -v path="${COMPONENT}" 'index($1, path) > 0 || index($2, path) > 0 {print $2}' .github/component_labels.txt)
15+
16+
if [ -z "${MATCHING_LABELS}" ]; then
17+
echo ""
18+
return
19+
fi
20+
21+
LABEL_NAME=""
22+
for POTENTIAL_LABEL in ${MATCHING_LABELS}; do
23+
if [ "$POTENTIAL_LABEL" = "$COMPONENT" ]; then
24+
LABEL_NAME=$POTENTIAL_LABEL
25+
break
26+
fi
27+
done
28+
29+
if [ -z "${LABEL_NAME}" ]; then
30+
LABEL_NAME="${MATCHING_LABELS[0]}"
31+
fi
32+
33+
echo $LABEL_NAME
34+
}
35+
36+
if [[ -z "${COMPONENT:-}" ]]; then
37+
echo "COMPONENT has not been set, please ensure it is set."
38+
exit 1
39+
fi
40+
41+
echo "$(get_label)"

.github/workflows/scripts/ping-codeowners-issues.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if [[ -z "${COMPONENT:-}" || -z "${ISSUE:-}" ]]; then
1313
fi
1414

1515
CUR_DIRECTORY=$(dirname "$0")
16-
COMPONENT=$(awk -v path="${COMPONENT}" 'index($1, path) > 0 || index($2, path) > 0 {print $1}' .github/component_labels.txt | head -n 1)
16+
COMPONENT=$(COMPONENT="${COMPONENT}" "${CUR_DIRECTORY}/get-label-from-component.sh" || true)
1717
# Some labels are unrelated to components. These labels do not have code owners,
1818
# e.g "os:windows", "priority:p1", and "chore"
1919
if [[ -z "${COMPONENT}" ]]; then

.github/workflows/scripts/ping-codeowners-on-new-issue.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ if [[ -n "${TITLE_COMPONENT}" && ! ("${TITLE_COMPONENT}" =~ " ") ]]; then
3333
if [[ -n "${CODEOWNERS}" ]]; then
3434
PING_LINES+="- ${TITLE_COMPONENT}: ${CODEOWNERS}\n"
3535
PINGED_COMPONENTS["${TITLE_COMPONENT}"]=1
36-
LABEL_NAME=$(awk -v path="${TITLE_COMPONENT}" 'index($1, path) > 0 || index($2, path) > 0 {print $2}' .github/component_labels.txt | head -n 1)
36+
LABEL_NAME=$(COMPONENT="${TITLE_COMPONENT}" "${CUR_DIRECTORY}/get-label-from-component.sh" || true)
37+
3738
if (( "${#LABEL_NAME}" <= 50 )); then
3839
LABELS+="${LABEL_NAME}"
3940
else
@@ -55,7 +56,8 @@ for COMPONENT in ${BODY_COMPONENTS}; do
5556

5657
PING_LINES+="- ${COMPONENT}: ${CODEOWNERS}\n"
5758
PINGED_COMPONENTS["${COMPONENT}"]=1
58-
LABEL_NAME=$(awk -v path="${COMPONENT}" 'index($1, path) > 0 || index($2, path) > 0 {print $2}' .github/component_labels.txt | head -n 1)
59+
LABEL_NAME=$(COMPONENT="${COMPONENT}" "${CUR_DIRECTORY}/get-label-from-component.sh" || true)
60+
5961
if (( "${#LABEL_NAME}" > 50 )); then
6062
echo "'${LABEL_NAME}' exceeds GitHub's 50-character limit on labels, skipping adding a label"
6163
continue
@@ -68,6 +70,7 @@ for COMPONENT in ${BODY_COMPONENTS}; do
6870
fi
6971
done
7072

73+
# TODO: This check isn't working, it always returns no related components
7174
if [[ -v PINGED_COMPONENTS[@] ]]; then
7275
echo "The issue was associated with components:" "${!PINGED_COMPONENTS[@]}"
7376
else

0 commit comments

Comments
 (0)