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

Please ignore #4952

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e51a7b0
Added k8s components to otel distribution
michalpristas Jun 11, 2024
3340f71
moved receiver to receivers
michalpristas Jun 11, 2024
4ca8b91
added k8sclusterreceiver
michalpristas Jun 12, 2024
d2c44b0
Merge branch 'main' into otel/added-k8s-comps
michalpristas Jun 12, 2024
783b625
Merge branch 'main' into otel/added-k8s-comps
michalpristas Jun 13, 2024
311f38f
added hostmetricsreceiver and resourcedetectionprocessor
michalpristas Jun 13, 2024
628555d
Merge branch 'otel/added-k8s-comps' of github.com:michalpristas/elast…
michalpristas Jun 13, 2024
90714ec
Merge branch 'main' into otel/added-k8s-comps
michalpristas Jun 13, 2024
8452072
Merge branch 'main' into otel/added-k8s-comps
michalpristas Jun 17, 2024
a923f16
resolved conflicts
michalpristas Jun 17, 2024
8524701
Merge branch 'otel/added-k8s-comps' of github.com:michalpristas/elast…
michalpristas Jun 17, 2024
ed871a4
Update rules.json
michalpristas Jun 17, 2024
6f58e33
dup entry in register
michalpristas Jun 17, 2024
9cabb70
Merge branch 'otel/added-k8s-comps' of github.com:michalpristas/elast…
michalpristas Jun 17, 2024
0a78a20
Merge branch 'main' of github.com:elastic/elastic-agent into otel/add…
michalpristas Jun 18, 2024
ff6304b
asap
michalpristas Jun 19, 2024
e8d032b
fun
michalpristas Jun 20, 2024
bd3a43c
fun
michalpristas Jun 20, 2024
6199c54
fun
michalpristas Jun 20, 2024
25a64ec
fun
michalpristas Jun 20, 2024
bb9d2bd
more fun
michalpristas Jun 20, 2024
1589102
conflicts
michalpristas Jun 20, 2024
a0e1f79
conflicts
michalpristas Jun 20, 2024
e4162dc
logs
michalpristas Jun 20, 2024
39d5595
logsush
michalpristas Jun 20, 2024
c909c7d
logsush
michalpristas Jun 20, 2024
9de1ebf
logsush
michalpristas Jun 20, 2024
773c7b3
logsush
michalpristas Jun 20, 2024
844bac0
logsush
michalpristas Jun 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ linters-settings:
- github.com/dop251/goja_nodejs
- github.com/fsnotify/fsnotify
- github.com/tonistiigi/fifo
- github.com/leoluk/perflib_exporter/perflib

gosimple:
# Select the Go version to target. The default is '1.13'.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ replace (
github.com/Shopify/sarama => github.com/elastic/sarama v1.19.1-0.20220310193331-ebc2b0d8eef3
github.com/dop251/goja => github.com/andrewkroh/goja v0.0.0-20190128172624-dd2ac4456e20
github.com/dop251/goja_nodejs => github.com/dop251/goja_nodejs v0.0.0-20171011081505-adff31b136e6
github.com/leoluk/perflib_exporter/perflib => github.com/prometheus-community/windows_exporter/pkg/perflib v0.25.1
github.com/tonistiigi/fifo => github.com/containerd/fifo v0.0.0-20190816180239-bda0ff6ed73c
)

Expand Down
36 changes: 36 additions & 0 deletions internal/pkg/agent/appinit/appinit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package appinit

import (
"os"
"sync"

"github.com/elastic/elastic-agent-libs/service"
)

var stopSvcChan = make(chan bool)
var once sync.Once
var stopBeat = func() {
close(stopSvcChan)
}

func init() {
if len(os.Args) > 1 && os.Args[1] == "run" {
once.Do(func() {
var wg sync.WaitGroup
wg.Add(1)
go func() {
wg.Done()
service.ProcessWindowsControlEvents(stopBeat)
}()
wg.Wait()
})
}
}

func StopSvcChan() chan bool {
return stopSvcChan
}
2 changes: 0 additions & 2 deletions internal/pkg/agent/cmd/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package cmd

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/pkg/agent/cmd/otel_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package cmd

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/pkg/agent/cmd/otel_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package cmd

