mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-22 16:36:27 +01:00
10063e98a6
### Describe Your Changes
related issue:
https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6041
#### Added
- Added service discovery support for Vultr.
#### Docs
- `CHANGELOG.md`, `sd_configs.md`, `vmagent.md` are updated.
#### Note
- Useful links:
- Vultr API:
https://www.vultr.com/api/#tag/instances/operation/list-instances
- Vultr client SDK: https://github.com/vultr/govultr
- Prometheus SD:
https://github.com/prometheus/prometheus/tree/main/discovery/vultr
---
### Checklist
The following checks are mandatory:
- [X] I have read the [Contributing
Guidelines](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/CONTRIBUTING.md)
- [x] All commits are signed and include `Signed-off-by` line. Use `git
commit -s` to include `Signed-off-by` your commits. See this
[doc](https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work) about
how to sign your commits.
- [x] Tests are passing locally. Use `make test` to run all tests
locally.
- [x] Linting is passing locally. Use `make check-all` to run all
linters locally.
Further checks are optional for External Contributions:
- [X] Include a link to the GitHub issue in the commit message, if issue
exists.
- [x] Mention the change in the
[Changelog](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/docs/CHANGELOG.md).
Explain what has changed and why. If there is a related issue or
documentation change - link them as well.
Tips for writing a good changelog message::
* Write a human-readable changelog message that describes the problem
and solution.
* Include a link to the issue or pull request in your changelog message.
* Use specific language identifying the fix, such as an error message,
metric name, or flag name.
* Provide a link to the relevant documentation for any new features you
add or modify.
- [ ] After your pull request is merged, please add a message to the
issue with instructions for how to test the fix or try the feature you
added. Here is an
[example](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4048#issuecomment-1546453726)
- [x] Do not close the original issue before the change is released.
Please note, in some cases Github can automatically close the issue once
PR is merged. Re-open the issue in such case.
- [x] If the change somehow affects public interfaces (a new flag was
added or updated, or some behavior has changed) - add the corresponding
change to documentation.
Signed-off-by: Jiekun <jiekun.dev@gmail.com>
(cherry picked from commit 17e3d019d2
)
97 lines
3.9 KiB
Go
97 lines
3.9 KiB
Go
package vultr
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
|
|
)
|
|
|
|
func TestGetInstanceLabels(t *testing.T) {
|
|
input := []Instance{
|
|
{
|
|
ID: "fake-id-07f7-4b68-88ac-fake-id",
|
|
Os: "Ubuntu 22.04 x64",
|
|
RAM: 1024,
|
|
Disk: 25,
|
|
MainIP: "64.176.84.27",
|
|
VCPUCount: 1,
|
|
Region: "sgp",
|
|
Plan: "vc2-1c-1gb",
|
|
AllowedBandwidth: 1,
|
|
ServerStatus: "installingbooting",
|
|
V6MainIP: "2002:18f0:4100:263a:5300:07ff:fdd7:691c",
|
|
Label: "vultr-sd",
|
|
InternalIP: "",
|
|
Hostname: "vultr-sd",
|
|
Tags: []string{"mock tags"},
|
|
OsID: 1743,
|
|
Features: []string{"ipv6"},
|
|
},
|
|
{
|
|
ID: "fake-id-07f7-4b68-88ac-fake-id",
|
|
Os: "Ubuntu 22.04 x64",
|
|
RAM: 1024,
|
|
Disk: 25,
|
|
MainIP: "64.176.84.27",
|
|
VCPUCount: 1,
|
|
Region: "sgp",
|
|
Plan: "vc2-1c-1gb",
|
|
AllowedBandwidth: 1,
|
|
ServerStatus: "installingbooting",
|
|
V6MainIP: "2002:18f0:4100:263a:5300:07ff:fdd7:691c",
|
|
Label: "vultr-sd",
|
|
InternalIP: "",
|
|
Hostname: "vultr-sd",
|
|
Tags: []string{"mock tags"},
|
|
OsID: 1743,
|
|
Features: []string{"ipv6"},
|
|
},
|
|
}
|
|
|
|
expect := []*promutils.Labels{
|
|
promutils.NewLabelsFromMap(map[string]string{
|
|
"__address__": "64.176.84.27:8080",
|
|
"__meta_vultr_instance_id": "fake-id-07f7-4b68-88ac-fake-id",
|
|
"__meta_vultr_instance_label": "vultr-sd",
|
|
"__meta_vultr_instance_os": "Ubuntu 22.04 x64",
|
|
"__meta_vultr_instance_os_id": "1743",
|
|
"__meta_vultr_instance_region": "sgp",
|
|
"__meta_vultr_instance_plan": "vc2-1c-1gb",
|
|
"__meta_vultr_instance_main_ip": "64.176.84.27",
|
|
"__meta_vultr_instance_internal_ip": "",
|
|
"__meta_vultr_instance_main_ipv6": "2002:18f0:4100:263a:5300:07ff:fdd7:691c",
|
|
"__meta_vultr_instance_hostname": "vultr-sd",
|
|
"__meta_vultr_instance_server_status": "installingbooting",
|
|
"__meta_vultr_instance_vcpu_count": "1",
|
|
"__meta_vultr_instance_ram_mb": "1024",
|
|
"__meta_vultr_instance_allowed_bandwidth_gb": "1",
|
|
"__meta_vultr_instance_disk_gb": "25",
|
|
"__meta_vultr_instance_features": ",ipv6,",
|
|
"__meta_vultr_instance_tags": ",mock tags,",
|
|
}),
|
|
promutils.NewLabelsFromMap(map[string]string{
|
|
"__address__": "64.176.84.27:8080",
|
|
"__meta_vultr_instance_id": "fake-id-07f7-4b68-88ac-fake-id",
|
|
"__meta_vultr_instance_label": "vultr-sd",
|
|
"__meta_vultr_instance_os": "Ubuntu 22.04 x64",
|
|
"__meta_vultr_instance_os_id": "1743",
|
|
"__meta_vultr_instance_region": "sgp",
|
|
"__meta_vultr_instance_plan": "vc2-1c-1gb",
|
|
"__meta_vultr_instance_main_ip": "64.176.84.27",
|
|
"__meta_vultr_instance_internal_ip": "",
|
|
"__meta_vultr_instance_main_ipv6": "2002:18f0:4100:263a:5300:07ff:fdd7:691c",
|
|
"__meta_vultr_instance_hostname": "vultr-sd",
|
|
"__meta_vultr_instance_server_status": "installingbooting",
|
|
"__meta_vultr_instance_vcpu_count": "1",
|
|
"__meta_vultr_instance_ram_mb": "1024",
|
|
"__meta_vultr_instance_allowed_bandwidth_gb": "1",
|
|
"__meta_vultr_instance_disk_gb": "25",
|
|
"__meta_vultr_instance_features": ",ipv6,",
|
|
"__meta_vultr_instance_tags": ",mock tags,",
|
|
}),
|
|
}
|
|
labels := getInstanceLabels(input, 8080)
|
|
discoveryutils.TestEqualLabelss(t, labels, expect)
|
|
}
|