mirror of
https://github.com/prometheus/prometheus.git
synced 2026-04-22 14:52:43 -04:00
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Compliance testing (push) Waiting to run
CI / Build Prometheus for common architectures (push) Waiting to run
CI / Build Prometheus for all architectures (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
[hcloud.Server.Datacenter] is deprecated and will be removed after 1 July 2026. Use [hcloud.Server.Location] instead. See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters Changes to Hetzner meta labels: - `__meta_hetzner_datacenter` - is deprecated for the role `robot` but kept for backward compatibility. Using `__meta_hetzner_robot_datacenter` is preferred. - is deprecated for the role `hcloud` and will stop working after the 1 July 2026. - `__meta_hetzner_hcloud_datacenter_location` label - is deprecated but kept for backward compatibility, the same data is available in the [`hcloud.Server.Location`](https://pkg.go.dev/github.com/hetznercloud/hcloud-go/v2/hcloud#Server) struct. - using `__meta_hetzner_hcloud_location` is preferred. - `__meta_hetzner_hcloud_datacenter_location_network_zone` - is deprecated but kept for backward compatibility, the same data is available in the [`hcloud.Server.Location`](https://pkg.go.dev/github.com/hetznercloud/hcloud-go/v2/hcloud#Server) struct. - using `__meta_hetzner_hcloud_location_network_zone` is preferred. - `__meta_hetzner_hcloud_location` - replacement label for `__meta_hetzner_hcloud_datacenter_location` - `__meta_hetzner_hcloud_location_network_zone` - replacement label for `__meta_hetzner_hcloud_datacenter_location_network_zone` - `__meta_hetzner_robot_datacenter` - replacement label for `__meta_hetzner_datacenter` with the role `robot`. Signed-off-by: Jonas Lammler <jonas.lammler@hetzner-cloud.de>
103 lines
3.7 KiB
Go
103 lines
3.7 KiB
Go
// Copyright The Prometheus Authors
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package hetzner
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/prometheus/common/config"
|
|
"github.com/prometheus/common/model"
|
|
"github.com/prometheus/common/promslog"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type robotSDTestSuite struct {
|
|
Mock *SDMock
|
|
}
|
|
|
|
func (s *robotSDTestSuite) SetupTest(t *testing.T) {
|
|
s.Mock = NewSDMock(t)
|
|
s.Mock.Setup()
|
|
|
|
s.Mock.HandleRobotServers()
|
|
}
|
|
|
|
func TestRobotSDRefresh(t *testing.T) {
|
|
suite := &robotSDTestSuite{}
|
|
suite.SetupTest(t)
|
|
cfg := DefaultSDConfig
|
|
cfg.HTTPClientConfig.BasicAuth = &config.BasicAuth{Username: robotTestUsername, Password: robotTestPassword}
|
|
cfg.robotEndpoint = suite.Mock.Endpoint()
|
|
|
|
d, err := newRobotDiscovery(&cfg, promslog.NewNopLogger())
|
|
require.NoError(t, err)
|
|
|
|
targetGroups, err := d.refresh(context.Background())
|
|
require.NoError(t, err)
|
|
require.Len(t, targetGroups, 1)
|
|
|
|
targetGroup := targetGroups[0]
|
|
require.NotNil(t, targetGroup, "targetGroup should not be nil")
|
|
require.NotNil(t, targetGroup.Targets, "targetGroup.targets should not be nil")
|
|
require.Len(t, targetGroup.Targets, 2)
|
|
|
|
for i, labelSet := range []model.LabelSet{
|
|
{
|
|
"__address__": model.LabelValue("123.123.123.123:80"),
|
|
"__meta_hetzner_role": model.LabelValue("robot"),
|
|
"__meta_hetzner_server_id": model.LabelValue("321"),
|
|
"__meta_hetzner_server_name": model.LabelValue("server1"),
|
|
"__meta_hetzner_server_status": model.LabelValue("ready"),
|
|
"__meta_hetzner_public_ipv4": model.LabelValue("123.123.123.123"),
|
|
"__meta_hetzner_public_ipv6_network": model.LabelValue("2a01:4f8:111:4221::/64"),
|
|
"__meta_hetzner_datacenter": model.LabelValue("nbg1-dc1"),
|
|
"__meta_hetzner_robot_datacenter": model.LabelValue("nbg1-dc1"),
|
|
"__meta_hetzner_robot_product": model.LabelValue("DS 3000"),
|
|
"__meta_hetzner_robot_cancelled": model.LabelValue("false"),
|
|
},
|
|
{
|
|
"__address__": model.LabelValue("123.123.123.124:80"),
|
|
"__meta_hetzner_role": model.LabelValue("robot"),
|
|
"__meta_hetzner_server_id": model.LabelValue("421"),
|
|
"__meta_hetzner_server_name": model.LabelValue("server2"),
|
|
"__meta_hetzner_server_status": model.LabelValue("in process"),
|
|
"__meta_hetzner_public_ipv4": model.LabelValue("123.123.123.124"),
|
|
"__meta_hetzner_datacenter": model.LabelValue("fsn1-dc10"),
|
|
"__meta_hetzner_robot_datacenter": model.LabelValue("fsn1-dc10"),
|
|
"__meta_hetzner_robot_product": model.LabelValue("X5"),
|
|
"__meta_hetzner_robot_cancelled": model.LabelValue("true"),
|
|
},
|
|
} {
|
|
t.Run(fmt.Sprintf("item %d", i), func(t *testing.T) {
|
|
require.Equal(t, labelSet, targetGroup.Targets[i])
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRobotSDRefreshHandleError(t *testing.T) {
|
|
suite := &robotSDTestSuite{}
|
|
suite.SetupTest(t)
|
|
cfg := DefaultSDConfig
|
|
cfg.robotEndpoint = suite.Mock.Endpoint()
|
|
|
|
d, err := newRobotDiscovery(&cfg, promslog.NewNopLogger())
|
|
require.NoError(t, err)
|
|
|
|
targetGroups, err := d.refresh(context.Background())
|
|
require.EqualError(t, err, "non 2xx status '401' response during hetzner service discovery with role robot")
|
|
|
|
require.Empty(t, targetGroups)
|
|
}
|