-
Notifications
You must be signed in to change notification settings - Fork 225
Initial implementation of a Prometheus source #663
Conversation
Hi @syedriko. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/cc @matzew |
/ok-to-test |
// ServiceAccountName holds the name of the Kubernetes service account | ||
// as which the underlying K8s resources should be run. If unspecified | ||
// this will default to the "default" service account for the namespace | ||
// in which the CouchDbSource exists. |
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.
nit: PrometheusSource
} | ||
) | ||
|
||
// Reconciler reconciles a CouchDbSource object |
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.
nit: PrometheusSource
eventTypes := make([]eventingv1alpha1.EventType, 0) | ||
|
||
// Only create EventTypes for Broker sinks. | ||
// We add this check here in case the CouchDbSource was changed from Broker to non-Broker sink. |
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.
same (CouchDb->Prometheus)
prometheus/pkg/adapter/adapter.go
Outdated
func (a *prometheusAdapter) makeEvent(payload interface{}) (*cloudevents.Event, error) { | ||
event := cloudevents.NewEvent() | ||
event.SetSource(a.source) | ||
event.SetID(`prometheus_source_adapter_id`) |
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.
Source + ID must be unique.
What about documenting it by adding the CloudEvents adapter spec for Prometheus? (see https://github.com/cloudevents/spec/blob/master/adapters/github.md for an example)
(I'm doing the same for CouchDB)
func newAdapterTestClient() *adapterTestClient { | ||
return &adapterTestClient{ | ||
kncetesting.NewTestClient(), | ||
make(chan struct{}), |
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.
you might need a buffered channel size 1, as the read/write is done in the same goroutine.
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} | ||
|
||
AddToScheme = SchemeBuilder.AddToScheme |
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.
need to add the knownTypes. See https://github.com/knative/eventing-contrib/pull/661/files#diff-72f3ea7d0a1d6e4cb62509e5f562de91R48
return nil | ||
} | ||
|
||
func (r *Reconciler) getReceiveAdapterImage() string { |
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.
Heads-up: when this PR gets merged we should do the same, which is to set the adapter image in controller
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.
Sure thing.
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.
@syedriko @lionelvillard it got merged!
Name: "PROMETHEUS_PROM_QL", | ||
Value: spec.PromQL, | ||
}, { | ||
Name: "SYSTEM_NAMESPACE", |
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.
should be NAMESPACE
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.
Fixed.
FieldRef: &corev1.ObjectFieldSelector{ | ||
FieldPath: "metadata.namespace", | ||
}, | ||
}, |
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.
METRICS_DOMAIN, K_METRICS_CONFIG and K_LOGGING_CONFIG are missing. Can added after this PR is merged.
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 do.
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.
@syedriko just seeing this, but I added the required bits, se:
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.
Thanks, @matzew, I merged your branch.
fc19213
to
d166dd7
Compare
prometheus/pkg/adapter/adapter.go
Outdated
} | ||
|
||
func (a *prometheusAdapter) makeEvent(payload interface{}) (*cloudevents.Event, error) { | ||
event := cloudevents.NewEvent() |
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.
cloudevents.VersionV03
as argument ?
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.
Added
prometheus/README.md
Outdated
kind: PrometheusSource | ||
metadata: | ||
name: prometheus-source | ||
namespace: knative-sources |
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.
let's remove this ns
, so (like other samples), it goes to default
.
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.
Fixed.
prometheus/demo/sink.yaml
Outdated
kind: Service | ||
metadata: | ||
name: event-display | ||
namespace: knative-sources |
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.
remove ns
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.
Removed
prometheus/demo/source.yaml
Outdated
kind: PrometheusSource | ||
metadata: | ||
name: prometheus-source | ||
namespace: knative-sources |
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.
remove ns
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.
Removed
@@ -0,0 +1,12 @@ | |||
apiVersion: sources.eventing.knative.dev/v1alpha1 | |||
kind: PrometheusSource |
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.
I get:
2019/10/22 10:22:03 Error processing env var: required key K_METRICS_CONFIG missing value
Got it running:
as said in the comments, other sources are on CE 0.3 - let's update that |
|
||
func (a *prometheusAdapter) makeEvent(payload interface{}) (*cloudevents.Event, error) { | ||
event := cloudevents.NewEvent() | ||
event.SetSource(a.source) |
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.
I think we should use something better here.
for instance in the kafka source, we add some context to it, like:
// KafkaEventSource returns the Kafka CloudEvent source.
func KafkaEventSource(namespace, kafkaSourceName, topic string) string {
return fmt.Sprintf("/apis/v1/namespaces/%s/kafkasources/%s#%s", namespace, kafkaSourceName, topic)
}
were that is used as:
...
event.SetSource(sourcesv1alpha1.KafkaEventSource(a.Namespace, a.Name, msg.Topic))
...
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.
Addressed
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.
Sweet! Couple of tweaks wrt the api definition.
serverURL: | ||
type: string | ||
promQL: | ||
type: string |
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.
Could we add "description" fields here as per:
https://github.com/knative/eventing/blob/master/docs/spec/sources.md
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.
We sure can
// Sink is a reference to an object that will resolve to a domain | ||
// name to use as the sink. | ||
// +optional | ||
Sink *corev1.ObjectReference `json:"sink,omitempty"` |
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.
This should be a Destination:
https://github.com/knative/eventing/blob/master/docs/spec/sources.md
And we should also have CloudEventOverrides here as well.
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.
I'd like to push back on this if that's ok. Can we merge this PR as it stands wrt sinks and ceOverrides and do the conversion of sinks to Destinations across the board in all the sources?
It would be nice to update https://github.com/knative/eventing/blob/master/pkg/duck/sinks.go to retrieve URIs from Destinations according to https://github.com/knative/eventing/blob/master/docs/spec/sources.md, update vendored knative.dev/pkg and knative.dev/eventing in eventing-contrib.
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.
I agree w/ @syedriko on this subject
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.
Keeping it consistent and doing conversion and testing (and upgrade docs if needed) for all sources in contrib sounds good to me
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"knative.dev/pkg/apis/duck" | ||
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" |
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.
Might as well use duck v1 instead of the v1beta1?
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.
We sure might
|
||
// PrometheusSourceStatus defines the observed state of PrometheusSource | ||
type PrometheusSourceStatus struct { | ||
// inherits duck/v1alpha1 Status, which currently provides: |
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.
v1alpha1 => v1
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.
Yep
// Check that Prometheus source can be validated and can be defaulted. | ||
var _ runtime.Object = (*PrometheusSource)(nil) | ||
|
||
// Check that we can create OwnerReferences to a Configuration. |
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.
s/Configuration/Prometheus Source/?
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.
Of course.
d166dd7
to
b0eaa57
Compare
prometheus/pkg/adapter/adapter.go
Outdated
} | ||
|
||
func (a *prometheusAdapter) Start(stopCh <-chan struct{}) error { | ||
return wait.PollUntil(5*time.Second, a.send, stopCh) |
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.
I think wait.Until
is better here. PollUntil
stops when there is an error, meaning that the adapter will stop running when an event couldn't be sent, which is not what we want. Instead we should log the error (for now) and keep going.
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.
I was wondering about that, too, tbh. And the hardcoded interval here.
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.
In that vein, https://github.com/knative/eventing/blob/ec4dcbbd5c35079dcbab80a94d22000338dda55b/pkg/adapter/main.go#L43 shouldn't return anything.
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.
Maybe. I'm not so sure that all errors can be caught at initialization time. But this is something to consider.
/lgtm Leaving the final |
*reconciler.Base | ||
|
||
receiveAdapterImage string | ||
once sync.Once |
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.
not used?
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.
evidently not
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: matzew, syedriko The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
3477a8e
to
ff9cd64
Compare
Squashed the commits. Can I be accepted into the knative org or should I remove myself from OWNERS_ALIASES? The question went to knative-admins@googlegroups.com. |
The following is the coverage report on the affected files.
|
/verify-owners |
/lgtm |
This is a barebones implementation of a Prometheus source for Knative Eventing.
It addresses #612.