-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a prometheus server to broker ingress * correct method comment * Add a metrics port to the broker's ingress Service Ultimately access to this port might need different permissions than the default (ingress) port. * Always shut down runnableServer If ShutdownTimeout is not positive, call Shutdown anyway without a timeout. * Add port values to the ingress container spec These are informational, and more useful now that two ports are exposed. * Instrument message count and dispatch time Also register the exporter so it can start serving metrics. * Simplify runnableServer shutdown No need to select since we're just waiting for the channel to be closed. * Use a WaitGroup to stop runnableServers Manager doesn't actually wait for Runnables to stop, so we need to add a WaitGroup to wait for the HTTP Server Shutdown to complete. This is hopefully temporary until kubernetes-sigs/controller-runtime#350 is fixed. * Hook up internal controller-runtime logger * Include GCP auth library Running outside GCP seems to not work without this. * Translate commented code into a directive * Tag measurements with the broker name The BROKER environment variable may contain the broker name. If non-empty, measurements will be tagged with the given string. * Make BROKER env var required There's no use case for running this without an existing broker context, so just require the BROKER name to be present. * Add a separate shutdownTimeout var Currently the same as writeTimeout, but allows for having separate write and shutdown timeouts later. * Add a shutdown timer for the waitgroup wg.Wait() can block indefinitely. Adding a timer here ensures the process shutdown time is bounded. * Don't redeclare brokerName We want to use the package var here. * Move wg.Add outside the goroutine This eliminates a case in which wg.Done could be called before wg.Add depending on how the goroutine is scheduled. * Use Fatalf instead of Fatal * Update Gopkg.lock * Get broker name from env var BROKER It's now a struct field instead of a package var. * Use ok instead of success For consistency with HTTP error codes. * Test RunnableServer Tests ensure the server starts, responds to requests, and stops or shuts down as requested. * Set brokerName in handler struct This was accidentally removed in a merge. * Format and expand comments on shutdown behavior * Remove unnecessary comments * Update copyright year * Add test to verify correct usage of context Verifies that the context is correctly timing out shutdown. * Remove logging from RunnableServer Return the error instead and let the caller decide whether to log it. The ShutdownContext test now occasionally flakes; still tracking that down. * Attempt to document metrics Lists metrics exposed by Broker ingress and the port on which they're exposed. As we add metrics to other components, we can list them in this file. * Improve stability of shutdown test Request goroutine needs a bit more time to start sometimes. Removed Logf calls from goroutines since they sometimes happen after the test completes, causing a panic. Removed the error check from the http get for the same reason. * Rename logf to crlog Documents source of package more clearly. * Remove obsolete logger field from RunnableServer
- Loading branch information
1 parent
eb69716
commit 87d1bf9
Showing
8 changed files
with
734 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,90 @@ | ||
/* | ||
* Copyright 2019 The Knative 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 ( | ||
"go.opencensus.io/stats" | ||
"go.opencensus.io/stats/view" | ||
"go.opencensus.io/tag" | ||
) | ||
|
||
const ( | ||
metricsNamespace = "broker_ingress" | ||
) | ||
|
||
var ( | ||
// MeasureMessagesTotal is a counter which records the number of messages received | ||
// by the ingress. The value of the Result tag indicates whether the message | ||
// was filtered or dispatched. | ||
MeasureMessagesTotal = stats.Int64( | ||
"knative.dev/eventing/broker/ingress/measures/messages_total", | ||
"Total number of messages received", | ||
stats.UnitNone, | ||
) | ||
|
||
// MeasureDispatchTime records the time spent dispatching a message, in milliseconds. | ||
MeasureDispatchTime = stats.Int64( | ||
"knative.dev/eventing/broker/ingress/measures/dispatch_time", | ||
"Time spent dispatching a message", | ||
stats.UnitMilliseconds, | ||
) | ||
|
||
// Tag keys must conform to the restrictions described in | ||
// go.opencensus.io/tag/validate.go. Currently those restrictions are: | ||
// - length between 1 and 255 inclusive | ||
// - characters are printable US-ASCII | ||
|
||
// TagResult is a tag key referring to the observed result of an operation. | ||
TagResult = mustNewTagKey("result") | ||
|
||
// TagBroker is a tag key referring to the Broker name serviced by this | ||
// ingress process. | ||
TagBroker = mustNewTagKey("broker") | ||
) | ||
|
||
func init() { | ||
// Create views for exporting measurements. This returns an error if a | ||
// previously registered view has the same name with a different value. | ||
err := view.Register( | ||
&view.View{ | ||
Name: "messages_total", | ||
Measure: MeasureMessagesTotal, | ||
Aggregation: view.Count(), | ||
TagKeys: []tag.Key{TagResult, TagBroker}, | ||
}, | ||
&view.View{ | ||
Name: "dispatch_time", | ||
Measure: MeasureDispatchTime, | ||
Aggregation: view.Distribution(10, 100, 1000, 10000), | ||
TagKeys: []tag.Key{TagResult, TagBroker}, | ||
}, | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// mustNewTagKey creates a Tag or panics. This will only fail if the tag key | ||
// doesn't conform to tag name validations. | ||
// TODO OC library should provide this | ||
func mustNewTagKey(k string) tag.Key { | ||
tagKey, err := tag.NewKey(k) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return tagKey | ||
} |
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,10 @@ | ||
# Metrics | ||
|
||
This is a list of metrics exported by Knative Eventing components. | ||
|
||
## Broker ingress | ||
|
||
| Name | Type | Description | Tags | ||
| ---- | ---- | ---- | ---- | | ||
| `messages_total` | count | Number of messages received. | `result`, `broker` | | ||
| `dispatch_time` | histogram | Time to dispatch a message. | `result`, `broker` | |
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
Oops, something went wrong.