Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
telegraf-nftables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Due to inactivity, this project is scheduled to be deleted on 2035-04-24.
Why is this scheduled?
Show more breadcrumbs
vqgroup
telegraf-nftables
Commits
265d0e6d
Unverified
Commit
265d0e6d
authored
6 years ago
by
Daniel Nelson
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix bug preventing database from being recreated (#3962)
parent
413cf6dd
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/outputs/influxdb/influxdb.go
+1
-1
1 addition, 1 deletion
plugins/outputs/influxdb/influxdb.go
plugins/outputs/influxdb/influxdb_test.go
+56
-6
56 additions, 6 deletions
plugins/outputs/influxdb/influxdb_test.go
with
57 additions
and
7 deletions
plugins/outputs/influxdb/influxdb.go
+
1
−
1
View file @
265d0e6d
...
...
@@ -210,7 +210,7 @@ func (i *InfluxDB) Write(metrics []telegraf.Metric) error {
}
switch
apiError
:=
err
.
(
type
)
{
case
APIError
:
case
*
APIError
:
if
!
i
.
SkipDatabaseCreation
{
if
apiError
.
Type
==
DatabaseNotFound
{
err
:=
client
.
CreateDatabase
(
ctx
)
...
...
This diff is collapsed.
Click to expand it.
plugins/outputs/influxdb/influxdb_test.go
+
56
−
6
View file @
265d0e6d
...
...
@@ -2,11 +2,13 @@ package influxdb_test
import
(
"context"
"net/http"
"testing"
"time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/metric"
"github.com/influxdata/telegraf/plugins/outputs/influxdb"
"github.com/stretchr/testify/require"
)
...
...
@@ -37,7 +39,7 @@ func (c *MockClient) CreateDatabase(ctx context.Context) error {
func
TestDeprecatedURLSupport
(
t
*
testing
.
T
)
{
var
actual
*
influxdb
.
UDPConfig
output
:=
influxdb
.
InfluxDB
{
URL
:
"udp://localhost:808
6
"
,
URL
:
"udp://localhost:808
9
"
,
CreateUDPClientF
:
func
(
config
*
influxdb
.
UDPConfig
)
(
influxdb
.
Client
,
error
)
{
actual
=
config
...
...
@@ -46,7 +48,7 @@ func TestDeprecatedURLSupport(t *testing.T) {
}
err
:=
output
.
Connect
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"udp://localhost:808
6
"
,
actual
.
URL
.
String
())
require
.
Equal
(
t
,
"udp://localhost:808
9
"
,
actual
.
URL
.
String
())
}
func
TestDefaultURL
(
t
*
testing
.
T
)
{
...
...
@@ -70,7 +72,7 @@ func TestConnectUDPConfig(t *testing.T) {
var
actual
*
influxdb
.
UDPConfig
output
:=
influxdb
.
InfluxDB
{
URLs
:
[]
string
{
"udp://localhost:808
6
"
},
URLs
:
[]
string
{
"udp://localhost:808
9
"
},
UDPPayload
:
42
,
CreateUDPClientF
:
func
(
config
*
influxdb
.
UDPConfig
)
(
influxdb
.
Client
,
error
)
{
...
...
@@ -81,7 +83,7 @@ func TestConnectUDPConfig(t *testing.T) {
err
:=
output
.
Connect
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"udp://localhost:808
6
"
,
actual
.
URL
.
String
())
require
.
Equal
(
t
,
"udp://localhost:808
9
"
,
actual
.
URL
.
String
())
require
.
Equal
(
t
,
42
,
actual
.
MaxPayloadSize
)
require
.
NotNil
(
t
,
actual
.
Serializer
)
}
...
...
@@ -90,7 +92,7 @@ func TestConnectHTTPConfig(t *testing.T) {
var
actual
*
influxdb
.
HTTPConfig
output
:=
influxdb
.
InfluxDB
{
URLs
:
[]
string
{
"http://localhost:808
9
"
},
URLs
:
[]
string
{
"http://localhost:808
6
"
},
Database
:
"telegraf"
,
RetentionPolicy
:
"default"
,
WriteConsistency
:
"any"
,
...
...
@@ -98,7 +100,7 @@ func TestConnectHTTPConfig(t *testing.T) {
Username
:
"guy"
,
Password
:
"smiley"
,
UserAgent
:
"telegraf"
,
HTTPProxy
:
"http://localhost:808
9
"
,
HTTPProxy
:
"http://localhost:808
6
"
,
HTTPHeaders
:
map
[
string
]
string
{
"x"
:
"y"
,
},
...
...
@@ -133,3 +135,51 @@ func TestConnectHTTPConfig(t *testing.T) {
require
.
Equal
(
t
,
output
.
Database
,
actual
.
Database
)
}
func
TestWriteRecreateDatabaseIfDatabaseNotFound
(
t
*
testing
.
T
)
{
var
createDatabaseCalled
bool
output
:=
influxdb
.
InfluxDB
{
URLs
:
[]
string
{
"http://localhost:8086"
},
CreateHTTPClientF
:
func
(
config
*
influxdb
.
HTTPConfig
)
(
influxdb
.
Client
,
error
)
{
return
&
MockClient
{
CreateDatabaseF
:
func
(
ctx
context
.
Context
)
error
{
createDatabaseCalled
=
true
return
nil
},
WriteF
:
func
(
ctx
context
.
Context
,
metrics
[]
telegraf
.
Metric
)
error
{
return
&
influxdb
.
APIError
{
StatusCode
:
http
.
StatusNotFound
,
Title
:
"404 Not Found"
,
Description
:
`database not found "telegraf"`
,
Type
:
influxdb
.
DatabaseNotFound
,
}
},
URLF
:
func
()
string
{
return
"http://localhost:8086"
},
},
nil
},
}
err
:=
output
.
Connect
()
require
.
NoError
(
t
,
err
)
m
,
err
:=
metric
.
New
(
"cpu"
,
map
[
string
]
string
{},
map
[
string
]
interface
{}{
"value"
:
42.0
,
},
time
.
Unix
(
0
,
0
),
)
require
.
NoError
(
t
,
err
)
metrics
:=
[]
telegraf
.
Metric
{
m
}
createDatabaseCalled
=
false
err
=
output
.
Write
(
metrics
)
// We only have one URL, so we expect an error
require
.
Error
(
t
,
err
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment