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

Monitoring and release pipeline #490

Merged
merged 8 commits into from
Nov 22, 2023
Merged
25 changes: 25 additions & 0 deletions .github/workflows/package_monitor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Auto instrumentation for version updates
sanojsubran marked this conversation as resolved.
Show resolved Hide resolved
run-name: Running job for checking newer packages and updating instrumentation
on:
schedule:
- cron: '0 4 * * *'
jobs:
monitor-update:
runs-on: ubuntu-latest
steps:
- name: Install package
run: |
sudo apt-get -y install jq

- uses: actions/checkout@v3
name: Checkout repo
with:
fetch-depth: 0
ssh-key: ${{secrets.PRIVATE_KEY_GO_TRACER_RELEASE}}

- name: Run script to monitor packages and create PR with updated changes
id: verison_updater
run: ./version_updater.sh
shell: bash {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions instrumentation/instaamqp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,9 @@ See the [`instaamqp` package documentation][godoc] for detailed examples.
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaamqp
[instaamqp.WrapChannel]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaamqp#WrapChannel
[amqp.Channel]: https://pkg.go.dev/github.com/streadway/[email protected]#Channel

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/streadway/amqp
current-version: v1.0.0
--->
6 changes: 6 additions & 0 deletions instrumentation/instaamqp091/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,9 @@ See the [`instaamqp091` package documentation][godoc] for detailed examples.
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaamqp091
[instaamqp091.WrapChannel]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaamqp091#WrapChannel
[amqp.Channel]: https://pkg.go.dev/github.com/rabbitmq/amqp091-go#Channel

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/rabbitmq/amqp091-go
current-version: v1.5.0
--->
6 changes: 6 additions & 0 deletions instrumentation/instaawssdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,9 @@ Known limitations:
[NewSensor]: https://pkg.go.dev/github.com/instana/go-sensor?tab=doc#NewSensor
[InstrumentSession]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaawssdk?tab=doc#InstrumentSession
[SpanContextFromSQSMessage]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaawssdk?tab=doc#SpanContextFromSQSMessage

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/aws/aws-sdk-go
current-version: v1.44.209
--->
6 changes: 6 additions & 0 deletions instrumentation/instaawsv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ Hence, to avoid collisions, it is recommended to avoid these keys in your applic
[SpanContextFromSQSMessage]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaawsv2?tab=doc#SpanContextFromSQSMessage
[aws-sdk-go-v2-github]: https://github.com/aws/aws-sdk-go-v2
[aws-config]: https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/config#Config

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/aws/aws-sdk-go-v2
current-version: v1.21.0
--->
2 changes: 1 addition & 1 deletion instrumentation/instaazurefunction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ Refer the [`instaazurefunction`](https://pkg.go.dev/github.com/instana/go-sensor
Limitations
-----------
- The instrumentation supports only HTTP and Queue trigger types.
- The instrumentation cannot support HTTP triggers if `enableForwardingHttpRequest` is set to `true` in the `host.json` file.
- The instrumentation cannot support HTTP triggers if `enableForwardingHttpRequest` is set to `true` in the `host.json` file.
7 changes: 7 additions & 0 deletions instrumentation/instabeego/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ _, err := req.Response()
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instabeego
[serverInstrumentationExample]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instabeego#example-package-ServerInstrumentation
[clientInstrumentationExample]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instabeego#example-package-HttpClientInstrumentation


<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/beego/beego/v2
current-version: v2.1.3
--->
6 changes: 6 additions & 0 deletions instrumentation/instaecho/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ e.GET("/foo", func(c echo.Context) error { /* ... */ })

[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaecho
[fullExample]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaecho#example-package

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/labstack/echo/v4
current-version: v0.4.9
--->
6 changes: 6 additions & 0 deletions instrumentation/instafiber/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ return c.SendString("Hello world!")
Refer to [`instafiber`](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instafiber) package documentation for more details.

[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instafiber

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/gofiber/fiber/v2
current-version: v2.50.0
--->
6 changes: 6 additions & 0 deletions instrumentation/instagin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ engine.GET("/api", func(c *gin.Context) {}

[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instagin
[fullExample]: https://github.com/instana/go-sensor/blob/main/example/gin/main.go

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/gin-gonic/gin
current-version: v1.9.1
--->
6 changes: 6 additions & 0 deletions instrumentation/instagorm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ instagorm.Instrument(db, sensor, dsn)


[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instagorm

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: gorm.io/gorm
current-version: v1.25.0
--->
6 changes: 6 additions & 0 deletions instrumentation/instagraphql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,9 @@ See the [`instagraphql` package documentation][godoc] for detailed examples.
[instagraphql.Do]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instagraphql#Do
[instagraphql.Subscribe]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instagraphql#Subscribe
[instagraphql.ResultCallbackFn]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instagraphql#ResultCallbackFn

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/graphql-go/graphql
current-version: v0.8.1
--->
6 changes: 6 additions & 0 deletions instrumentation/instagrpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ If the context contains an active span stored using [`instana.ContextWithSpan()`
[Sensor]: https://pkg.go.dev/github.com/instana/go-sensor/?tab=doc#Sensor
[SpanFromContext]: https://pkg.go.dev/github.com/instana/go-sensor/?tab=doc#SpanFromContext
[ContextWithSpan]: https://pkg.go.dev/github.com/instana/go-sensor/?tab=doc#ContextWithSpan

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: google.golang.org/grpc
current-version: v1.59.0
--->
6 changes: 6 additions & 0 deletions instrumentation/instahttprouter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ r.HandlerFunc(http.MethodDelete, "/foo/:id", func(writer http.ResponseWriter, re
[Full example](../../example/httprouter/main.go)

[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instahttprouter

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/julienschmidt/httprouter
current-version: v1.3.0
--->
6 changes: 6 additions & 0 deletions instrumentation/instalambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,9 @@ func subCall(ctx context.Context) {
[instalambda.NewHandler]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instalambda#NewHandler
[instalambda.WrapHandler]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instalambda#WrapHandler
[instana.SpanFromContext]: https://pkg.go.dev/github.com/instana/go-sensor#SpanFromContext

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/aws/aws-lambda-go
current-version: v1.20.0
--->
6 changes: 6 additions & 0 deletions instrumentation/instalogrus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ logrus.WithContext(ctx).

[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instalogrus
[fullExample]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instalogrus#example-package

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/sirupsen/logrus
current-version: v1.5.0
--->
6 changes: 6 additions & 0 deletions instrumentation/instamongo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ See the [`instamongo` package documentation][godoc] for detailed examples.
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instamongo
[instamongo.Connect]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instamongo#Connect
[instamongo.NewClient]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instamongo#NewClient

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: go.mongodb.org/mongo-driver
current-version: v1.7.2
--->
6 changes: 6 additions & 0 deletions instrumentation/instamux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ r.HandleFunc("/foo", func(writer http.ResponseWriter, request *http.Request) {})

[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instamux
[fullExample]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instamux#example-package

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/gorilla/mux
current-version: v1.8.0
--->
6 changes: 6 additions & 0 deletions instrumentation/instapgx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,9 @@ To run integration tests, a PostgreSQL database is required in the environment.
```bash
docker run -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres
```

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/jackc/pgx/v4
current-version: v4.14.1
--->
6 changes: 6 additions & 0 deletions instrumentation/instaredigo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ reply, err := conn.Do("SET", "greetings", "helloworld")
```

See the [`instaredigo` package documentation](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaredigo) for detailed examples.

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/gomodule/redigo
current-version: v1.8.8
--->
6 changes: 6 additions & 0 deletions instrumentation/instaredis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ See the [`instaredis` package documentation][godoc] for detailed examples.
[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaredis
[instaredis.WrapClient]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaredis#WrapClient
[instaredis.WrapClusterClient]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaredis#WrapClusterClient

<!---
Mandatory comment section for CI/CD !!
target-pkg-url: github.com/go-redis/redis/v8
current-version: v8.11.4
--->
1 change: 1 addition & 0 deletions instrumentation/instasarama/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,4 @@ See the topic [Kafka header migration](https://www.ibm.com/docs/en/instana-obser
[WrapConsumerGroupHandler]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instasarama?tab=doc#WrapConsumerGroupHandler
[ProducerMessageWithSpan]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instasarama?tab=doc#ProducerMessageWithSpan
[SpanContextFromConsumerMessage]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instasarama?tab=doc#SpanContextFromConsumerMessage

144 changes: 144 additions & 0 deletions version_updater.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#!/bin/bash

# (c) Copyright IBM Corp. 2023

# ---------------------------------------------------------------------- #
# Script to monitor the packages and update the instrumentation packages #
# ---------------------------------------------------------------------- #

# Function to extract the package url and current version from the metadata
extract_info_from_markdown() {
if [ -e "$1" ]; then
local markdown_text=$(<"$1")
# Extract target-package-url and current-version using awk
TARGET_PKG_URL=$(echo "$markdown_text" | awk -F: '/target-pkg-url:/ {print $2}' | tr -d '[:space:]')
CURRENT_VERSION=$(echo "$markdown_text" | awk -F: '/current-version:/ {print $2}' | tr -d '[:space:]')
else
echo "Error: File not found - $1"
TARGET_PKG_URL=""
CURRENT_VERSION=""
fi
}

# Function to query the latest released version of the package
find_latest_version() {
local pkg=$1
if [ -n "$pkg" ]; then
# Query the latest version for the package
local url="https://proxy.golang.org/${pkg}/@latest"
LATEST_VERSION=$(curl -s "$url" | jq .Version | tr -d '"')
else
LATEST_VERSION=""
echo "Invalid package location: $pkg"
fi

}

# Function to compare versions
version_compare() {
local version1=$1
local version2=$2

local major_version1=$(echo "$version1" | sed -E 's/v([0-9]+)\.([0-9]+)\..*/\1/')
local minor_version1=$(echo "$version1" | sed -E 's/v([0-9]+)\.([0-9]+)\..*/\2/')
local major_version2=$(echo "$version2" | sed -E 's/v([0-9]+)\.([0-9]+)\..*/\1/')
local minor_version2=$(echo "$version2" | sed -E 's/v([0-9]+)\.([0-9]+)\..*/\2/')

# We are checking the changes in minor versions for automation purpose
if [ "$major_version1" = "$major_version2" ] && [ "$minor_version1" -gt "$minor_version2" ]; then
echo "true"
else
echo "false"
fi
}

# Function to update the metadata with the latest version information
replace_version_in_file() {
local version=$1
local file_path=$2

# Read the content of the file
local file_content=$(<"$file_path")

# Replace current-version with the new version
# shellcheck disable=SC2001
local updated_content=$(echo "$file_content" | sed "s/current-version: [^ ]*/current-version: $version/")

# Write the updated content back to the file
echo "$updated_content" > "$file_path"
echo "Version in file $file_path updated to $version"
}

DIRECTORY_PATH=$(pwd)/instrumentation
echo "$DIRECTORY_PATH"

if [ -d "$DIRECTORY_PATH" ]; then
for folder in "$DIRECTORY_PATH"/*/; do
# Create a branch and commit the changes
git config user.name "IBM/Instana/Team Go"
git config user.email "[email protected]"

git checkout main

INSTRUMENTATION=$(basename "$folder")
# Identify the path to the README file
README_PATH="${folder}README.md"

echo "--------------$INSTRUMENTATION-----------------"
if [ ! -e "$README_PATH" ]; then
continue
fi

# Extract the metadata from the README file
extract_info_from_markdown "$README_PATH"

if [ -z "$TARGET_PKG_URL" ]; then
continue
fi

# Print the extracted values
#echo "Target Package URL: $TARGET_PKG_URL"
echo "Current Version: $CURRENT_VERSION"

# Find the latest version of the instrumented package
find_latest_version "$TARGET_PKG_URL"
echo "Latest version:" "$LATEST_VERSION"

version_compare "$LATEST_VERSION" "$CURRENT_VERSION"
update_needed=$( version_compare "$LATEST_VERSION" "$CURRENT_VERSION" )

if [ "$update_needed" != true ]; then
continue
fi

if gh pr list | grep -q "instrumentation $INSTRUMENTATION for new version $LATEST_VERSION"; then
echo "PR for $INSTRUMENTATION newer version:$LATEST_VERSION already exists. Skipping to next iteration"
continue
fi

echo "Update needed for this package. Update process starting..."
cd "$folder" || continue
go get "$TARGET_PKG_URL"
go mod tidy
go test ./... || echo "Continuing the operation even if the test fails. This needs manual intervention"


# Need to update the current version in the README file
replace_version_in_file "$LATEST_VERSION" "$README_PATH"

CURRENT_TIME_UNIX=$(date '+%s')
git checkout -b "update-instrumentations-$INSTRUMENTATION-id-$CURRENT_TIME_UNIX"

git add go.mod go.sum README.md
git commit -m "Updated go.mod, go.sum files, README.md for $INSTRUMENTATION"
git push origin @

# Create a PR request for the changes
# shellcheck disable=SC2046
gh pr create --title "Updating instrumentation $INSTRUMENTATION for new version $LATEST_VERSION. Id: $CURRENT_TIME_UNIX" \
--body "This PR adds changes for the newer version $LATEST_VERSION for the instrumented package" --head $(git branch --show-current)

done
else
echo "Error: The specified path is not a directory."
fi