Skip to content

Commit

Permalink
Upgrade telegraf v1-23-0 (#437)
Browse files Browse the repository at this point in the history
* Upgrade telegraf version to aws version of 1.23.0, bump go version to 1.17, make necessary changes to fix building errors.

* Bump Go version to 1.17 and make adjustments accordingly

* Bump github yaml go versions to 1.17.8

* WIP: dep fix

* Fix Cadvisor and Remove Cadvisor For Darwin (#454)

Update Cadvisor, Runc, GOPSUtil

* Create separate RegisterEventLogger for non-windows and windows

* Lumberjack logger fix

* Use Empty Context For K8 Endpoints

* Add k8 Logging (#466)

* Fix K8 namespace_number_of_running_pods

* Make Opts Empty Instead Of Var

* Echo TOML Output

* Upload To Public Test ECR

* Use Public Test ECR

* Add Log Line For Checking EC2 Metadata

* Remove Not Needed Log Line

* Add Back {{cluster_name}} From Hard Coded Cluster

* Mount Containerd Sock

* Update scraper code in start.go

* Use https://github.com/aws-samples/amazon-cloudwatch-container-insights/blob/master/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/prometheus-eks.yaml For Prometheus EKS Yaml

* Update Prometheus Version

* Init Prometheus Discovery

* Add Go Mod Caching To Dockerfile

* Fix Haproxy Missing haproxy_backend_http_responses_total$

* Post rebasing go mod tidy and vender sync

* Resolve Some Comments

* resolving comments

Co-authored-by: Seth L <[email protected]>
Co-authored-by: Seth Levine <[email protected]>
  • Loading branch information
3 people authored Jun 8, 2022
1 parent 5d7e322 commit 5335531
Show file tree
Hide file tree
Showing 63 changed files with 4,284 additions and 893 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.15.15
go-version: ~1.17.8

- name: Check out code
uses: actions/checkout@v2
Expand All @@ -41,7 +41,7 @@ jobs:

- uses: zencargo/github-action-go-mod-tidy@v1
with:
go-version: 1.15
go-version: 1.17.8

- name: Cache build output
uses: actions/cache@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.15.15
go-version: ~1.17.8

- name: Check out code
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ~1.15.15
go-version: ~1.17.8

- name: Cache Go
uses: actions/cache@v2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/integrationTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.15.15
go-version: ~1.17.8

- name: Install rpm
run: sudo apt install rpm
Expand Down Expand Up @@ -181,7 +181,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.15.15
go-version: ~1.17.8

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
Expand Down Expand Up @@ -238,7 +238,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.15.15
go-version: ~1.17.8

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.15.15
go-version: ~1.17.8
id: go

#Need to install rpm so ubuntu can make rpm by default ubuntu can make deb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ FROM $GO_IMAGE as builder
# NOTE: This arg will be populated by docker buildx
# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
ARG TARGETARCH
ENV GOPROXY=direct
RUN mkdir -p /go/src/github.com/aws/amazon-cloudwatch-agent/
WORKDIR /go/src/github.com/aws/amazon-cloudwatch-agent/

ARG GO111MODULE="on"
ENV GO111MODULE=${GO111MODULE}

COPY go.mod /go/src/github.com/aws/amazon-cloudwatch-agent/
COPY go.sum /go/src/github.com/aws/amazon-cloudwatch-agent/
RUN go mod download -x
COPY . /go/src/github.com/aws/amazon-cloudwatch-agent/
RUN make build-for-docker-${TARGETARCH}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ data:
]
},
{
"source_labels": ["Service", "backend"],
"label_matcher": ".*haproxy-ingress-.*metrics;(httpback-shared-backend|httpback-default-backend|httpsback-shared-backend|_default_backend|.*backend_http)",
"source_labels": ["Service"],
"label_matcher": ".*haproxy-ingress-.*metrics",
"dimensions": [["Service","Namespace","ClusterName","backend","code"]],
"metric_selectors": [
"^haproxy_backend_http_responses_total$"
Expand Down Expand Up @@ -230,7 +230,6 @@ data:
source_labels:
- __meta_kubernetes_pod_phase
target_label: pod_phase
- job_name: 'kubernetes-pod-fluentbit-plugin'
sample_limit: 10000
metrics_path: /api/v1/metrics/prometheus
Expand Down Expand Up @@ -274,7 +273,6 @@ data:
source_labels:
- __meta_kubernetes_pod_node_name
target_label: NodeName
- job_name: kubernetes-service-endpoints
sample_limit: 10000
kubernetes_sd_configs:
Expand Down Expand Up @@ -341,7 +339,6 @@ data:
replacement: "$1"
- regex: proxy
action: labeldrop
- job_name: 'kubernetes-pod-jmx'
sample_limit: 10000
metrics_path: /metrics
Expand Down Expand Up @@ -380,7 +377,6 @@ data:
- source_labels: [__name__]
regex: 'jvm_gc_collection_seconds.*'
action: drop
kind: ConfigMap
metadata:
name: prometheus-config
Expand All @@ -402,16 +398,16 @@ metadata:
rules:
- apiGroups: [""]
resources:
- nodes
- nodes/proxy
- services
- endpoints
- pods
- nodes
- nodes/proxy
- services
- endpoints
- pods
verbs: ["get", "list", "watch"]
- apiGroups:
- extensions
- extensions
resources:
- ingresses
- ingresses
verbs: ["get", "list", "watch"]
- nonResourceURLs: ["/metrics"]
verbs: ["get"]
Expand Down Expand Up @@ -461,7 +457,7 @@ spec:
# Please don't change below envs
env:
- name: CI_VERSION
value: "k8s/1.2.4"
value: "k8s/1.3.9"
# Please don't change the mountPath
volumeMounts:
- name: prometheus-cwagentconfig
Expand All @@ -477,4 +473,4 @@ spec:
configMap:
name: prometheus-config
terminationGracePeriodSeconds: 60
serviceAccountName: cwagent-prometheus
serviceAccountName: cwagent-prometheus
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ spec:
containers:
- name: cloudwatch-agent
image: amazon/cloudwatch-agent:1.230621.0
imagePullPolicy: Always
#ports:
# - containerPort: 8125
# hostPort: 8125
Expand Down Expand Up @@ -56,6 +57,9 @@ spec:
- name: varlibdocker
mountPath: /var/lib/docker
readOnly: true
- name: containerdsock
mountPath: /run/containerd/containerd.sock
readOnly: true
- name: sys
mountPath: /sys
readOnly: true
Expand All @@ -75,6 +79,9 @@ spec:
- name: varlibdocker
hostPath:
path: /var/lib/docker
- name: containerdsock
hostPath:
path: /run/containerd/containerd.sock
- name: sys
hostPath:
path: /sys
Expand Down
24 changes: 12 additions & 12 deletions cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/aws/amazon-cloudwatch-agent/logs"
"github.com/aws/amazon-cloudwatch-agent/profiler"

lumberjack "github.com/aws/amazon-cloudwatch-agent/logger"
_ "github.com/aws/amazon-cloudwatch-agent/plugins"
"github.com/influxdata/telegraf/agent"
"github.com/influxdata/telegraf/config"
Expand All @@ -47,6 +46,7 @@ import (

const (
defaultEnvCfgFileName = "env-config.json"
LogTargetEventLog = "eventlog"
)

var fDebug = flag.Bool("debug", false,
Expand Down Expand Up @@ -273,14 +273,14 @@ func runAgent(ctx context.Context,
return errors.New("Error: no inputs found, did you provide a valid config file?")
}

if int64(c.Agent.Interval.Duration) <= 0 {
return fmt.Errorf("Agent interval must be positive, found %s",
c.Agent.Interval.Duration)
if int64(c.Agent.Interval) <= 0 {
return fmt.Errorf("Agent interval must be positive, found %v",
c.Agent.Interval)
}

if int64(c.Agent.FlushInterval.Duration) <= 0 {
return fmt.Errorf("Agent flush_interval must be positive; found %s",
c.Agent.Interval.Duration)
if int64(c.Agent.FlushInterval) <= 0 {
return fmt.Errorf("Agent flush_interval must be positive; found %v",
c.Agent.FlushInterval)
}

if *fSchemaTest {
Expand All @@ -304,6 +304,7 @@ func runAgent(ctx context.Context,
RotationInterval: ag.Config.Agent.LogfileRotationInterval,
RotationMaxSize: ag.Config.Agent.LogfileRotationMaxSize,
RotationMaxArchives: ag.Config.Agent.LogfileRotationMaxArchives,
LogWithTimezone: "",
}

logger.SetupLogging(logConfig)
Expand Down Expand Up @@ -548,11 +549,10 @@ func main() {
}
os.Exit(0)
} else {
winlogger, err := s.Logger(nil)
if err == nil {
//When in service mode, register eventlog target and setup default logging to eventlog
logger.RegisterEventLogger(winlogger)
logger.SetupLogging(logger.LogConfig{LogTarget: lumberjack.LogTargetLumberjack})
// When in service mode, register eventlog target and setup default logging to eventlog
e := RegisterEventLogger()
if e != nil {
log.Println("E! Cannot register event log " + e.Error())
}
err = s.Run()

Expand Down
17 changes: 17 additions & 0 deletions cmd/amazon-cloudwatch-agent/register_event_logger_notwindows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

//go:build !windows
// +build !windows

package main

// RegisterEventLogger is for supporting Windows Event, it should only be created when running on Windows
// To minimize duplicate code for Windows vs non-Windows build amazon-cloudwatch-agent.go main class,
// create this dummy method so amazon-cloudwatch-agent.go can be build independent to the OS. Because of this method is
// invoked inside the if statement of "if runtime.GOOS == "windows" && windowsRunAsService() {" effectively it
// is unreachable, but Go compiler needs to see this exits to build.
func RegisterEventLogger() error {
// Unreachable code, do nothing.
return nil
}
24 changes: 24 additions & 0 deletions cmd/amazon-cloudwatch-agent/register_event_logger_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

//go:build windows
// +build windows

package main

import (
lumberjack "github.com/aws/amazon-cloudwatch-agent/logger"
"github.com/influxdata/telegraf/logger"
)

// RegisterEventLogger is for supporting Windows Event
func RegisterEventLogger() error {
// When in service mode, register eventlog target and setup default logging to eventlog

e := logger.RegisterEventLogger(LogTargetEventLog)
if e != nil {
return e
}
logger.SetupLogging(logger.LogConfig{LogTarget: lumberjack.LogTargetLumberjack})
return nil
}
22 changes: 22 additions & 0 deletions cmd/start-amazon-cloudwatch-agent/start-amazon-cloudwatch-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main

import (
"io"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -92,8 +93,29 @@ func main() {
log.Fatalf("E! Cannot translate JSON config into TOML, ERROR is %v \n", err)
}
log.Printf("I! Config has been translated into TOML %s \n", tomlConfigPath)
printFileContents(tomlConfigPath)

if err := startAgent(writer); err != nil {
log.Printf("E! Error when starting Agent, Error is %v \n", err)
os.Exit(1)
}
}

func printFileContents(path string) {
file, err := os.Open(path)
if err != nil {
log.Printf("E! Error when printing file(%s) contents, Error is %v \n", path, err)
os.Exit(1)
}
defer func() {
if err = file.Close(); err != nil {
log.Printf("E! Error when closing file, Error is %v \n", err)
}
}()

b, err := ioutil.ReadAll(file)
if err != nil {
log.Printf("E! Error when reading file(%s), Error is %v \n", path, err)
}
log.Printf("D! toml config %v", string(b))
}
Loading

0 comments on commit 5335531

Please sign in to comment.