-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add systest for poet registrations with PoW and cert
- Loading branch information
Showing
5 changed files
with
153 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,4 @@ cycle-gap="30s" | |
jsonlog="true" | ||
debuglog="true" | ||
|
||
pow-difficulty=4 | ||
|
||
metrics-port=8081 | ||
pow-difficulty=4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/prometheus/common/expfmt" | ||
) | ||
|
||
var errMetricNotFound = errors.New("metric not found") | ||
|
||
func fetchCounterMetric( | ||
ctx context.Context, | ||
url string, | ||
metricName string, | ||
labelFilters map[string]string, | ||
) (float64, error) { | ||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) | ||
if err != nil { | ||
return 0, fmt.Errorf("failed to create HTTP request: %v", err) | ||
} | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
return 0, fmt.Errorf("failed to fetch metrics: %v", err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
parser := expfmt.TextParser{} | ||
metricFamilies, err := parser.TextToMetricFamilies(resp.Body) | ||
if err != nil { | ||
return 0, fmt.Errorf("failed to parse metric families: %v", err) | ||
} | ||
|
||
metricFamily, ok := metricFamilies[metricName] | ||
if !ok { | ||
return 0, fmt.Errorf("metric not found: %s", metricName) | ||
} | ||
|
||
for _, metric := range metricFamily.Metric { | ||
if metric.Counter != nil { | ||
// Check if the metric has the specified labels | ||
labels := make(map[string]string) | ||
for _, lp := range metric.Label { | ||
labels[lp.GetName()] = lp.GetValue() | ||
} | ||
|
||
matches := true | ||
for key, value := range labelFilters { | ||
if labels[key] != value { | ||
matches = false | ||
break | ||
} | ||
} | ||
|
||
if matches { | ||
return metric.GetCounter().GetValue(), nil | ||
} | ||
} | ||
} | ||
|
||
return 0, errMetricNotFound | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters