Skip to content

Commit

Permalink
add some stats (nb of imported nodes + execution time)
Browse files Browse the repository at this point in the history
`-no-dro` option is deprecated for a `-drop` option (it's reverse)
  • Loading branch information
Issif committed Dec 3, 2019
1 parent bece84c commit 9544162
Show file tree
Hide file tree
Showing 29 changed files with 55 additions and 17 deletions.
1 change: 1 addition & 0 deletions addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (list addressList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]addressNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions autoscalinggroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (list autoScalingGroupList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]autoScalingGroupNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions availibiltyzones.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (list availabilityZoneList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]availabilityZoneNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions cacheclusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,5 @@ func (list cacheClusterList) addEdges(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)
}
1 change: 1 addition & 0 deletions cachesubnetgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (list cacheSubnetGroupList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]cacheSubnetGroupNodes)
n := make(map[string]string)
Expand Down
5 changes: 5 additions & 0 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ type connector struct {
awsAccountID string
ressources map[string]map[string]string
waitGroup sync.WaitGroup
stats statistics
}

type statistics struct {
NumberOfNodes int
}

func newConnector(profile, region, dgraph *string) *connector {
Expand Down
1 change: 1 addition & 0 deletions dbclusterparametergroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (list dbClusterParameterGroupList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]dbClusterParameterGroupNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions dbclusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (list dbClusterList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]dbClusterNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions dbinstances.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (list dbInstanceList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]dbInstanceNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions dbparametergroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (list dbParameterGroupList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]dbParameterGroupNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions dbsubnetgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (list dbSubnetGroupList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]dbSubnetGroupNodes)
n := make(map[string]string)
Expand Down
8 changes: 4 additions & 4 deletions dgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func (c *connector) dgraphDropAll() {
log.Println("Drop all previous data")
log.Println("Drop all data")
op := api.Operation{DropAll: true}
if err := c.dgraphClient.Alter(*c.context, &op); err != nil {
log.Fatal(err)
Expand All @@ -25,9 +25,9 @@ func (c *connector) dgraphDropPrevious() {
defer txn.Discard(*c.context)

q := `query query($owner: string, $region: string){
list(func: eq(OwnerId, $owner)) @filter(eq(Region, $region)) {
uid
}
list(func: eq(OwnerId, $owner)) @filter(eq(Region, $region)) {
uid
}
}`

res, err := txn.QueryWithVars(*c.context, q, map[string]string{"$owner": c.awsAccountID, "$region": c.awsRegion})
Expand Down
1 change: 1 addition & 0 deletions images.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (list imageList) addNodes(c *connector) {
}

c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]imageNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions instanceprofiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (list instanceProfileList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]instanceProfileNodes)
n := make(map[string]string)
Expand Down
7 changes: 4 additions & 3 deletions instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (list instanceList) addNodes(c *connector) {
return
}
log.Println("Add Instance Nodes")
instances := make(instanceNodes, 0, len(list.Reservations))
a := make(instanceNodes, 0, len(list.Reservations))

for _, r := range list.Reservations {
for _, i := range r.Instances {
Expand Down Expand Up @@ -81,10 +81,11 @@ func (list instanceList) addNodes(c *connector) {
if i.PublicIpAddress != nil {
b.PublicIPAddress = *i.PublicIpAddress
}
instances = append(instances, b)
a = append(a, b)
}
}
c.dgraphAddNodes(instances)
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]instanceNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions keypairs.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (list keyPairList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]keyPairNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions launchconfigurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (list launchConfigurationList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]launchConfigurationNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions launchtemplates.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (list launchTemplateList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]launchTemplateNodes)
n := make(map[string]string)
Expand Down
2 changes: 2 additions & 0 deletions loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (list loadBalancerList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]loadBalancerNodes)
n := make(map[string]string)
Expand Down Expand Up @@ -131,6 +132,7 @@ func (list loadBalancerV2List) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]loadBalancerNodes)
n := make(map[string]string)
Expand Down
24 changes: 15 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"time"
)

