Skip to content

Commit

Permalink
Get EOLInfo and compare with actual engine version
Browse files Browse the repository at this point in the history
  • Loading branch information
chaspy committed Feb 7, 2021
1 parent 5902746 commit c19bd9e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.15

require (
github.com/aws/aws-sdk-go v1.37.6
github.com/hashicorp/go-version v1.2.0
github.com/jszwec/csvutil v1.4.0
github.com/prometheus/client_golang v1.9.0
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
Expand Down
54 changes: 47 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/hashicorp/go-version"
"github.com/jszwec/csvutil"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand All @@ -36,19 +37,17 @@ var (
Name: "cluster_count",
Help: "Number of RDS",
},
[]string{"cluster_identifier", "engine", "engine_version"},
[]string{"cluster_identifier", "engine", "engine_version", "eol_status"},
)
)

func main() {
eolinfo, err := readEOLInfoCSV()
interval, err := getInterval()
if err != nil {
log.Fatal(err)
}

fmt.Println(eolinfo)

interval, err := getInterval()
eolInfo, err := readEOLInfoCSV()
if err != nil {
log.Fatal(err)
}
Expand All @@ -62,7 +61,7 @@ func main() {

// register metrics as background
for range ticker.C {
err := snapshot()
err := snapshot(eolInfo)
if err != nil {
log.Fatal(err)
}
Expand All @@ -71,7 +70,7 @@ func main() {
log.Fatal(http.ListenAndServe(":8080", nil))
}

func snapshot() error {
func snapshot(eolInfo []EOLInfo) error {
rdsCount.Reset()

ClusterInfos, err := getRDSClusters()
Expand All @@ -87,10 +86,16 @@ func snapshot() error {
RDSInfos := append(ClusterInfos, InstanceInfos...)

for _, RDSInfo := range RDSInfos {
eolStatus, err := validateEOLStatus(RDSInfo, eolInfo)
if err != nil {
return fmt.Errorf("failed to validate EOL Status: %w", err)
}

labels := prometheus.Labels{
"cluster_identifier": RDSInfo.ClusterIdentifier,
"engine": RDSInfo.Engine,
"engine_version": RDSInfo.EngineVersion,
"eol_status": eolStatus,
}
rdsCount.With(labels).Set(1)
}
Expand Down Expand Up @@ -228,3 +233,38 @@ func readEOLInfoCSV() ([]EOLInfo, error) {

return eolInfos, nil
}

func validateEOLStatus(rdsInfo RDSInfo, eolInfos []EOLInfo) (string, error) {
for _, eolInfo := range eolInfos {
if eolInfo.Engine == rdsInfo.Engine {
fmt.Printf("match engine %v\n", eolInfo.Engine)

result, err := compareEngineVersion(rdsInfo, eolInfo)
if err != nil {
return "", fmt.Errorf("failed to compare Engine Version:: %w", err)
}

if result {
fmt.Printf("match engine version %v\n", rdsInfo.EngineVersion)
}
}
}

return "hoge", nil
}

func compareEngineVersion(rdsInfo RDSInfo, eolInfo EOLInfo) (bool, error) {
engineVersion, err := version.NewVersion(rdsInfo.EngineVersion)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return false, nil
}

eolEngineVersion, err := version.NewVersion(eolInfo.EOLEngineVersion)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return false, nil
}

return engineVersion.LessThan(eolEngineVersion), nil
}

0 comments on commit c19bd9e

Please sign in to comment.