Skip to content

Commit

Permalink
Merge branch 'main' into mtoff/trace_retries_interval
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoffl01 authored Dec 5, 2024
2 parents 20fcaa1 + 9980c24 commit f2d67c1
Show file tree
Hide file tree
Showing 23 changed files with 649 additions and 164 deletions.
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- [ ] If this interacts with the agent in a new way, a system test has been added.
- [ ] Add an appropriate team label so this PR gets put in the right place for the release notes.
- [ ] Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.
- [ ] For internal contributors, a matching PR should be created to the `v2-dev` branch and reviewed by @DataDog/apm-go.


Unsure? Have a question? Request a review!
153 changes: 153 additions & 0 deletions .github/workflows/apps/latest_major_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016 Datadog, Inc.

package main

import (
"encoding/json"
"fmt"
"sort"
"github.com/Masterminds/semver/v3"
"golang.org/x/mod/modfile"
"net/http"
"os"
"regexp"
"strings"
)

type Tag struct {
Name string
}

func getLatestMajorVersion(repo string) (string, error) {
// Get latest major version available for repo from github.
const apiURL = "https://api.github.com/repos/%s/tags"
url := fmt.Sprintf(apiURL, repo)

resp, err := http.Get(url)
if err != nil {
return "", err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("failed to fetch tags: %s", resp.Status)
}

var tags []struct {
Name string `json:"name"`
}

if err := json.NewDecoder(resp.Body).Decode(&tags); err != nil {
return "", err
}
latestByMajor := make(map[int]*semver.Version)

for _, tag := range tags {
v, err := semver.NewVersion(tag.Name)
if err != nil {
continue // Skip invalid versions
}

if v.Prerelease() != "" {
continue // Ignore pre-release versions
}

major := int(v.Major())
if current, exists := latestByMajor[major]; !exists || v.GreaterThan(current) {
latestByMajor[major] = v
}
}

var latestMajor *semver.Version
for _, v := range latestByMajor {
if latestMajor == nil || v.Major() > latestMajor.Major() {
latestMajor = v
}
}

if latestMajor != nil {
return fmt.Sprintf("v%d", latestMajor.Major()), nil
}

return "", fmt.Errorf("no valid versions found")

}

func main() {

data, err := os.ReadFile("integration_go.mod")
if err != nil {
fmt.Println("Error reading integration_go.mod:", err)
return
}

modFile, err := modfile.Parse("integration_go.mod", data, nil)
if err != nil {
fmt.Println("Error parsing integration_go.mod:", err)
return
}

latestMajor := make(map[string]*semver.Version)

// Match on versions with /v{major}
versionRegex := regexp.MustCompile(`^(?P<module>.+?)/v(\d+)$`)

// Iterate over the required modules and update latest major version if necessary
for _, req := range modFile.Require {
module := req.Mod.Path

if match := versionRegex.FindStringSubmatch(module); match != nil {
url := match[1] // base module URL (e.g., github.com/foo)
majorVersionStr := "v" + match[2] // Create semantic version string (e.g., "v2")

moduleName := strings.TrimPrefix(strings.TrimSpace(url), "github.com/")

// Parse the semantic version
majorVersion, err := semver.NewVersion(majorVersionStr)
if err != nil {
fmt.Printf("Skip invalid version for module %s: %v\n", module, err)
continue
}

if existing, ok := latestMajor[moduleName]; !ok || majorVersion.GreaterThan(existing) {
latestMajor[moduleName] = majorVersion
}
}
}

// Output latest major version that we support.
// Check if a new major version in Github is available that we don't support.
// If so, output that a new latest is available.

// Sort the output
modules := make([]string, 0, len(latestMajor))
for module := range latestMajor {
modules = append(modules, module)
}
sort.Strings(modules)

for _, module := range modules {
major := latestMajor[module]

latestVersion, err := getLatestMajorVersion(module) // latest version available
if err != nil {
fmt.Printf("Error fetching latest version for module '%s': %v\n", module, err)
continue
}

latestVersionParsed, err := semver.NewVersion(latestVersion)
if err != nil {
fmt.Printf("Error parsing latest version '%s' for module '%s': %v\n", latestVersion, module, err)
continue
}

fmt.Printf("Latest DD major version of %s: %d\n", module, major.Major())
if major.LessThan(latestVersionParsed) {
fmt.Printf("New latest major version of %s available: %d\n", module, latestVersionParsed.Major())
}

}
}
4 changes: 2 additions & 2 deletions .github/workflows/appsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ jobs:
needs: go-mod-caching
strategy:
matrix:
runs-on: [ macos-12, macos-14 ] # oldest and newest macos runners available - macos-14 mainly is here to cover the fact it is an ARM machine
runs-on: [ macos-13, macos-15 ] # oldest and newest macos runners available - macos-15 is an ARM runner
go-version: [ "1.23", "1.22" ]
fail-fast: true # saving some CI time - macos runners too long to get
fail-fast: true # saving some CI time - macos runners are too long to get
steps:
- uses: actions/checkout@v4

Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/outdated-integrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Outdated Integrations
on:
schedule:
- cron: "0 0 * * 0" # Runs every Sunday at midnight UTC
workflow_dispatch:

concurrency:
# Automatically cancel previous runs if a new one is triggered to conserve resources.
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Find new major versions for the contrib package dependencies
runs-on: ubuntu-latest
permissions:
actions: read
contents: write
pull-requests: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- run: go get github.com/Masterminds/semver/v3

- run: go run .github/workflows/apps/latest_major_version.go > latests.txt

- run: git diff

- name: Create Pull Request
id: pr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: "upgrade-latest-major-version"
commit-message: "Update latests file"
base: main
title: "chore: update latest majors"
labels: changelog/no-changelog
body: "Auto-generated PR from Outdated Integrations workflow to update latests major versions"
24 changes: 12 additions & 12 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Note: Later matches take precedence

# default owner
* @DataDog/dd-trace-go-guild
* @DataDog/dd-trace-go-guild @DataDog/apm-go

# no owner: changes to these files will not automatically ping any particular
# team and can be reviewed by anybody with the appropriate permissions. This is
Expand All @@ -15,22 +15,22 @@ go.sum
/ddtrace @DataDog/apm-go

# profiling
/profiler @DataDog/profiling-go
/internal/traceprof @DataDog/profiling-go
/profiler @DataDog/profiling-go @DataDog/apm-go
/internal/traceprof @DataDog/profiling-go @DataDog/apm-go

# appsec
/appsec @DataDog/asm-go
/internal/appsec @DataDog/asm-go
/contrib/**/*appsec*.go @DataDog/asm-go
/.github/workflows/appsec.yml @DataDog/asm-go
/appsec @DataDog/asm-go @DataDog/apm-go
/internal/appsec @DataDog/asm-go @DataDog/apm-go
/contrib/**/*appsec*.go @DataDog/asm-go @DataDog/apm-go
/.github/workflows/appsec.yml @DataDog/asm-go @DataDog/apm-go

# datastreams
/datastreams @Datadog/data-streams-monitoring
/internal/datastreams @Datadog/data-streams-monitoring
/datastreams @Datadog/data-streams-monitoring @DataDog/apm-go
/internal/datastreams @Datadog/data-streams-monitoring @DataDog/apm-go

# civisibility
/internal/civisibility @DataDog/ci-app-libraries
/internal/civisibility @DataDog/ci-app-libraries @DataDog/apm-go

# Gitlab configuration
.gitlab-ci.yml @DataDog/dd-trace-go-guild @DataDog/apm-core-reliability-and-performance
/.gitlab-ci @DataDog/dd-trace-go-guild @DataDog/apm-core-reliability-and-performance
.gitlab-ci.yml @DataDog/dd-trace-go-guild @DataDog/apm-core-reliability-and-performance @DataDog/apm-go
/.gitlab-ci @DataDog/dd-trace-go-guild @DataDog/apm-core-reliability-and-performance @DataDog/apm-go
11 changes: 11 additions & 0 deletions ddtrace/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"fmt"
"log"
"os"
"os/signal"
"syscall"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
Expand All @@ -27,6 +29,15 @@ func Example_datadog() {
tracer.Start(tracer.WithAgentAddr("host:port"))
defer tracer.Stop()

// If you expect your application to be shutdown via SIGTERM (e.g. a container in k8s)
// You likely want to listen for that signal and stop the tracer to ensure no data is lost
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGTERM)
go func() {
<-sigChan
tracer.Stop()
}()

// Start a root span.
span := tracer.StartSpan("get.data")
defer span.Finish()
Expand Down
2 changes: 0 additions & 2 deletions ddtrace/tracer/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type startupInfo struct {
Tags map[string]string `json:"tags"` // Global tags
RuntimeMetricsEnabled bool `json:"runtime_metrics_enabled"` // Whether runtime metrics are enabled
RuntimeMetricsV2Enabled bool `json:"runtime_metrics_v2_enabled"` // Whether runtime metrics v2 are enabled
HealthMetricsEnabled bool `json:"health_metrics_enabled"` // Whether health metrics are enabled
ProfilerCodeHotspotsEnabled bool `json:"profiler_code_hotspots_enabled"` // Whether profiler code hotspots are enabled
ProfilerEndpointsEnabled bool `json:"profiler_endpoints_enabled"` // Whether profiler endpoints are enabled
ApplicationVersion string `json:"dd_version"` // Version of the user's application
Expand Down Expand Up @@ -133,7 +132,6 @@ func logStartup(t *tracer) {
Tags: tags,
RuntimeMetricsEnabled: t.config.runtimeMetrics,
RuntimeMetricsV2Enabled: t.config.runtimeMetricsV2,
HealthMetricsEnabled: t.config.runtimeMetrics,
ApplicationVersion: t.config.version,
ProfilerCodeHotspotsEnabled: t.config.profilerHotspots,
ProfilerEndpointsEnabled: t.config.profilerEndpoints,
Expand Down
Loading

0 comments on commit f2d67c1

Please sign in to comment.