Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timestamped values #277

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ modules:
- name: example_timestamped_value
type: object
path: '{ .values[?(@.state == "INACTIVE")] }'
epochTimestamp: '{ .timestamp }'
epochtimestamp: '{ .timestamp }'
help: Example of a timestamped value scrape in the json
labels:
environment: beta # static label
Expand Down
2 changes: 1 addition & 1 deletion examples/data.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"counter": 1234,
"timestamp": 1657568506,
"values": [
{
"id": "id-A",
Expand All @@ -12,6 +11,7 @@
"id": "id-B",
"count": 2,
"some_boolean": true,
"timestamp": 1657568506,
"state": "INACTIVE"
},
{
Expand Down
4 changes: 3 additions & 1 deletion exporter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ func SanitizeValue(s string) (float64, error) {

func SanitizeIntValue(s string) (int64, error) {
var err error
var valueFloat float64
var value int64
var resultErr string

if value, err = strconv.ParseInt(s, 10, 64); err == nil {
if valueFloat, err = strconv.ParseFloat(s, 64); err == nil {
value = int64(math.Round(valueFloat))
return value, nil
}
resultErr = fmt.Sprintf("%s", err)
Expand Down