-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[targets.example] Add targets extensions example. (#742)
- Loading branch information
Showing
6 changed files
with
274 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package mytargets | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
|
||
"github.com/cloudprober/cloudprober/logger" | ||
"github.com/cloudprober/cloudprober/targets" | ||
"github.com/cloudprober/cloudprober/targets/endpoint" | ||
"github.com/cloudprober/cloudprober/targets/resolver" | ||
) | ||
|
||
var globalResolver = resolver.New() | ||
|
||
type myTargets struct { | ||
c *MyTargetsConf | ||
} | ||
|
||
func (ut *myTargets) ListEndpoints() []endpoint.Endpoint { | ||
return []endpoint.Endpoint{{ | ||
Name: ut.c.GetHostname(), | ||
Port: int(ut.c.GetPort()), | ||
}} | ||
} | ||
|
||
func (ut *myTargets) Resolve(name string, ipVer int) (net.IP, error) { | ||
return globalResolver.Resolve(name, ipVer) | ||
} | ||
|
||
func Init() { | ||
extensionNumber := int(E_Mytargets.TypeDescriptor().Number()) | ||
targets.RegisterTargetsType(extensionNumber, func(c interface{}, l *logger.Logger) (targets.Targets, error) { | ||
utConf, ok := c.(*MyTargetsConf) | ||
if !ok { | ||
return nil, fmt.Errorf("invalid target config type: %T", c) | ||
} | ||
return &myTargets{ | ||
c: utConf, | ||
}, nil | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
syntax = "proto2"; | ||
|
||
package myprober; | ||
|
||
option go_package="github.com/cloudprober/cloudprober/examples/extensions/myprober/mytargets"; | ||
|
||
import "github.com/cloudprober/cloudprober/targets/proto/targets.proto"; | ||
|
||
message MyTargetsConf { | ||
optional string hostname = 1; | ||
optional int32 port = 2; | ||
} | ||
|
||
extend cloudprober.targets.TargetsDef { | ||
optional MyTargetsConf mytargets = 200; | ||
} |