Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cb-util
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christoph Alt
cb-util
Commits
4b34adca
Commit
4b34adca
authored
2 years ago
by
Christoph Alt
Browse files
Options
Downloads
Patches
Plain Diff
upload works now also with row data points
parent
2a75ddba
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#43045
passed
2 years ago
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cbutil/upload.py
+17
-3
17 additions, 3 deletions
cbutil/upload.py
tests/test_upload.py
+14
-3
14 additions, 3 deletions
tests/test_upload.py
with
31 additions
and
6 deletions
cbutil/upload.py
+
17
−
3
View file @
4b34adca
...
@@ -2,10 +2,15 @@ import logging
...
@@ -2,10 +2,15 @@ import logging
import
os
import
os
import
pprint
import
pprint
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
from
typing
import
Dict
,
List
,
Union
import
dotenv
import
dotenv
from
influxdb
import
InfluxDBClient
from
influxdb
import
InfluxDBClient
from
.data_points
import
DataPoint
Points
=
Union
[
List
[
Dict
],
List
[
DataPoint
]]
logger
=
logging
.
getLogger
(
__file__
)
logger
=
logging
.
getLogger
(
__file__
)
MISSING_DB_PW
=
"""
MISSING_DB_PW
=
"""
...
@@ -53,16 +58,25 @@ class Uploader:
...
@@ -53,16 +58,25 @@ class Uploader:
database
=
config
.
database
,
database
=
config
.
database
,
)
)
def
upload
(
self
,
points
,
dry_run
=
False
,
*
,
time_precision
=
'
s
'
,
**
kwargs
):
def
upload
(
self
,
points
:
Points
,
dry_run
=
False
,
*
,
time_precision
=
'
s
'
,
**
kwargs
):
logger
.
info
(
f
"
Uploading:
{
pprint
.
pformat
(
points
)
}
"
)
to_upload
=
points
if
isinstance
(
points
[
0
],
DataPoint
):
assert
all
(
isinstance
(
dp
,
DataPoint
)
for
dp
in
points
)
to_upload
=
[
dp
.
asdict
()
for
dp
in
points
]
else
:
assert
all
(
isinstance
(
dp
,
Dict
)
for
dp
in
points
)
logger
.
info
(
f
"
Uploading:
{
pprint
.
pformat
(
to_upload
)
}
"
)
success
=
True
if
(
common_tags
:
=
kwargs
.
get
(
"
tags
"
)):
if
(
common_tags
:
=
kwargs
.
get
(
"
tags
"
)):
logger
.
info
(
f
"
with common tags:
{
pprint
.
pformat
(
common_tags
)
}
"
)
logger
.
info
(
f
"
with common tags:
{
pprint
.
pformat
(
common_tags
)
}
"
)
if
not
dry_run
:
if
not
dry_run
:
success
=
self
.
client
.
write_points
(
points
,
success
=
self
.
client
.
write_points
(
to_upload
,
time_precision
=
time_precision
,
time_precision
=
time_precision
,
**
kwargs
)
**
kwargs
)
if
success
:
if
success
:
logger
.
info
(
f
"
Uploaded
{
len
(
points
)
}
items
"
)
logger
.
info
(
f
"
Uploaded
{
len
(
points
)
}
items
"
)
else
:
else
:
raise
ValueError
(
"
Uploading to influxdb went wrong!
"
)
raise
ValueError
(
"
Uploading to influxdb went wrong!
"
)
return
success
This diff is collapsed.
Click to expand it.
tests/test_upload.py
+
14
−
3
View file @
4b34adca
from
cbutil.upload
import
Uploader
,
DBConfig
,
load_config_from_env
import
os
import
os
import
time
from
cbutil.data_points
import
DataPoint
from
cbutil.upload
import
DBConfig
,
Uploader
,
load_config_from_env
DUMMY_CONF
=
DBConfig
(
"
host
"
,
1234
,
"
user_name
"
,
"
database
"
,
"
write_user_pw
"
)
def
setup_env
():
def
setup_env
():
...
@@ -12,8 +17,7 @@ def setup_env():
...
@@ -12,8 +17,7 @@ def setup_env():
def
test_init_with_conf
():
def
test_init_with_conf
():
conf
=
DBConfig
(
"
host
"
,
1234
,
"
user_name
"
,
"
database
"
,
"
write_user_pw
"
)
Uploader
(
DUMMY_CONF
)
Uploader
(
conf
)
def
test_load_conf
():
def
test_load_conf
():
...
@@ -37,3 +41,10 @@ def test_init_from_env():
...
@@ -37,3 +41,10 @@ def test_init_from_env():
assert
up
.
config
.
user_name
==
os
.
environ
[
"
INFLUXDB_USER_NAME
"
]
assert
up
.
config
.
user_name
==
os
.
environ
[
"
INFLUXDB_USER_NAME
"
]
assert
up
.
config
.
database
==
os
.
environ
[
"
INFLUXDB_DATABASE
"
]
assert
up
.
config
.
database
==
os
.
environ
[
"
INFLUXDB_DATABASE
"
]
assert
up
.
config
.
write_user_pw
==
os
.
environ
[
"
INFLUXDB_WRITE_USER_PASSWORD
"
]
assert
up
.
config
.
write_user_pw
==
os
.
environ
[
"
INFLUXDB_WRITE_USER_PASSWORD
"
]
def
test_upload
():
up
=
Uploader
(
DUMMY_CONF
)
dp
=
DataPoint
(
measurement
=
"
Test
"
,
time
=
int
(
time
.
time
()),
fields
=
dict
(),
tags
=
dict
())
assert
up
.
upload
([
dp
],
dry_run
=
True
)
assert
up
.
upload
([
dp
.
asdict
()],
dry_run
=
True
)
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