1
0
Fork 0

pass of comments
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Massaki Archambault 2021-09-26 00:42:34 -04:00
parent 42e2a23e26
commit 80e64a3760
8 changed files with 21 additions and 3 deletions

View File

@ -577,7 +577,7 @@ func (e *Exporter) collectHotspotMetrics(wg *sync.WaitGroup, ch chan<- prometheu
func (e *Exporter) collectHotspotActivityMetrics(wg *sync.WaitGroup, ch chan<- prometheus.Metric, account *Account, hotspotData heliumapi.AccountHotspot) {
defer wg.Done()
hotspotActivityForAddress, err := heliumapi.GetHotspotActivityCount(hotspotData.Address)
hotspotActivityForAddress, err := heliumapi.GetHotspotActivityCounts(hotspotData.Address)
if err != nil {
fmt.Println(err)
return

1
go.mod
View File

@ -11,7 +11,6 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.29.0 // indirect
github.com/prometheus/exporter-toolkit v0.6.1 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
google.golang.org/protobuf v1.26.0-rc.1 // indirect

View File

@ -8,6 +8,7 @@ import (
"github.com/helium-blockchain-exporter/heliumapi/activity"
)
// query https://docs.helium.com/api/blockchain/accounts#account-for-address
func GetAccountForAddress(account string) (*Account, error) {
path := "/v1/accounts/" + account
@ -27,6 +28,7 @@ func GetAccountForAddress(account string) (*Account, error) {
return &respobject.Data, nil
}
// query https://docs.helium.com/api/blockchain/accounts#activity-for-account
func GetActivityForAccount(account string, filterTypes []string, minTime *time.Time, maxTime *time.Time) (*activity.Activities, error) {
path := "/v1/accounts/" + account + "/activity"
params := map[string]string{}
@ -57,6 +59,7 @@ func GetActivityForAccount(account string, filterTypes []string, minTime *time.T
return activity.NewActivities(combinedResp)
}
// query https://docs.helium.com/api/blockchain/accounts#activity-counts-for-account
func GetActivityCountsForAccount(account string) (*ActivityCounts, error) {
path := "/v1/accounts/" + account + "/activity/count"
@ -76,6 +79,7 @@ func GetActivityCountsForAccount(account string) (*ActivityCounts, error) {
return &respobject.Data, nil
}
// query https://docs.helium.com/api/blockchain/accounts#reward-totals-for-an-account
func GetRewardTotalsForAccount(account string, minTime *time.Time, maxTime *time.Time) (*RewardTotal, error) {
path := "/v1/accounts/" + account + "/rewards/sum"
params := map[string]string{}
@ -102,6 +106,7 @@ func GetRewardTotalsForAccount(account string, minTime *time.Time, maxTime *time
return &respobject.Data, nil
}
// query https://docs.helium.com/api/blockchain/accounts#hotspots-for-account
func GetHotspotsForAccount(account string) (*[]AccountHotspot, error) {
path := "/v1/accounts/" + account + "/hotspots"

View File

@ -9,6 +9,11 @@ type ActivityResp struct {
Data []json.RawMessage `json:"data"`
}
// Parse the response from the activity api.
// The helium api return a list of of activities in an array with mixed type.
// In order to operate on the array, we determine the type using the "type"
// property, unmarshal the activity with the proper model, and add it to the proper
// array in an Activities structure.
func NewActivities(resp ActivityResp) (*Activities, error) {
type ActivityType struct {
Type string `json:"type"`

View File

@ -6,7 +6,8 @@ import (
"time"
)
func GetHotspotActivityCount(hotspot string) (*ActivityCounts, error) {
// query https://docs.helium.com/api/blockchain/hotspots#hotspots-activity-counts
func GetHotspotActivityCounts(hotspot string) (*ActivityCounts, error) {
path := "/v1/hotspots/" + hotspot + "/activity/count"
// query the api
@ -25,6 +26,7 @@ func GetHotspotActivityCount(hotspot string) (*ActivityCounts, error) {
return &respobject.Data, nil
}
// query https://docs.helium.com/api/blockchain/hotspots#reward-total-for-a-hotspot
func GetRewardsTotalForHotspot(hotspot string, minTime *time.Time, maxTime *time.Time) (*RewardTotal, error) {
path := "/v1/hotspots/" + hotspot + "/rewards/sum"
params := map[string]string{}

View File

@ -5,6 +5,7 @@ import (
"fmt"
)
// query https://docs.helium.com/api/blockchain/oracle-prices#current-oracle-price
func GetCurrentOraclePrice() (*CurrentOraclePrice, error) {
path := "/v1/oracle/prices/current"

View File

@ -12,6 +12,7 @@ var (
client = &http.Client{}
)
// createGetRequest create a GET request to the helium api
func createGetRequest(path string, params map[string]string) (*http.Request, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s", ApiUrl, path), nil)
@ -33,6 +34,7 @@ func createGetRequest(path string, params map[string]string) (*http.Request, err
return req, err
}
// getHeliumApi query a regular helium api endpoint
func getHeliumApi(path string, params *map[string]string) ([]byte, error) {
// if params is nil, set it to an empty map
if params == nil {
@ -60,6 +62,9 @@ func getHeliumApi(path string, params *map[string]string) ([]byte, error) {
return body, nil
}
// getHeliumApiWithCursor query a helium api with a cursor
// It will continue to query the api until all the cursors are exhausted. Combine all the
// responses in a single object.
func getHeliumApiWithCursor(path string, params *map[string]string) ([][]byte, error) {
// if params is nil, set it to an empty map
if params == nil {

View File

@ -5,6 +5,7 @@ import (
"fmt"
)
// query https://docs.helium.com/api/blockchain/stats#blockchain-stats
func GetBlockchainStats() (*BlockchainStats, error) {
path := "/v1/stats"