Skip to content

Commit 61fda6e

Browse files
authored
Monitoring and release pipeline (#490)
* Adding meta data for monitoring packages * Added script for monitoring and updating packages * Added github action for monitoring and updating * Updated github workflow for version monitoring and updation. * Updated script not to create a duplicate PR if one already exists for the same version * Scheduling the job to run at 4am on a daily basis * Refactored the monitoring script * Changed the title of Github Action
1 parent 990d72b commit 61fda6e

File tree

23 files changed

+286
-1
lines changed

23 files changed

+286
-1
lines changed

Diff for: .github/workflows/package_monitor.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Auto update for instrumentation packages
2+
run-name: Running job for checking newer packages and updating instrumentation
3+
on:
4+
schedule:
5+
- cron: '0 4 * * *'
6+
jobs:
7+
monitor-update:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Install package
11+
run: |
12+
sudo apt-get -y install jq
13+
14+
- uses: actions/checkout@v3
15+
name: Checkout repo
16+
with:
17+
fetch-depth: 0
18+
ssh-key: ${{secrets.PRIVATE_KEY_GO_TRACER_RELEASE}}
19+
20+
- name: Run script to monitor packages and create PR with updated changes
21+
id: verison_updater
22+
run: ./version_updater.sh
23+
shell: bash {0}
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Diff for: instrumentation/instaamqp/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,9 @@ See the [`instaamqp` package documentation][godoc] for detailed examples.
117117
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaamqp
118118
[instaamqp.WrapChannel]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaamqp#WrapChannel
119119
[amqp.Channel]: https://pkg.go.dev/github.com/streadway/[email protected]#Channel
120+
121+
<!---
122+
Mandatory comment section for CI/CD !!
123+
target-pkg-url: github.com/streadway/amqp
124+
current-version: v1.0.0
125+
--->

Diff for: instrumentation/instaamqp091/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,9 @@ See the [`instaamqp091` package documentation][godoc] for detailed examples.
132132
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaamqp091
133133
[instaamqp091.WrapChannel]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaamqp091#WrapChannel
134134
[amqp.Channel]: https://pkg.go.dev/github.com/rabbitmq/amqp091-go#Channel
135+
136+
<!---
137+
Mandatory comment section for CI/CD !!
138+
target-pkg-url: github.com/rabbitmq/amqp091-go
139+
current-version: v1.5.0
140+
--->

Diff for: instrumentation/instaawssdk/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,9 @@ Known limitations:
116116
[NewSensor]: https://pkg.go.dev/github.com/instana/go-sensor?tab=doc#NewSensor
117117
[InstrumentSession]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaawssdk?tab=doc#InstrumentSession
118118
[SpanContextFromSQSMessage]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaawssdk?tab=doc#SpanContextFromSQSMessage
119+
120+
<!---
121+
Mandatory comment section for CI/CD !!
122+
target-pkg-url: github.com/aws/aws-sdk-go
123+
current-version: v1.44.209
124+
--->

Diff for: instrumentation/instaawsv2/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ Hence, to avoid collisions, it is recommended to avoid these keys in your applic
5757
[SpanContextFromSQSMessage]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaawsv2?tab=doc#SpanContextFromSQSMessage
5858
[aws-sdk-go-v2-github]: https://github.com/aws/aws-sdk-go-v2
5959
[aws-config]: https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/config#Config
60+
61+
<!---
62+
Mandatory comment section for CI/CD !!
63+
target-pkg-url: github.com/aws/aws-sdk-go-v2
64+
current-version: v1.21.0
65+
--->

Diff for: instrumentation/instaazurefunction/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ Refer the [`instaazurefunction`](https://pkg.go.dev/github.com/instana/go-sensor
4444
Limitations
4545
-----------
4646
- The instrumentation supports only HTTP and Queue trigger types.
47-
- The instrumentation cannot support HTTP triggers if `enableForwardingHttpRequest` is set to `true` in the `host.json` file.
47+
- The instrumentation cannot support HTTP triggers if `enableForwardingHttpRequest` is set to `true` in the `host.json` file.

Diff for: instrumentation/instabeego/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,10 @@ _, err := req.Response()
6969
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instabeego
7070
[serverInstrumentationExample]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instabeego#example-package-ServerInstrumentation
7171
[clientInstrumentationExample]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instabeego#example-package-HttpClientInstrumentation
72+
73+
74+
<!---
75+
Mandatory comment section for CI/CD !!
76+
target-pkg-url: github.com/beego/beego/v2
77+
current-version: v2.1.3
78+
--->

Diff for: instrumentation/instaecho/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ e.GET("/foo", func(c echo.Context) error { /* ... */ })
3333

3434
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaecho
3535
[fullExample]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaecho#example-package
36+
37+
<!---
38+
Mandatory comment section for CI/CD !!
39+
target-pkg-url: github.com/labstack/echo/v4
40+
current-version: v0.4.9
41+
--->

Diff for: instrumentation/instafiber/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ return c.SendString("Hello world!")
3333
Refer to [`instafiber`](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instafiber) package documentation for more details.
3434

3535
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instafiber
36+
37+
<!---
38+
Mandatory comment section for CI/CD !!
39+
target-pkg-url: github.com/gofiber/fiber/v2
40+
current-version: v2.50.0
41+
--->

Diff for: instrumentation/instagin/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ engine.GET("/api", func(c *gin.Context) {}
4343

4444
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instagin
4545
[fullExample]: https://github.com/instana/go-sensor/blob/main/example/gin/main.go
46+
47+
<!---
48+
Mandatory comment section for CI/CD !!
49+
target-pkg-url: github.com/gin-gonic/gin
50+
current-version: v1.9.1
51+
--->

Diff for: instrumentation/instagorm/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ instagorm.Instrument(db, sensor, dsn)
3636

3737

3838
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instagorm
39+
40+
<!---
41+
Mandatory comment section for CI/CD !!
42+
target-pkg-url: gorm.io/gorm
43+
current-version: v1.25.0
44+
--->

Diff for: instrumentation/instagraphql/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,9 @@ See the [`instagraphql` package documentation][godoc] for detailed examples.
105105
[instagraphql.Do]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instagraphql#Do
106106
[instagraphql.Subscribe]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instagraphql#Subscribe
107107
[instagraphql.ResultCallbackFn]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instagraphql#ResultCallbackFn
108+
109+
<!---
110+
Mandatory comment section for CI/CD !!
111+
target-pkg-url: github.com/graphql-go/graphql
112+
current-version: v0.8.1
113+
--->

Diff for: instrumentation/instagrpc/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,9 @@ If the context contains an active span stored using [`instana.ContextWithSpan()`
8181
[Sensor]: https://pkg.go.dev/github.com/instana/go-sensor/?tab=doc#Sensor
8282
[SpanFromContext]: https://pkg.go.dev/github.com/instana/go-sensor/?tab=doc#SpanFromContext
8383
[ContextWithSpan]: https://pkg.go.dev/github.com/instana/go-sensor/?tab=doc#ContextWithSpan
84+
85+
<!---
86+
Mandatory comment section for CI/CD !!
87+
target-pkg-url: google.golang.org/grpc
88+
current-version: v1.59.0
89+
--->

Diff for: instrumentation/instahttprouter/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ r.HandlerFunc(http.MethodDelete, "/foo/:id", func(writer http.ResponseWriter, re
3939
[Full example](../../example/httprouter/main.go)
4040

4141
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instahttprouter
42+
43+
<!---
44+
Mandatory comment section for CI/CD !!
45+
target-pkg-url: github.com/julienschmidt/httprouter
46+
current-version: v1.3.0
47+
--->

Diff for: instrumentation/instalambda/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,9 @@ func subCall(ctx context.Context) {
112112
[instalambda.NewHandler]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instalambda#NewHandler
113113
[instalambda.WrapHandler]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instalambda#WrapHandler
114114
[instana.SpanFromContext]: https://pkg.go.dev/github.com/instana/go-sensor#SpanFromContext
115+
116+
<!---
117+
Mandatory comment section for CI/CD !!
118+
target-pkg-url: github.com/aws/aws-lambda-go
119+
current-version: v1.20.0
120+
--->

Diff for: instrumentation/instalogrus/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,9 @@ logrus.WithContext(ctx).
4040

4141
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instalogrus
4242
[fullExample]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instalogrus#example-package
43+
44+
<!---
45+
Mandatory comment section for CI/CD !!
46+
target-pkg-url: github.com/sirupsen/logrus
47+
current-version: v1.5.0
48+
--->

Diff for: instrumentation/instamongo/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@ See the [`instamongo` package documentation][godoc] for detailed examples.
3838
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instamongo
3939
[instamongo.Connect]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instamongo#Connect
4040
[instamongo.NewClient]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instamongo#NewClient
41+
42+
<!---
43+
Mandatory comment section for CI/CD !!
44+
target-pkg-url: go.mongodb.org/mongo-driver
45+
current-version: v1.7.2
46+
--->

Diff for: instrumentation/instamux/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ r.HandleFunc("/foo", func(writer http.ResponseWriter, request *http.Request) {})
3737

3838
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instamux
3939
[fullExample]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instamux#example-package
40+
41+
<!---
42+
Mandatory comment section for CI/CD !!
43+
target-pkg-url: github.com/gorilla/mux
44+
current-version: v1.8.0
45+
--->

Diff for: instrumentation/instapgx/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ To run integration tests, a PostgreSQL database is required in the environment.
6969
```bash
7070
docker run -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres
7171
```
72+
73+
<!---
74+
Mandatory comment section for CI/CD !!
75+
target-pkg-url: github.com/jackc/pgx/v4
76+
current-version: v4.14.1
77+
--->

Diff for: instrumentation/instaredigo/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ reply, err := conn.Do("SET", "greetings", "helloworld")
2727
```
2828

2929
See the [`instaredigo` package documentation](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaredigo) for detailed examples.
30+
31+
<!---
32+
Mandatory comment section for CI/CD !!
33+
target-pkg-url: github.com/gomodule/redigo
34+
current-version: v1.8.8
35+
--->

Diff for: instrumentation/instaredis/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ See the [`instaredis` package documentation][godoc] for detailed examples.
3737
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaredis
3838
[instaredis.WrapClient]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaredis#WrapClient
3939
[instaredis.WrapClusterClient]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaredis#WrapClusterClient
40+
41+
<!---
42+
Mandatory comment section for CI/CD !!
43+
target-pkg-url: github.com/go-redis/redis/v8
44+
current-version: v8.11.4
45+
--->

Diff for: instrumentation/instasarama/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,4 @@ See the topic [Kafka header migration](https://www.ibm.com/docs/en/instana-obser
151151
[WrapConsumerGroupHandler]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instasarama?tab=doc#WrapConsumerGroupHandler
152152
[ProducerMessageWithSpan]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instasarama?tab=doc#ProducerMessageWithSpan
153153
[SpanContextFromConsumerMessage]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instasarama?tab=doc#SpanContextFromConsumerMessage
154+

Diff for: version_updater.sh

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/bin/bash
2+
3+
# (c) Copyright IBM Corp. 2023
4+
5+
# ---------------------------------------------------------------------- #
6+
# Script to monitor the packages and update the instrumentation packages #
7+
# ---------------------------------------------------------------------- #
8+
9+
# Function to extract the package url and current version from the metadata
10+
extract_info_from_markdown() {
11+
if [ -e "$1" ]; then
12+
local markdown_text=$(<"$1")
13+
# Extract target-package-url and current-version using awk
14+
TARGET_PKG_URL=$(echo "$markdown_text" | awk -F: '/target-pkg-url:/ {print $2}' | tr -d '[:space:]')
15+
CURRENT_VERSION=$(echo "$markdown_text" | awk -F: '/current-version:/ {print $2}' | tr -d '[:space:]')
16+
else
17+
echo "Error: File not found - $1"
18+
TARGET_PKG_URL=""
19+
CURRENT_VERSION=""
20+
fi
21+
}
22+
23+
# Function to query the latest released version of the package
24+
find_latest_version() {
25+
local pkg=$1
26+
if [ -n "$pkg" ]; then
27+
# Query the latest version for the package
28+
local url="https://proxy.golang.org/${pkg}/@latest"
29+
LATEST_VERSION=$(curl -s "$url" | jq .Version | tr -d '"')
30+
else
31+
LATEST_VERSION=""
32+
echo "Invalid package location: $pkg"
33+
fi
34+
35+
}
36+
37+
# Function to compare versions
38+
version_compare() {
39+
local version1=$1
40+
local version2=$2
41+
42+
local major_version1=$(echo "$version1" | sed -E 's/v([0-9]+)\.([0-9]+)\..*/\1/')
43+
local minor_version1=$(echo "$version1" | sed -E 's/v([0-9]+)\.([0-9]+)\..*/\2/')
44+
local major_version2=$(echo "$version2" | sed -E 's/v([0-9]+)\.([0-9]+)\..*/\1/')
45+
local minor_version2=$(echo "$version2" | sed -E 's/v([0-9]+)\.([0-9]+)\..*/\2/')
46+
47+
# We are checking the changes in minor versions for automation purpose
48+
if [ "$major_version1" = "$major_version2" ] && [ "$minor_version1" -gt "$minor_version2" ]; then
49+
echo "true"
50+
else
51+
echo "false"
52+
fi
53+
}
54+
55+
# Function to update the metadata with the latest version information
56+
replace_version_in_file() {
57+
local version=$1
58+
local file_path=$2
59+
60+
# Read the content of the file
61+
local file_content=$(<"$file_path")
62+
63+
# Replace current-version with the new version
64+
# shellcheck disable=SC2001
65+
local updated_content=$(echo "$file_content" | sed "s/current-version: [^ ]*/current-version: $version/")
66+
67+
# Write the updated content back to the file
68+
echo "$updated_content" > "$file_path"
69+
echo "Version in file $file_path updated to $version"
70+
}
71+
72+
DIRECTORY_PATH=$(pwd)/instrumentation
73+
echo "$DIRECTORY_PATH"
74+
75+
if [ -d "$DIRECTORY_PATH" ]; then
76+
for folder in "$DIRECTORY_PATH"/*/; do
77+
# Create a branch and commit the changes
78+
git config user.name "IBM/Instana/Team Go"
79+
git config user.email "[email protected]"
80+
81+
git checkout main
82+
83+
INSTRUMENTATION=$(basename "$folder")
84+
# Identify the path to the README file
85+
README_PATH="${folder}README.md"
86+
87+
echo "--------------$INSTRUMENTATION-----------------"
88+
if [ ! -e "$README_PATH" ]; then
89+
continue
90+
fi
91+
92+
# Extract the metadata from the README file
93+
extract_info_from_markdown "$README_PATH"
94+
95+
if [ -z "$TARGET_PKG_URL" ]; then
96+
continue
97+
fi
98+
99+
# Print the extracted values
100+
#echo "Target Package URL: $TARGET_PKG_URL"
101+
echo "Current Version: $CURRENT_VERSION"
102+
103+
# Find the latest version of the instrumented package
104+
find_latest_version "$TARGET_PKG_URL"
105+
echo "Latest version:" "$LATEST_VERSION"
106+
107+
version_compare "$LATEST_VERSION" "$CURRENT_VERSION"
108+
update_needed=$( version_compare "$LATEST_VERSION" "$CURRENT_VERSION" )
109+
110+
if [ "$update_needed" != true ]; then
111+
continue
112+
fi
113+
114+
if gh pr list | grep -q "instrumentation $INSTRUMENTATION for new version $LATEST_VERSION"; then
115+
echo "PR for $INSTRUMENTATION newer version:$LATEST_VERSION already exists. Skipping to next iteration"
116+
continue
117+
fi
118+
119+
echo "Update needed for this package. Update process starting..."
120+
cd "$folder" || continue
121+
go get "$TARGET_PKG_URL"
122+
go mod tidy
123+
go test ./... || echo "Continuing the operation even if the test fails. This needs manual intervention"
124+
125+
126+
# Need to update the current version in the README file
127+
replace_version_in_file "$LATEST_VERSION" "$README_PATH"
128+
129+
CURRENT_TIME_UNIX=$(date '+%s')
130+
git checkout -b "update-instrumentations-$INSTRUMENTATION-id-$CURRENT_TIME_UNIX"
131+
132+
git add go.mod go.sum README.md
133+
git commit -m "Updated go.mod, go.sum files, README.md for $INSTRUMENTATION"
134+
git push origin @
135+
136+
# Create a PR request for the changes
137+
# shellcheck disable=SC2046
138+
gh pr create --title "Updating instrumentation $INSTRUMENTATION for new version $LATEST_VERSION. Id: $CURRENT_TIME_UNIX" \
139+
--body "This PR adds changes for the newer version $LATEST_VERSION for the instrumented package" --head $(git branch --show-current)
140+
141+
done
142+
else
143+
echo "Error: The specified path is not a directory."
144+
fi

0 commit comments

Comments
 (0)