2016-06-28 06:15:37 -07:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
2016-11-21 06:51:36 -08:00
|
|
|
package gce
|
2016-06-28 06:15:37 -07:00
|
|
|
|
|
|
|
import (
|
2017-10-24 21:21:42 -07:00
|
|
|
"context"
|
2022-06-03 04:47:14 -07:00
|
|
|
"errors"
|
2016-06-28 06:15:37 -07:00
|
|
|
"fmt"
|
2024-09-09 18:41:53 -07:00
|
|
|
"log/slog"
|
2016-06-28 06:15:37 -07:00
|
|
|
"net/http"
|
2018-08-10 13:21:46 -07:00
|
|
|
"strconv"
|
2016-06-28 06:15:37 -07:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2023-10-23 06:55:36 -07:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2016-06-28 06:15:37 -07:00
|
|
|
"github.com/prometheus/common/model"
|
|
|
|
"golang.org/x/oauth2/google"
|
2022-08-31 06:50:38 -07:00
|
|
|
"google.golang.org/api/compute/v1"
|
2019-04-10 10:47:25 -07:00
|
|
|
"google.golang.org/api/option"
|
2016-06-28 06:15:37 -07:00
|
|
|
|
2020-08-20 05:48:26 -07:00
|
|
|
"github.com/prometheus/prometheus/discovery"
|
2019-03-25 03:54:22 -07:00
|
|
|
"github.com/prometheus/prometheus/discovery/refresh"
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 12:01:34 -08:00
|
|
|
"github.com/prometheus/prometheus/discovery/targetgroup"
|
2016-10-17 00:45:43 -07:00
|
|
|
"github.com/prometheus/prometheus/util/strutil"
|
2016-06-28 06:15:37 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2016-10-07 23:40:12 -07:00
|
|
|
gceLabel = model.MetaLabelPrefix + "gce_"
|
|
|
|
gceLabelProject = gceLabel + "project"
|
|
|
|
gceLabelZone = gceLabel + "zone"
|
|
|
|
gceLabelNetwork = gceLabel + "network"
|
|
|
|
gceLabelSubnetwork = gceLabel + "subnetwork"
|
|
|
|
gceLabelPublicIP = gceLabel + "public_ip"
|
|
|
|
gceLabelPrivateIP = gceLabel + "private_ip"
|
2018-08-10 08:11:03 -07:00
|
|
|
gceLabelInstanceID = gceLabel + "instance_id"
|
2016-10-07 23:40:12 -07:00
|
|
|
gceLabelInstanceName = gceLabel + "instance_name"
|
|
|
|
gceLabelInstanceStatus = gceLabel + "instance_status"
|
|
|
|
gceLabelTags = gceLabel + "tags"
|
2016-10-17 00:45:43 -07:00
|
|
|
gceLabelMetadata = gceLabel + "metadata_"
|
2018-05-08 09:37:47 -07:00
|
|
|
gceLabelLabel = gceLabel + "label_"
|
2018-03-31 01:20:19 -07:00
|
|
|
gceLabelMachineType = gceLabel + "machine_type"
|
2016-06-28 06:15:37 -07:00
|
|
|
)
|
|
|
|
|
2019-03-25 03:54:22 -07:00
|
|
|
// DefaultSDConfig is the default GCE SD configuration.
|
|
|
|
var DefaultSDConfig = SDConfig{
|
|
|
|
Port: 80,
|
|
|
|
TagSeparator: ",",
|
|
|
|
RefreshInterval: model.Duration(60 * time.Second),
|
|
|
|
}
|
2016-06-28 06:15:37 -07:00
|
|
|
|
2020-08-20 05:48:26 -07:00
|
|
|
func init() {
|
|
|
|
discovery.RegisterConfig(&SDConfig{})
|
|
|
|
}
|
|
|
|
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 12:01:34 -08:00
|
|
|
// SDConfig is the configuration for GCE based service discovery.
|
|
|
|
type SDConfig struct {
|
|
|
|
// Project: The Google Cloud Project ID
|
|
|
|
Project string `yaml:"project"`
|
|
|
|
|
|
|
|
// Zone: The zone of the scrape targets.
|
|
|
|
// If you need to configure multiple zones use multiple gce_sd_configs
|
|
|
|
Zone string `yaml:"zone"`
|
|
|
|
|
|
|
|
// Filter: Can be used optionally to filter the instance list by other criteria.
|
|
|
|
// Syntax of this filter string is described here in the filter query parameter section:
|
|
|
|
// https://cloud.google.com/compute/docs/reference/latest/instances/list
|
|
|
|
Filter string `yaml:"filter,omitempty"`
|
|
|
|
|
|
|
|
RefreshInterval model.Duration `yaml:"refresh_interval,omitempty"`
|
|
|
|
Port int `yaml:"port"`
|
|
|
|
TagSeparator string `yaml:"tag_separator,omitempty"`
|
|
|
|
}
|
|
|
|
|
2024-01-23 07:53:55 -08:00
|
|
|
// NewDiscovererMetrics implements discovery.Config.
|
|
|
|
func (*SDConfig) NewDiscovererMetrics(reg prometheus.Registerer, rmi discovery.RefreshMetricsInstantiator) discovery.DiscovererMetrics {
|
|
|
|
return &gceMetrics{
|
|
|
|
refreshMetrics: rmi,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-20 05:48:26 -07:00
|
|
|
// Name returns the name of the Config.
|
|
|
|
func (*SDConfig) Name() string { return "gce" }
|
|
|
|
|
|
|
|
// NewDiscoverer returns a Discoverer for the Config.
|
|
|
|
func (c *SDConfig) NewDiscoverer(opts discovery.DiscovererOptions) (discovery.Discoverer, error) {
|
2024-01-23 07:53:55 -08:00
|
|
|
return NewDiscovery(*c, opts.Logger, opts.Metrics)
|
2020-08-20 05:48:26 -07:00
|
|
|
}
|
|
|
|
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 12:01:34 -08:00
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (c *SDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
*c = DefaultSDConfig
|
|
|
|
type plain SDConfig
|
|
|
|
err := unmarshal((*plain)(c))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if c.Project == "" {
|
2019-03-25 16:01:12 -07:00
|
|
|
return errors.New("GCE SD configuration requires a project")
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 12:01:34 -08:00
|
|
|
}
|
|
|
|
if c.Zone == "" {
|
2019-03-25 16:01:12 -07:00
|
|
|
return errors.New("GCE SD configuration requires a zone")
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 12:01:34 -08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-03-16 16:29:47 -07:00
|
|
|
// Discovery periodically performs GCE-SD requests. It implements
|
2018-01-08 15:59:18 -08:00
|
|
|
// the Discoverer interface.
|
2017-03-16 16:29:47 -07:00
|
|
|
type Discovery struct {
|
2019-03-25 03:54:22 -07:00
|
|
|
*refresh.Discovery
|
2016-06-28 06:15:37 -07:00
|
|
|
project string
|
|
|
|
zone string
|
|
|
|
filter string
|
|
|
|
client *http.Client
|
|
|
|
svc *compute.Service
|
|
|
|
isvc *compute.InstancesService
|
|
|
|
port int
|
|
|
|
tagSeparator string
|
|
|
|
}
|
|
|
|
|
2017-03-16 16:29:47 -07:00
|
|
|
// NewDiscovery returns a new Discovery which periodically refreshes its targets.
|
2024-09-09 18:41:53 -07:00
|
|
|
func NewDiscovery(conf SDConfig, logger *slog.Logger, metrics discovery.DiscovererMetrics) (*Discovery, error) {
|
2024-01-23 07:53:55 -08:00
|
|
|
m, ok := metrics.(*gceMetrics)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("invalid discovery metrics type")
|
|
|
|
}
|
|
|
|
|
2019-03-25 03:54:22 -07:00
|
|
|
d := &Discovery{
|
2016-06-28 06:15:37 -07:00
|
|
|
project: conf.Project,
|
|
|
|
zone: conf.Zone,
|
|
|
|
filter: conf.Filter,
|
|
|
|
port: conf.Port,
|
|
|
|
tagSeparator: conf.TagSeparator,
|
|
|
|
}
|
|
|
|
var err error
|
2019-03-25 03:54:22 -07:00
|
|
|
d.client, err = google.DefaultClient(context.Background(), compute.ComputeReadonlyScope)
|
2016-06-28 06:15:37 -07:00
|
|
|
if err != nil {
|
2022-06-03 04:47:14 -07:00
|
|
|
return nil, fmt.Errorf("error setting up communication with GCE service: %w", err)
|
2016-06-28 06:15:37 -07:00
|
|
|
}
|
2019-04-10 10:47:25 -07:00
|
|
|
d.svc, err = compute.NewService(context.Background(), option.WithHTTPClient(d.client))
|
2016-06-28 06:15:37 -07:00
|
|
|
if err != nil {
|
2022-06-03 04:47:14 -07:00
|
|
|
return nil, fmt.Errorf("error setting up communication with GCE service: %w", err)
|
2016-06-28 06:15:37 -07:00
|
|
|
}
|
2019-03-25 03:54:22 -07:00
|
|
|
d.isvc = compute.NewInstancesService(d.svc)
|
|
|
|
|
|
|
|
d.Discovery = refresh.NewDiscovery(
|
2023-10-23 06:55:36 -07:00
|
|
|
refresh.Options{
|
2024-01-23 07:53:55 -08:00
|
|
|
Logger: logger,
|
|
|
|
Mech: "gce",
|
|
|
|
Interval: time.Duration(conf.RefreshInterval),
|
|
|
|
RefreshF: d.refresh,
|
|
|
|
MetricsInstantiator: m.refreshMetrics,
|
2023-10-23 06:55:36 -07:00
|
|
|
},
|
2019-03-25 03:54:22 -07:00
|
|
|
)
|
|
|
|
return d, nil
|
2016-06-28 06:15:37 -07:00
|
|
|
}
|
|
|
|
|
2019-03-25 03:54:22 -07:00
|
|
|
func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) {
|
|
|
|
tg := &targetgroup.Group{
|
2017-03-16 16:29:47 -07:00
|
|
|
Source: fmt.Sprintf("GCE_%s_%s", d.project, d.zone),
|
2016-06-28 06:15:37 -07:00
|
|
|
}
|
|
|
|
|
2017-03-16 16:29:47 -07:00
|
|
|
ilc := d.isvc.List(d.project, d.zone)
|
|
|
|
if len(d.filter) > 0 {
|
|
|
|
ilc = ilc.Filter(d.filter)
|
2016-06-28 06:15:37 -07:00
|
|
|
}
|
2019-03-25 03:54:22 -07:00
|
|
|
err := ilc.Pages(ctx, func(l *compute.InstanceList) error {
|
2016-06-28 06:15:37 -07:00
|
|
|
for _, inst := range l.Items {
|
|
|
|
if len(inst.NetworkInterfaces) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
labels := model.LabelSet{
|
2017-03-16 16:29:47 -07:00
|
|
|
gceLabelProject: model.LabelValue(d.project),
|
2016-10-07 23:40:12 -07:00
|
|
|
gceLabelZone: model.LabelValue(inst.Zone),
|
2018-08-10 13:21:46 -07:00
|
|
|
gceLabelInstanceID: model.LabelValue(strconv.FormatUint(inst.Id, 10)),
|
2016-10-07 23:40:12 -07:00
|
|
|
gceLabelInstanceName: model.LabelValue(inst.Name),
|
|
|
|
gceLabelInstanceStatus: model.LabelValue(inst.Status),
|
2018-03-31 01:20:19 -07:00
|
|
|
gceLabelMachineType: model.LabelValue(inst.MachineType),
|
2016-06-28 06:15:37 -07:00
|
|
|
}
|
|
|
|
priIface := inst.NetworkInterfaces[0]
|
|
|
|
labels[gceLabelNetwork] = model.LabelValue(priIface.Network)
|
|
|
|
labels[gceLabelSubnetwork] = model.LabelValue(priIface.Subnetwork)
|
|
|
|
labels[gceLabelPrivateIP] = model.LabelValue(priIface.NetworkIP)
|
2017-03-16 16:29:47 -07:00
|
|
|
addr := fmt.Sprintf("%s:%d", priIface.NetworkIP, d.port)
|
2016-06-28 06:15:37 -07:00
|
|
|
labels[model.AddressLabel] = model.LabelValue(addr)
|
|
|
|
|
2021-06-27 18:03:10 -07:00
|
|
|
// Append named interface metadata for all interfaces
|
|
|
|
for _, iface := range inst.NetworkInterfaces {
|
2021-07-06 04:53:23 -07:00
|
|
|
gceLabelNetAddress := model.LabelName(fmt.Sprintf("%sinterface_ipv4_%s", gceLabel, strutil.SanitizeLabelName(iface.Name)))
|
2021-06-27 18:03:10 -07:00
|
|
|
labels[gceLabelNetAddress] = model.LabelValue(iface.NetworkIP)
|
2021-06-21 20:40:50 -07:00
|
|
|
}
|
|
|
|
|
2016-10-17 00:45:43 -07:00
|
|
|
// Tags in GCE are usually only used for networking rules.
|
2016-06-28 06:15:37 -07:00
|
|
|
if inst.Tags != nil && len(inst.Tags.Items) > 0 {
|
|
|
|
// We surround the separated list with the separator as well. This way regular expressions
|
|
|
|
// in relabeling rules don't have to consider tag positions.
|
2017-03-16 16:29:47 -07:00
|
|
|
tags := d.tagSeparator + strings.Join(inst.Tags.Items, d.tagSeparator) + d.tagSeparator
|
2016-06-28 06:15:37 -07:00
|
|
|
labels[gceLabelTags] = model.LabelValue(tags)
|
|
|
|
}
|
|
|
|
|
2016-10-17 00:45:43 -07:00
|
|
|
// GCE metadata are key-value pairs for user supplied attributes.
|
|
|
|
if inst.Metadata != nil {
|
|
|
|
for _, i := range inst.Metadata.Items {
|
|
|
|
// Protect against occasional nil pointers.
|
|
|
|
if i.Value == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
name := strutil.SanitizeLabelName(i.Key)
|
|
|
|
labels[gceLabelMetadata+model.LabelName(name)] = model.LabelValue(*i.Value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-08 09:37:47 -07:00
|
|
|
// GCE labels are key-value pairs that group associated resources
|
2018-10-10 13:05:48 -07:00
|
|
|
for key, value := range inst.Labels {
|
|
|
|
name := strutil.SanitizeLabelName(key)
|
|
|
|
labels[gceLabelLabel+model.LabelName(name)] = model.LabelValue(value)
|
2018-05-08 09:37:47 -07:00
|
|
|
}
|
|
|
|
|
2016-06-28 06:15:37 -07:00
|
|
|
if len(priIface.AccessConfigs) > 0 {
|
|
|
|
ac := priIface.AccessConfigs[0]
|
|
|
|
if ac.Type == "ONE_TO_ONE_NAT" {
|
|
|
|
labels[gceLabelPublicIP] = model.LabelValue(ac.NatIP)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tg.Targets = append(tg.Targets, labels)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
2022-06-03 04:47:14 -07:00
|
|
|
return nil, fmt.Errorf("error retrieving refresh targets from gce: %w", err)
|
2016-06-28 06:15:37 -07:00
|
|
|
}
|
2019-03-25 03:54:22 -07:00
|
|
|
return []*targetgroup.Group{tg}, nil
|
2016-06-28 06:15:37 -07:00
|
|
|
}
|