import (
Expand Down
17 changes: 0 additions & 17 deletions internal/pkg/agent/cmd/otel_windows.go

This file was deleted.

17 changes: 0 additions & 17 deletions internal/pkg/agent/cmd/otel_windows_test.go

This file was deleted.

23 changes: 9 additions & 14 deletions internal/pkg/agent/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/elastic/elastic-agent-system-metrics/report"
"github.com/elastic/elastic-agent/internal/pkg/agent/vault"

"github.com/elastic/elastic-agent/internal/pkg/agent/appinit"
"github.com/elastic/elastic-agent/internal/pkg/agent/application"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/filelock"
Expand Down Expand Up @@ -117,6 +118,13 @@ func run(override cfgOverrider, testingMode bool, fleetInitTimeout time.Duration
service.WaitExecutionDone()
}()

service.BeforeRun()
defer service.Cleanup()

// register as a service
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

if err := handleUpgrade(); err != nil {
return fmt.Errorf("error checking for and handling upgrade: %w", err)
}
Expand All @@ -129,20 +137,7 @@ func run(override cfgOverrider, testingMode bool, fleetInitTimeout time.Duration
_ = locker.Unlock()
}()

service.BeforeRun()
defer service.Cleanup()

// register as a service
stop := make(chan bool)
ctx, cancel := context.WithCancel(context.Background())
stopBeat := func() {
close(stop)
}

defer cancel()
go service.ProcessWindowsControlEvents(stopBeat)

return runElasticAgent(ctx, cancel, override, stop, testingMode, fleetInitTimeout, false, nil, modifiers...)
return runElasticAgent(ctx, cancel, override, appinit.StopSvcChan(), testingMode, fleetInitTimeout, false, nil, modifiers...)
}

func logReturn(l *logger.Logger, err error) error {
Expand Down
2 changes: 0 additions & 2 deletions internal/pkg/agent/cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package cmd

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/pkg/agent/cmd/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package cmd

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/pkg/otel/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package otel

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/pkg/otel/config_file_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package otel

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/pkg/otel/config_file_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package otel

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/pkg/otel/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package otel

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/pkg/otel/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package otel

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/pkg/otel/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package otel

import (
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"os"
"time"

_ "github.com/elastic/elastic-agent/internal/pkg/agent/appinit"
"github.com/elastic/elastic-agent/internal/pkg/agent/cmd"
"github.com/elastic/elastic-agent/pkg/core/process"
)
Expand All @@ -36,7 +37,7 @@
}
defer pj.Close()

rand.Seed(time.Now().UnixNano())

Check failure on line 40 in main.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator. (staticcheck)
command := cmd.NewCommand()
err = command.Execute()
if err != nil {
Expand Down
17 changes: 15 additions & 2 deletions pkg/testing/fixture_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (f *Fixture) installNoPkgManager(ctx context.Context, installOpts *InstallO
installArgs = append(installArgs, installOptsArgs...)
out, err := f.Exec(ctx, installArgs, opts...)
if err != nil {
return out, fmt.Errorf("error running agent install command: %w", err)
return out, fmt.Errorf("error running agent install command: %w with output: %s", err, string(out))
}

f.installed = true
Expand Down Expand Up @@ -245,6 +245,19 @@ func (f *Fixture) installNoPkgManager(ctx context.Context, installOpts *InstallO
if err != nil {
f.t.Logf("error serializing processes: %s", err)
}

if runtime.GOOS == "windows" {
filePath := filepath.Join(dir, "build", "diagnostics", fmt.Sprintf("TEST-%s-%s-%s-EventLogs.json", sanitizedTestName, f.operatingSystem, f.architecture))
psCommand := `Get-EventLog -LogName Application -EntryType Error -Newest 1000`
out, err := exec.Command("powershell", "-NoProfile", psCommand).CombinedOutput()
if err != nil {
f.t.Logf("error executing command: %s with output %s", err, string(out))
} else {
if err := os.WriteFile(filePath, out, 0666); err != nil {
f.t.Logf("error wrting file %s: %s", filePath, err)
}
}
}
}
})

Expand Down Expand Up @@ -603,7 +616,7 @@ func (f *Fixture) uninstallNoPkgManager(ctx context.Context, uninstallOpts *Unin
}
out, err := f.Exec(ctx, uninstallArgs, opts...)
if err != nil {
return out, fmt.Errorf("error running uninstall command: %w", err)
return out, fmt.Errorf("error running uninstall command: %w with output: %s", err, string(out))
}
f.installed = false

Expand Down
Loading