Skip to content

Commit

Permalink
Added special parsing for Ubuntu versions (#16)
Browse files Browse the repository at this point in the history
* Added special parsing for Ubuntue versions

* Fixed date in changelog
  • Loading branch information
Corbin Phelps authored Jan 9, 2019
1 parent bc634aa commit 1c568b0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.1 - 2019-01-09
### Fixes
- Added special case for parsing Ubuntu versions

## 1.0.0 - 2018-11-29
### Changes
- Bumped version for GA release
Expand Down
19 changes: 19 additions & 0 deletions src/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metrics

import (
"reflect"
"strings"

"github.com/blang/semver"
"github.com/newrelic/infra-integrations-sdk/data/metric"
Expand Down Expand Up @@ -56,6 +57,12 @@ func collectVersion(connection *connection.PGSQLConnection) (*semver.Version, er
return nil, err
}

// special case for ubuntu parsing
version := versionRows[0].Version
if strings.Contains(version, "Ubuntu") {
return parseUbuntuVersion(version)
}

v, err := semver.ParseTolerant(versionRows[0].Version)
if err != nil {
return nil, err
Expand All @@ -64,6 +71,18 @@ func collectVersion(connection *connection.PGSQLConnection) (*semver.Version, er
return &v, nil
}

func parseUbuntuVersion(version string) (*semver.Version, error) {
specialIndex := strings.Index(version, " (Ubuntu")
partialVersion := version[:specialIndex]

v, err := semver.ParseTolerant(partialVersion)
if err != nil {
return nil, err
}

return &v, nil
}

// PopulateInstanceMetrics populates the metrics for an instance
func PopulateInstanceMetrics(instanceEntity *integration.Entity, version *semver.Version, connection *connection.PGSQLConnection, hostname string) {
metricSet := instanceEntity.NewMetricSet("PostgresqlInstanceSample",
Expand Down
20 changes: 20 additions & 0 deletions src/metrics/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ func Test_collectVersion(t *testing.T) {
assert.Equal(t, expected, version)
}

func Test_collectVersion_Ubuntu(t *testing.T) {

testConnection, mock := connection.CreateMockSQL(t)

versionRows := sqlmock.NewRows([]string{"server_version"}).
AddRow("10.4 (Ubuntu 10.4-2.pgdg16.04+1)")

mock.ExpectQuery(versionQuery).WillReturnRows(versionRows)

expected := &semver.Version{
Major: 10,
Minor: 4,
}

version, err := collectVersion(testConnection)

assert.Nil(t, err)
assert.Equal(t, expected, version)
}

func Test_collectVersion_Err(t *testing.T) {

testConnection, mock := connection.CreateMockSQL(t)
Expand Down
2 changes: 1 addition & 1 deletion src/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

const (
integrationName = "com.newrelic.postgresql"
integrationVersion = "1.0.0"
integrationVersion = "1.0.1"
)

func main() {
Expand Down

0 comments on commit 1c568b0

Please sign in to comment.