func main() {
Expand All @@ -12,33 +14,34 @@ func main() {
dgraph := flag.String("dgraph", "127.0.0.1:9080", "Dgraph server (ip:port)")
dtype := flag.String("type", "", "Get the schema for a type (only after importing some data)")
list := flag.Bool("list", false, "List available ressource types")
nodrop := flag.Bool("no-drop", false, "Disable the drop of all nodes and the schema before import")
drop := flag.Bool("drop", false, "Drop all nodes and the schema")
noschema := flag.Bool("no-schema", false, "Disable the refresh schema at each run")
flag.Parse()

if *dtype != "" {
dgraphDisplaySchema(dgraph, dtype)
if *list == true {
fmt.Println("Address, AutoScalingGroup, AvailabilityZone, CacheCluster, CacheSubnetGroup, Cidr, DbCluster, DbClusterParameterGroup, DbInstance, DbParameterGroup, DbSubnetGroup, Instance, InstanceProfile, KeyPair, LaunchConfiguration, LaunchTemplate, LoadBalancer, NatGateway, OptionGroup, SecurityGroup, Subnet, TargetGroup, Volume, Vpc, VpcPeeringConnection")
os.Exit(0)
}

connector := newConnector(profile, region, dgraph)
defer connector.grpcConnexion.Close()

if *list == true {
fmt.Println("Address, AutoScalingGroup, AvailabilityZone, CacheCluster, CacheSubnetGroup, Cidr, DbCluster, DbClusterParameterGroup, DbInstance, DbParameterGroup, DbSubnetGroup, Instance, InstanceProfile, KeyPair, LaunchConfiguration, LaunchTemplate, LoadBalancer, NatGateway, OptionGroup, SecurityGroup, Subnet, TargetGroup, Volume, Vpc, VpcPeeringConnection")
if *drop == true {
connector.dgraphDropAll()
os.Exit(0)
}

if *nodrop != true {
connector.dgraphDropAll()
} else {
connector.dgraphDropPrevious()
if *dtype != "" {
dgraphDisplaySchema(dgraph, dtype)
os.Exit(0)
}

if *noschema != true {
connector.dgraphAddSchema()
}

connector.dgraphDropPrevious()

var instances instanceList
var keypairs keyPairList
var volumes volumeList
Expand Down Expand Up @@ -69,6 +72,7 @@ func main() {

// List ressources
connector.waitGroup.Add(25)
start := time.Now()
go func() { instances = connector.listInstances() }()
go func() { keypairs = connector.listKeyPairs() }()
go func() { volumes = connector.listVolumes() }()
Expand Down Expand Up @@ -153,4 +157,6 @@ func main() {
// snapshots.addEdges(connector)

connector.waitGroup.Wait()

log.Printf("%v Nodes have been imported in %s\n", connector.stats.NumberOfNodes, time.Since(start))
}
1 change: 1 addition & 0 deletions natgateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (list natGatewayList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]natGatewayNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions optionsgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (list optionGroupList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]optionGroupNodes)
n := make(map[string]string)
Expand Down
2 changes: 2 additions & 0 deletions securitygroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (list securityGroupList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

if len(y) != 0 {
for i := range y {
Expand All @@ -118,6 +119,7 @@ func (list securityGroupList) addNodes(c *connector) {
})
}
c.dgraphAddNodes(z)
c.stats.NumberOfNodes += len(z)
}

m := make(map[string]securityGroupNodes)
Expand Down
2 changes: 1 addition & 1 deletion snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func (list snapshotList) addNodes(c *connector) {
b.Progress = *i.Progress
a = append(a, b)
}

c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]snapshotNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (list subnetList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]subnetNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions targetgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (list targetGroupList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]targetGroupNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (list volumeList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]volumeNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions vpcpeeringconnections.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (list vpcPeeringConnectionList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]vpcPeeringConnectionNodes)
n := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions vpcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (list vpcList) addNodes(c *connector) {
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)

m := make(map[string]vpcNodes)
n := make(map[string]string)
Expand Down

0 comments on commit 9544162

Please sign in to comment.