-
Notifications
You must be signed in to change notification settings - Fork 138
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
Wrap the server with the Prometheus so we get metrics + add an e2e te… #267
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e2e1bd0
Wrap the server with the Prometheus so we get metrics + add an e2e te…
vaikas 9882981
oops :)
vaikas c452aae
Expose the prometheus port.
vaikas e2c9e21
Just dumping the metrics to see if they are there or not.
vaikas b01e06a
Working theory is that because there's 3 replicas, we get super duper
vaikas 8b26e61
Switch to single replica so we can scrape easier.
vaikas 0e487fb
Modify deployment in place instead of modifying the deployment.yaml.
vaikas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Copyright 2021 The Sigstore Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
dto "github.com/prometheus/client_model/go" | ||
"github.com/prometheus/common/expfmt" | ||
) | ||
|
||
const ( | ||
latencyMetric = "fulcio_api_latency" | ||
certMetric = "fulcio_new_certs" | ||
) | ||
|
||
func parseMF(url string) (map[string]*dto.MetricFamily, error) { | ||
resp, err := http.Get(url) // nolint | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
var parser expfmt.TextParser | ||
return parser.TextToMetricFamilies(resp.Body) | ||
} | ||
|
||
func main() { | ||
f := flag.String("url", "http://fulcio-server.fulcio-dev.svc:2112/metrics", "set url to fetch metrics from") | ||
flag.Parse() | ||
|
||
mf, err := parseMF(*f) | ||
if err != nil { | ||
log.Fatalf("Failed to fetch/parse metrics: %v", err) | ||
} | ||
|
||
// Just grab the api_latency metric, make sure it's a histogram | ||
// and just make sure there is at least one 200, and no errors there. | ||
latency, ok := mf[latencyMetric] | ||
if !ok || latency == nil { | ||
log.Fatal("Did not get fulcio_api_latency metric") | ||
} | ||
if err := checkLatency(latency); err != nil { | ||
log.Fatalf("fulcio_api_latency metric failed: %s", err) | ||
} | ||
|
||
// Then make sure the cert counter went up. | ||
certCount, ok := mf[certMetric] | ||
if !ok || certCount == nil { | ||
log.Fatal("Did not get fulcio_new_certs metric") | ||
} | ||
if err := checkCertCount(certCount); err != nil { | ||
log.Fatalf("fulcio_new_certs metric failed: %s", err) | ||
} | ||
} | ||
|
||
// Make sure latency is a Histogram, and it has a POST with a 201. | ||
func checkLatency(latency *dto.MetricFamily) error { | ||
if *latency.Type != *dto.MetricType_HISTOGRAM.Enum() { | ||
return fmt.Errorf("Wrong type, wanted %+v, got: %+v", dto.MetricType_HISTOGRAM.Enum(), latency.Type) | ||
} | ||
if len(latency.Metric) != 1 { | ||
return fmt.Errorf("Got multiple entries, or none for metric, wanted one, got: %+v", latency.Metric) | ||
} | ||
// Make sure there's a 'post' and it's a 201. | ||
var code string | ||
var method string | ||
for _, value := range latency.Metric[0].Label { | ||
if *value.Name == "code" { | ||
code = *value.Value | ||
} | ||
if *value.Name == "method" { | ||
method = *value.Value | ||
} | ||
} | ||
if code != "201" { | ||
return fmt.Errorf("unexpected code, wanted 201, got %s", code) | ||
} | ||
if method != "post" { | ||
return fmt.Errorf("unexpected method, wanted post, got %s", method) | ||
} | ||
|
||
if *latency.Metric[0].Histogram.SampleCount != 1 { | ||
return fmt.Errorf("Unexpected samplecount, wanted 1, got %d", *latency.Metric[0].Histogram.SampleCount) | ||
} | ||
return nil | ||
} | ||
|
||
func checkCertCount(certCount *dto.MetricFamily) error { | ||
if *certCount.Type != *dto.MetricType_COUNTER.Enum() { | ||
return fmt.Errorf("Wrong type, wanted %+v, got: %+v", dto.MetricType_COUNTER.Enum(), certCount.Type) | ||
} | ||
if len(certCount.Metric) != 1 { | ||
return fmt.Errorf("Got multiple entries, or none for metric, wanted one, got: %+v", certCount.Metric) | ||
} | ||
if *certCount.Metric[0].Counter.Value < 1 { | ||
return fmt.Errorf("Got incorrect cert count, wanted one, got: %f", *certCount.Metric[0].Counter.Value) | ||
} | ||
return nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the decorate handler mean fulcio would still function correctly without a running Prometheus instance present?What would happen to requests in that scenario?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nice part of the prometheus model is that it's pull based - exposing metrics with no instance is safe and a noop. A running collector would be needed to actually scrape these and do something useful with them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha, good for me.