Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
83a687e
Update Prometheus library
ishleenk17 Mar 27, 2025
e499dd4
Update NOTICE
ishleenk17 Mar 27, 2025
3bdf1ad
Update the default contenttype in testdata
ishleenk17 Mar 28, 2025
fc2a8d4
Merge branch 'main' into prometheus_300
ishleenk17 Mar 28, 2025
cce6949
Resolve linter errors
ishleenk17 Mar 28, 2025
cfee5cf
Resolve linter errors
ishleenk17 Mar 28, 2025
5744592
lint error
ishleenk17 Mar 28, 2025
3f2f58b
Merge branch 'main' into prometheus_300
ishleenk17 Mar 28, 2025
a4f1598
Merge branch 'main' into prometheus_300
ishleenk17 Apr 1, 2025
48b855a
Merge branch 'main' into prometheus_300
ishleenk17 Apr 2, 2025
01e8d40
adding files for remotewrite prom3
gizas Apr 10, 2025
3c52e6e
adding files for remotewrite prom3
gizas Apr 10, 2025
2a636b7
Add comment
ishleenk17 Apr 15, 2025
0f18909
Merge branch 'main' into prometheus_300
ishleenk17 Apr 15, 2025
4e39893
Update go mod
ishleenk17 Apr 15, 2025
bfff7f7
Add default port in URL parsing
ishleenk17 Apr 17, 2025
0f091d7
Add URL tests
ishleenk17 Apr 17, 2025
81ef7a7
Merge branch 'main' into prometheus_300
ishleenk17 Apr 17, 2025
2883239
Resolve linter errors
ishleenk17 Apr 17, 2025
4a46b72
Update TestNewLeaderElectionManager flaky test
MichaelKatsoulis Apr 17, 2025
48ff87e
Merge branch 'main' into prometheus_300
ishleenk17 Apr 18, 2025
81a455f
Fix linter errors
MichaelKatsoulis Apr 18, 2025
c7cd6dd
Merge branch 'main' into prometheus_300
ishleenk17 Apr 18, 2025
80cd63f
Update metricbeat/mb/parse/url.go
ishleenk17 Apr 22, 2025
8a640af
Update url.go
ishleenk17 Apr 22, 2025
82ccb59
update err
ishleenk17 Apr 22, 2025
1ed7470
CI error
ishleenk17 Apr 22, 2025
1b495d1
log update
ishleenk17 Apr 22, 2025
484eac9
Merge branch 'main' into prometheus_300
ishleenk17 Apr 22, 2025
792352a
upfdate defaultPort
ishleenk17 Apr 22, 2025
bcc51fc
update changelog
ishleenk17 Apr 22, 2025
9df88e1
Update metricbeat/helper/prometheus/textparse.go
ishleenk17 Apr 22, 2025
03cdce0
Update metricbeat/mb/parse/url.go
ishleenk17 Apr 22, 2025
955566c
Merge branch 'main' into prometheus_300
ishleenk17 Apr 22, 2025
9e18795
Merge branch 'main' into prometheus_300
ishleenk17 Apr 23, 2025
597ad68
Merge branch 'main' into prometheus_300
ishleenk17 Apr 23, 2025
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 CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ otherwise no tag is added. {issue}42208[42208] {pull}42403[42403]
- Changed the Elasticsearch module behavior to only pull settings from non-system indices. {pull}43243[43243]
- Exclude dotted indices from settings pull in Elasticsearch module. {pull}43306[43306]
- Updated Meraki API endpoint for Channel Utilization data. Switched to `GetOrganizationWirelessDevicesChannelUtilizationByDevice`. {pull}43485[43485]
- Upgrade Prometheus Library to v0.300.1. {pull}43540[43540]

*Metricbeat*

Expand Down
1,123 changes: 1,051 additions & 72 deletions NOTICE.txt

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ require (
github.com/lib/pq v1.10.3
github.com/magefile/mage v1.15.0
github.com/mattn/go-colorable v0.1.13
github.com/miekg/dns v1.1.61
github.com/miekg/dns v1.1.62
github.com/mitchellh/gox v1.0.1
github.com/mitchellh/hashstructure v1.1.0
github.com/mitchellh/mapstructure v1.5.0
Expand Down Expand Up @@ -133,7 +133,7 @@ require (
golang.org/x/sys v0.31.0
golang.org/x/text v0.23.0
golang.org/x/time v0.8.0
golang.org/x/tools v0.25.0
golang.org/x/tools v0.26.0
google.golang.org/api v0.214.0
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/grpc v1.71.0
Expand All @@ -142,9 +142,9 @@ require (
gopkg.in/yaml.v2 v2.4.0
gotest.tools/gotestsum v1.7.0
howett.net/plist v1.0.1
k8s.io/api v0.29.5
k8s.io/apimachinery v0.29.5
k8s.io/client-go v0.29.5
k8s.io/api v0.31.1
k8s.io/apimachinery v0.31.1
k8s.io/client-go v0.31.1
kernel.org/pub/linux/libs/security/libcap/cap v1.2.57
)

Expand Down Expand Up @@ -207,7 +207,7 @@ require (
github.com/otiai10/copy v1.12.0
github.com/pierrec/lz4/v4 v4.1.22
github.com/pkg/xattr v0.4.9
github.com/prometheus/prometheus v0.54.1
github.com/prometheus/prometheus v0.300.1
github.com/shirou/gopsutil/v4 v4.25.1
github.com/teambition/rrule-go v1.8.2
github.com/tklauser/go-sysconf v0.3.12
Expand Down Expand Up @@ -301,9 +301,9 @@ require (
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/fearful-symmetry/gomsr v0.0.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.5 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
Expand Down Expand Up @@ -367,7 +367,7 @@ require (
github.com/mitchellh/iochan v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/spdystream v0.4.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand All @@ -390,6 +390,7 @@ require (
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
Expand Down Expand Up @@ -470,14 +471,15 @@ require (
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
gonum.org/v1/gonum v0.15.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
kernel.org/pub/linux/libs/security/libcap/psx v1.2.57 // indirect
mvdan.cc/garble v0.12.1 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

require (
Expand Down
61 changes: 36 additions & 25 deletions go.sum

Large diffs are not rendered by default.

66 changes: 26 additions & 40 deletions libbeat/autodiscover/providers/kubernetes/kubernetes_test.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this file are not really related to this PR, are they? Would it make sense to extract them into a separate PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes are done as when Prometheus library is upgrade, it alos upgrade k8s.io indirectly that leads to flaky test runs. Hence added here.

Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,8 @@ func createLease() *v1.Lease {
}

// applyLease applies the lease
func applyLease(client kubernetes.Interface, lease *v1.Lease, firstTime bool) error {
var err error
if firstTime {
_, err = client.CoordinationV1().Leases(namespace).Create(context.Background(), lease, metav1.CreateOptions{})
return err
}
_, err = client.CoordinationV1().Leases(namespace).Update(context.Background(), lease, metav1.UpdateOptions{})
func applyLease(client kubernetes.Interface, lease *v1.Lease) error {
_, err := client.CoordinationV1().Leases(namespace).Create(context.Background(), lease, metav1.CreateOptions{})
return err
}

Expand Down Expand Up @@ -85,9 +80,10 @@ func TestLeaseConfigurableFields(t *testing.T) {
le, err := NewLeaderElectionManager(uuid, &cfg, client, startLeadingFunc, stopLeadingFunc, logger)
require.NoError(t, err)

leaseDuration = le.(*leaderElectionManager).leaderElection.LeaseDuration
retryPeriod = le.(*leaderElectionManager).leaderElection.RetryPeriod
renewDeadline = le.(*leaderElectionManager).leaderElection.RenewDeadline
lem, _ := le.(*leaderElectionManager)
leaseDuration = lem.leaderElection.LeaseDuration
retryPeriod = lem.leaderElection.RetryPeriod
renewDeadline = lem.leaderElection.RenewDeadline

require.Equalf(t, cfg.LeaseDuration, leaseDuration, "lease duration should be the same as the one provided in the configuration.")
require.Equalf(t, cfg.RetryPeriod, retryPeriod, "retry period should be the same as the one provided in the configuration.")
Expand All @@ -104,20 +100,20 @@ func TestNewLeaderElectionManager(t *testing.T) {

lease := createLease()
// create the lease that leader election will be using
err := applyLease(client, lease, true)
err := applyLease(client, lease)
require.NoError(t, err)

uuid, err := uuid.NewV4()
require.NoError(t, err)

waitForNewLeader := make(chan string)
waitForLosingLeader := make(chan string)
var loosingLeader = ""

startLeadingFunc := func(uuid string, eventID string) {
waitForNewLeader <- eventID
}
stopLeadingFunc := func(uuid string, eventID string) {
waitForLosingLeader <- eventID
loosingLeader = eventID
}
logger := logp.NewLogger("kubernetes-test")

Expand All @@ -141,15 +137,17 @@ func TestNewLeaderElectionManager(t *testing.T) {

le, err := NewLeaderElectionManager(uuid, &cfg, client, startLeadingFunc, stopLeadingFunc, logger)
require.NoError(t, err)

leaseDuration = le.(*leaderElectionManager).leaderElection.LeaseDuration
retryPeriod = le.(*leaderElectionManager).leaderElection.RetryPeriod
lem, _ := le.(*leaderElectionManager)
leaseDuration = lem.leaderElection.LeaseDuration
retryPeriod = lem.leaderElection.RetryPeriod

les[i] = &le
}

for _, le := range les {
(*le).Start()
// Start leader election managers with some delay so the first always becomes the first leader
time.Sleep(500 * time.Millisecond)
}

// It is possible that startLeading is triggered more than one time before stopLeading is called.
Expand All @@ -169,14 +167,13 @@ func TestNewLeaderElectionManager(t *testing.T) {
if exists {
t.Fatalf("The new leader produced the same event id as the previous one.")
}
expectedLoosingEventIds[eventId] = true

// wait for loosing leader
loosingEventId := <-waitForLosingLeader
_, exists = expectedLoosingEventIds[loosingEventId]
_, exists = expectedLoosingEventIds[loosingLeader]
if !exists {
t.Fatalf("The loosing leader used an unexpected event id %s.", eventId)
}

expectedLoosingEventIds[eventId] = true
}

go func() {
Expand All @@ -199,38 +196,27 @@ func TestNewLeaderElectionManager(t *testing.T) {
}
}()

renewals := 5
// cause lease renewals
for i := 0; i < renewals; i++ {
// Force the lease to be applied again, so a new leader is elected.
newHolder := "does-not-matter-" + fmt.Sprint(i)
lease.Spec.HolderIdentity = &newHolder
err = applyLease(client, lease, false)
require.NoError(t, err)

// wait some time to ensure lease renewal
<-time.After((retryPeriod + leaseDuration) * 2)
for _, le := range les {
// stop leader
(*le).Stop()
time.Sleep((retryPeriod + leaseDuration) * 2)
// start leader again
// during this time, the leader will have changed
(*le).Start()
}

endedRequests <- 1

<-finished

// Wait for some to ensure we are not having lease fail renewal, and there is no new leader.
<-time.After((retryPeriod + leaseDuration) * 2)
time.Sleep((retryPeriod + leaseDuration) * 2)

// waitForNewLeader channel should be empty, because we removed it just before ending the for cycle.
require.Equalf(t, 0, len(waitForNewLeader), "waitForNewLeader channel should be empty.")

// waitForLosingLeader channel should be empty, because the last leader did not lose the lease lock yet.
require.Equalf(t, 0, len(waitForLosingLeader), "waitForLosingLeader channel should be empty.")

for _, le := range les {
(*le).Stop()
}

// When the context gets cancelled, stopLeading is always called.
// Let's check that the leaders electors are correctly stopping.
for i := 0; i < numberNodes; i++ {
<-waitForLosingLeader
}
}
9 changes: 5 additions & 4 deletions metricbeat/helper/prometheus/textparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func histogramMetricName(name string, s float64, qv string, lbls string, t *int6
}

func ParseMetricFamilies(b []byte, contentType string, ts time.Time, logger *logp.Logger) ([]*MetricFamily, error) {
parser, err := textparse.New(b, contentType, false, labels.NewSymbolTable())
parser, err := textparse.New(b, contentType, ContentTypeTextFormat, false, false, labels.NewSymbolTable()) // Fallback protocol set to ContentTypeTextFormat
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -588,11 +588,12 @@ func ParseMetricFamilies(b []byte, contentType string, ts time.Time, logger *log
continue
}

if l.Name == model.QuantileLabel {
switch l.Name {
case model.QuantileLabel:
qv = lset.Get(model.QuantileLabel)
} else if l.Name == labels.BucketLabel {
case labels.BucketLabel:
qv = lset.Get(labels.BucketLabel)
} else {
default:
lbls.WriteString(l.Name)
lbls.WriteString(l.Value)
}
Expand Down
25 changes: 15 additions & 10 deletions metricbeat/mb/parse/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type URLHostParserBuilder struct {
DefaultUsername string
DefaultPassword string
DefaultScheme string
DefaultPort string
QueryParams string
}

Expand Down Expand Up @@ -104,7 +105,7 @@ func (b URLHostParserBuilder) Build() mb.HostParser {
// Combine paths and normalize
fullPath := strings.Trim(p.Join(basePath, path), "/")

return ParseURL(host, b.DefaultScheme, user, pass, fullPath, b.QueryParams)
return ParseURL(host, b.DefaultScheme, user, pass, fullPath, b.DefaultPort, b.QueryParams)
}
}

Expand All @@ -116,7 +117,7 @@ func NewHostDataFromURL(u *url.URL) mb.HostData {
return NewHostDataFromURLWithTransport(dialer.NewDefaultDialerBuilder(), u)
}

// NewHostDataFromURLWithTransport Allow to specify what kind of transport to in conjonction of the
// NewHostDataFromURLWithTransport allows to specify the type of transport to use in conjunction with the
// url, this is useful if you use a combined scheme like "http+unix://" or "http+npipe".
func NewHostDataFromURLWithTransport(transport dialer.Builder, u *url.URL) mb.HostData {
var user, pass string
Expand All @@ -143,8 +144,8 @@ func NewHostDataFromURLWithTransport(transport dialer.Builder, u *url.URL) mb.Ho
// ParseURL returns HostData object from a raw 'host' value and a series of
// defaults that are added to the URL if not present in the rawHost value.
// Values from the rawHost take precedence over the defaults.
func ParseURL(rawHost, scheme, user, pass, path, query string) (mb.HostData, error) {
u, transport, err := getURL(rawHost, scheme, user, pass, path, query)
func ParseURL(rawHost, scheme, user, pass, path, defaultPort, query string) (mb.HostData, error) {
u, transport, err := getURL(rawHost, scheme, user, pass, path, defaultPort, query)

if err != nil {
return mb.HostData{}, err
Expand Down Expand Up @@ -186,7 +187,7 @@ func SetURLUser(u *url.URL, defaultUser, defaultPass string) {
// getURL constructs a URL from the rawHost value and adds the provided user,
// password, path, and query params if one was not set in the rawURL value.
func getURL(
rawURL, scheme, username, password, path, query string,
rawURL, scheme, username, password, path, defaultPort, query string,
) (*url.URL, dialer.Builder, error) {

if parts := strings.SplitN(rawURL, "://", 2); len(parts) != 2 {
Expand All @@ -198,7 +199,7 @@ func getURL(

u, err := url.Parse(rawURL)
if err != nil {
return nil, t, fmt.Errorf("error parsing URL: %v", err)
return nil, t, fmt.Errorf("error parsing URL: %w", err)
}

// discover the transport to use to communicate with the host if we have a combined scheme.
Expand Down Expand Up @@ -231,7 +232,7 @@ func getURL(
u.Path = "/" + segs[1]
}

p = `\\.\pipe\` + strings.Replace(p, "/", "\\", -1)
p = `\\.\pipe\` + strings.ReplaceAll(p, "/", "\\")
t = dialer.NewNpipeDialerBuilder(p)
default:
t = dialer.NewDefaultDialerBuilder()
Expand All @@ -244,18 +245,22 @@ func getURL(
return nil, t, fmt.Errorf("error parsing URL: empty host")
}

// Validate the host. The port is optional.
host, _, err := net.SplitHostPort(u.Host)
// Validate the host.
host, port, err := net.SplitHostPort(u.Host)
if err != nil {
if strings.Contains(err.Error(), "missing port") {
host = u.Host
} else {
return nil, t, fmt.Errorf("error parsing URL: %v", err)
return nil, t, fmt.Errorf("error parsing URL: %w", err)
}
}
if host == "" {
return nil, t, fmt.Errorf("error parsing URL: empty host")
}
// Add default port to host if port is empty and defaultport is set
if port == "" && defaultPort != "" {
u.Host = net.JoinHostPort(host, defaultPort)
}
}

if u.Path == "" && path != "" {
Expand Down
Loading