Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doodoocoder
prometheus
提交
f708fd5c
P
prometheus
项目概览
doodoocoder
/
prometheus
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
prometheus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f708fd5c
编写于
9月 04, 2018
作者:
T
Tariq Ibrahim
提交者:
Tobias Schmidt
9月 04, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding support for multiple azure environments (#4569)
Signed-off-by:
N
Tariq Ibrahim
<
tariq.ibrahim@microsoft.com
>
上级
40517dc4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
30 addition
and
14 deletion
+30
-14
config/config_test.go
config/config_test.go
+1
-0
config/testdata/conf.good.yml
config/testdata/conf.good.yml
+2
-1
discovery/azure/azure.go
discovery/azure/azure.go
+25
-13
docs/configuration/configuration.md
docs/configuration/configuration.md
+2
-0
未找到文件。
config/config_test.go
浏览文件 @
f708fd5c
...
...
@@ -441,6 +441,7 @@ var expectedConf = &Config{
ServiceDiscoveryConfig
:
sd_config
.
ServiceDiscoveryConfig
{
AzureSDConfigs
:
[]
*
azure
.
SDConfig
{
{
Environment
:
"AzurePublicCloud"
,
SubscriptionID
:
"11AAAA11-A11A-111A-A111-1111A1111A11"
,
TenantID
:
"BBBB222B-B2B2-2B22-B222-2BB2222BB2B2"
,
ClientID
:
"333333CC-3C33-3333-CCC3-33C3CCCCC33C"
,
...
...
config/testdata/conf.good.yml
浏览文件 @
f708fd5c
...
...
@@ -195,7 +195,8 @@ scrape_configs:
-
job_name
:
service-azure
azure_sd_configs
:
-
subscription_id
:
11AAAA11-A11A-111A-A111-1111A1111A11
-
environment
:
AzurePublicCloud
subscription_id
:
11AAAA11-A11A-111A-A111-1111A1111A11
tenant_id
:
BBBB222B-B2B2-2B22-B222-2BB2222BB2B2
client_id
:
333333CC-3C33-3333-CCC3-33C3CCCCC33C
client_secret
:
mysecret
...
...
discovery/azure/azure.go
浏览文件 @
f708fd5c
...
...
@@ -65,11 +65,13 @@ var (
DefaultSDConfig
=
SDConfig
{
Port
:
80
,
RefreshInterval
:
model
.
Duration
(
5
*
time
.
Minute
),
Environment
:
azure
.
PublicCloud
.
Name
,
}
)
// SDConfig is the configuration for Azure based service discovery.
type
SDConfig
struct
{
Environment
string
`yaml:"environment,omitempty"`
Port
int
`yaml:"port"`
SubscriptionID
string
`yaml:"subscription_id"`
TenantID
string
`yaml:"tenant_id,omitempty"`
...
...
@@ -159,27 +161,37 @@ type azureClient struct {
// createAzureClient is a helper function for creating an Azure compute client to ARM.
func
createAzureClient
(
cfg
SDConfig
)
(
azureClient
,
error
)
{
env
,
err
:=
azure
.
EnvironmentFromName
(
cfg
.
Environment
)
if
err
!=
nil
{
return
azureClient
{},
err
}
activeDirectoryEndpoint
:=
env
.
ActiveDirectoryEndpoint
resourceManagerEndpoint
:=
env
.
ResourceManagerEndpoint
var
c
azureClient
oauthConfig
,
err
:=
adal
.
NewOAuthConfig
(
a
zure
.
PublicCloud
.
A
ctiveDirectoryEndpoint
,
cfg
.
TenantID
)
oauthConfig
,
err
:=
adal
.
NewOAuthConfig
(
activeDirectoryEndpoint
,
cfg
.
TenantID
)
if
err
!=
nil
{
return
azureClient
{},
err
}
spt
,
err
:=
adal
.
NewServicePrincipalToken
(
*
oauthConfig
,
cfg
.
ClientID
,
string
(
cfg
.
ClientSecret
),
azure
.
PublicCloud
.
R
esourceManagerEndpoint
)
spt
,
err
:=
adal
.
NewServicePrincipalToken
(
*
oauthConfig
,
cfg
.
ClientID
,
string
(
cfg
.
ClientSecret
),
r
esourceManagerEndpoint
)
if
err
!=
nil
{
return
azureClient
{},
err
}
c
.
vm
=
compute
.
NewVirtualMachinesClient
(
cfg
.
SubscriptionID
)
c
.
vm
.
Authorizer
=
autorest
.
NewBearerAuthorizer
(
spt
)
bearerAuthorizer
:=
autorest
.
NewBearerAuthorizer
(
spt
)
c
.
vm
=
compute
.
NewVirtualMachinesClientWithBaseURI
(
resourceManagerEndpoint
,
cfg
.
SubscriptionID
)
c
.
vm
.
Authorizer
=
bearerAuthorizer
c
.
nic
=
network
.
NewInterfacesClient
(
cfg
.
SubscriptionID
)
c
.
nic
.
Authorizer
=
autorest
.
NewBearerAuthorizer
(
spt
)
c
.
nic
=
network
.
NewInterfacesClient
WithBaseURI
(
resourceManagerEndpoint
,
cfg
.
SubscriptionID
)
c
.
nic
.
Authorizer
=
bearerAuthorizer
c
.
vmss
=
compute
.
NewVirtualMachineScaleSetsClient
(
cfg
.
SubscriptionID
)
c
.
vmss
.
Authorizer
=
autorest
.
NewBearerAuthorizer
(
spt
)
c
.
vmss
=
compute
.
NewVirtualMachineScaleSetsClient
WithBaseURI
(
resourceManagerEndpoint
,
cfg
.
SubscriptionID
)
c
.
vmss
.
Authorizer
=
bearerAuthorizer
c
.
vmssvm
=
compute
.
NewVirtualMachineScaleSetVMsClient
(
cfg
.
SubscriptionID
)
c
.
vmssvm
.
Authorizer
=
autorest
.
NewBearerAuthorizer
(
spt
)
c
.
vmssvm
=
compute
.
NewVirtualMachineScaleSetVMsClient
WithBaseURI
(
resourceManagerEndpoint
,
cfg
.
SubscriptionID
)
c
.
vmssvm
.
Authorizer
=
bearerAuthorizer
return
c
,
nil
}
...
...
@@ -347,7 +359,7 @@ func (d *Discovery) refresh() (tg *targetgroup.Group, err error) {
}
func
(
client
*
azureClient
)
getVMs
()
([]
virtualMachine
,
error
)
{
v
ms
:=
[]
virtualMachine
{}
v
ar
vms
[]
virtualMachine
result
,
err
:=
client
.
vm
.
ListAll
()
if
err
!=
nil
{
return
vms
,
fmt
.
Errorf
(
"could not list virtual machines: %s"
,
err
)
...
...
@@ -373,7 +385,7 @@ func (client *azureClient) getVMs() ([]virtualMachine, error) {
}
func
(
client
*
azureClient
)
getScaleSets
()
([]
compute
.
VirtualMachineScaleSet
,
error
)
{
scaleSets
:=
[]
compute
.
VirtualMachineScaleSet
{}
var
scaleSets
[]
compute
.
VirtualMachineScaleSet
result
,
err
:=
client
.
vmss
.
ListAll
()
if
err
!=
nil
{
return
scaleSets
,
fmt
.
Errorf
(
"could not list virtual machine scale sets: %s"
,
err
)
...
...
@@ -392,7 +404,7 @@ func (client *azureClient) getScaleSets() ([]compute.VirtualMachineScaleSet, err
}
func
(
client
*
azureClient
)
getScaleSetVMs
(
scaleSet
compute
.
VirtualMachineScaleSet
)
([]
virtualMachine
,
error
)
{
v
ms
:=
[]
virtualMachine
{}
v
ar
vms
[]
virtualMachine
//TODO do we really need to fetch the resourcegroup this way?
r
,
err
:=
newAzureResourceFromID
(
*
scaleSet
.
ID
,
nil
)
...
...
docs/configuration/configuration.md
浏览文件 @
f708fd5c
...
...
@@ -272,6 +272,8 @@ See below for the configuration options for Azure discovery:
```
yaml
# The information to access the Azure API.
# The Azure environment.
[
environment
:
<string> | default = AzurePublicCloud
]
# The subscription ID.
subscription_id
:
<string>
# The tenant ID.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录