Skip to content

[WIP] Add NATS Streaming as a new bus implementation#491

Closed
ghost wants to merge 16 commits into
masterfrom
unknown repository
Closed

[WIP] Add NATS Streaming as a new bus implementation#491
ghost wants to merge 16 commits into
masterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Oct 5, 2018

Fixes #

Proposed Changes

  • add NATS Streaming v.0.11.0 as a new bus implementation.
  • the messages are persisted 24h
  • the name of this bus to be used by a channel is "natss"

@knative-prow-robot knative-prow-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 5, 2018
Copy link
Copy Markdown
Contributor

@devguyio devguyio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@radufa I aded a couple of cosmetic comments. Will test locally and provide any extra feedback.

Comment thread config/buses/natss/100-natss.yaml Outdated
labels:
app: nats-streaming
spec:
# type: NodePort
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented line

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread config/buses/natss/100-natss.yaml Outdated
spec:
# type: NodePort
type: ClusterIP
# clusterIP: None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented line

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread config/buses/natss/README.md Outdated
1. Apply the 'natss' Bus `ko apply -f config/buses/natss/`
1. Create Channels that reference the 'natss' Bus

The NATSS-Streaming bus uses NATS-Streaming based on a simple setup, see [Natss Streaming](./100-natss.yaml) .
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NATS Streaming without a hyphen.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread pkg/buses/natss/bus.go Outdated
}
}
// subscribe to a NATSS subject
if natsStreamingSub, err := (*natsConn).Subscribe(channel.Name, mcb /*nmh.msgh*/, stan.DurableName(subscription.Name)); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the comment /*nmh.msgh*/

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread config/buses/natss/100-natss.yaml Outdated
apiVersion: v1
kind: Service
metadata:
name: nats-streaming-headless
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor naming comment: I suppose headless is used in case clusterIP:None. Please consider removing headless.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Contributor

@vaikas vaikas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll review rest later, just got through the yaml files.

# configuration file used to override default NATS server settings
stan.conf: |
# content of configuration file used to override default NATS Streaming server settings
kind: ConfigMap
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bit of a nit, could you organize this:
apiversion
kind
metadata
data

makes it easier to parse mentally :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

args:
- -D
- -SD
- --cluster_id=knative-nats-streaming
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this something that needs to be possibly updated when deploying?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a kind of a shared "security context" between all NATS Streaming servers running in a cluster and all their clients. Now it's only a simple deployment without clustering.

- "ReadWriteOnce"
resources:
requests:
storage: "1Gi"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for the persistence of the messages? If so, is there a way to get a rough idea how this might be tweaked depending on message rates / sizes, etc.?

Copy link
Copy Markdown
Author

@ghost ghost Oct 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is for persistence, for all messages... We have to improve the strategy for the persistence layer in the future, but it's enough for this simple example.

@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 5, 2018
@ghost
Copy link
Copy Markdown
Author

ghost commented Oct 5, 2018

/retest

1 similar comment
@ghost
Copy link
Copy Markdown
Author

ghost commented Oct 5, 2018

/retest

@grantr
Copy link
Copy Markdown
Contributor

grantr commented Oct 5, 2018

/cc @adamharwayne

Comment thread config/buses/natss/100-natss.yaml Outdated
selector:
app: nats-streaming
sessionAffinity: None
selector:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selector is defined twice.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted

Comment thread config/buses/natss/100-natss.yaml Outdated
kind: StatefulSet
metadata:
name: nats-streaming
namespace: default
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in the knative-eventing namespace?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is deployed now in knative-eventing namespace

requests:
cpu: "100m"
limits:
memory: "32M"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems low, is it enough?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's enough for this simple, not production ready, "bus" implementation. We will come later with a NATS Streaming cluster which will be deeper integrated into Eventing.

Comment thread pkg/buses/natss/bus.go Outdated
}
// subscribe to a NATSS subject
if natsStreamingSub, err := (*natsConn).Subscribe(channel.Name, mcb, stan.DurableName(subscription.Name)); err != nil {
bus.logger.Errorf(" Create new NATSS Subscription failed: %+v", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return err

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/buses/natss/bus.go Outdated
// unsubscribe from a NATSS subject
if natsStreamingSub, ok := bus.subscribers[subscription.Name]; ok {
if err := (*natsStreamingSub).Unsubscribe(); err != nil {
bus.logger.Errorf(" Unsubscribe() failed: %+v", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return err

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/buses/natss/bus.go Outdated
ProvisionFunc: func(channel buses.ChannelReference, parameters buses.ResolvedParameters) error {
bus.logger.Infof("Provision channel %q\n", channel.Name)
bus.logger.Info("channel=%+v; parameters=%+v", channel, parameters)
// TODO create a NATSS subject
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything to do? Aren't the subjects created with the subscriptions, rather than the bus itself? If so, I think we can simply not assign ProvisionFunc and UnprovisionFunc.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only a place holder now, cause the creation of a NATS Streaming subjects will be validated in the future, avoiding automatically (uncontrolled) creation.
For this simple implementation, this code is not necessary now. A subject is created, if necessary, with the subscription.
I'll delete it, if it has an impact of the clarity of this example.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference is to either fill out the TODO with what is actually planned or to remove them. But it is weakly held.

Comment thread pkg/buses/natss/stanutil/stanutil.go Outdated
}

// IsConnected ....
func IsConnected(sc *stan.Conn) (ok bool) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used, removed

Comment thread pkg/buses/natss/bus.go Outdated
const BusType = "natss"

type NatssBus struct {
natsConn *stan.Conn
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is used.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread pkg/buses/natss/bus.go Outdated
// TODO delete a NATSS subject
return nil
},
SubscribeFunc: func(channel buses.ChannelReference, subscription buses.SubscriptionReference, parameters buses.ResolvedParameters) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For ease of reading, can these be moved to functions on NatssBus?

SubscribeFunc: bus.subscribeFunc,
...

func (b *NatssBus) subscribeFunc(...)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread pkg/buses/natss/bus.go Outdated
// TODO delete a NATSS subject
return nil
},
SubscribeFunc: func(channel buses.ChannelReference, subscription buses.SubscriptionReference, parameters buses.ResolvedParameters) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think SubscribeFunc and UnsubscribeFunc should be set in the Dispatcher, not the Provisioner.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved

@ghost
Copy link
Copy Markdown
Author

ghost commented Oct 8, 2018

/retest

@bbrowning
Copy link
Copy Markdown
Contributor

The last integration test failures were due to an unrelated issue impacting all PRs that has been fixed. Submitting this one for testing again.

/test pull-knative-eventing-integration-tests

@ghost
Copy link
Copy Markdown
Author

ghost commented Oct 9, 2018

@adamharwayne I have done the changes proposed by you. Please have a look.

@n3wscott
Copy link
Copy Markdown
Contributor

n3wscott commented Oct 9, 2018

Should we add a new bus vs provisioner?

@ghost
Copy link
Copy Markdown
Author

ghost commented Oct 9, 2018

@n3wscott Are you referring to the Provisioner part of the bus implementation (see in this case the discussion with @adamharwayne)?

Copy link
Copy Markdown
Contributor

@adamharwayne adamharwayne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me. Please add some unit tests and I will be happy to approve.

Comment thread pkg/buses/natss/bus.go Outdated
return err
}
delete(bus.subscribers, subscription.Name)
bus.logger.Errorf(" Unsubscribe() successful.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Info

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread pkg/buses/natss/bus.go Outdated
}
}
// subscribe to a NATSS subject
aw, _ := time.ParseDuration("60s")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 * time.Minute

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread pkg/buses/natss/bus.go Outdated
ProvisionFunc: func(channel buses.ChannelReference, parameters buses.ResolvedParameters) error {
bus.logger.Infof("Provision channel %q\n", channel.Name)
bus.logger.Info("channel=%+v; parameters=%+v", channel, parameters)
// TODO create a NATSS subject
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference is to either fill out the TODO with what is actually planned or to remove them. But it is weakly held.

* limitations under the License.
*/

package stanutil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add unit tests for this package.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The unit tests are using NATS Streaming embedded.

Comment thread pkg/buses/natss/bus_test.go Outdated

import "testing"

func TestStub(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add in some tests.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamharwayne the NATS Streaming server can be embedded inside of the test process to run unit tests again a real NATS Streaming server. This implies vendoring the NATS Streaming server code in Eventing.
Of course, mocking NATS Streaming could be another solution.
Cause this is the first bus implementation which should add tests, please advise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far we haven't run the real implementations in unit tests, but it seems like a good idea as long as:

  1. It isn't flaky
  2. It doesn't take too long (upper bound of 1 minute to start with?).

I didn't realize that the other buses didn't have tests. If you don't vendor the NATS streaming server, then I would focus on testing the event handler functions (e.g. handles errors gracefully, only ACKs the message if the downstream acked, etc.).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll use the embedded NATS Streaming for the unit tests. It's stable and the startup time is aprox. 10s.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@googlebot
Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@ghost
Copy link
Copy Markdown
Author

ghost commented Oct 17, 2018

I signed it!

@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

@ghost
Copy link
Copy Markdown
Author

ghost commented Oct 17, 2018

/cc @adamharwayne

Copy link
Copy Markdown
Contributor

@adamharwayne adamharwayne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the tests! I suddenly see why none of our existing buses have tests...

Comment thread config/buses/natss/README.md Outdated
@@ -0,0 +1,11 @@
# Stub - Knative Bus
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Stub - Knative Bus
# NATS Streaming - Knative Bus

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

)

const (
clusterId = "knative-eventing"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run gofmt.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

func TestConnectPublishClose(t *testing.T) {
// connect
natsConn, err := Connect(clusterId, clientId, natssUrl, logger)
assert.Nil(t, err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think our standard way to do this is:

if err != nil {
  t.Error("Connect returned nil")
}

Replacing the error message as needed.

Copy link
Copy Markdown
Author

@ghost ghost Oct 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, also I've removed the "testify" from vendor


func TestConnectPublishClose(t *testing.T) {
// connect
natsConn, err := Connect(clusterId, clientId, natssUrl, logger)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this to defer closing here (well, just after checking if err is not nil).

defer Close(natsConn, logger)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if err != nil {
panic(err)
}
retCode := m.Run()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this to defer stopNatss here, now that we know the err is nil.

defer stopNatss(stanServer)
retCode := m.Run()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread pkg/buses/natss/bus_test.go Outdated
busProv.Run(1, stopCh, "test-provisioner-natss")
busDisp.Run(1, stopCh, "test-dispatcher-natss")

// create adummy channel
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adummy -> a dummy

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/buses/natss/bus_test.go Outdated
// wait for subscriber to respond
select {
case <-done: logger.Infof("Subscriber finished")
case <-time.After(5 * time.Second): logger.Info("Subscriber timeout")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this fail the test?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, done

Comment thread pkg/buses/natss/bus.go Outdated
func SetNewBusProvisioner(opts *buses.BusOpts) SetupNatssBus {
return func(b *NatssBus) error {
b.natsUrl = NatssUrl
b.provisioner = buses.NewBusProvisioner(b.ref, b.dispEventHandler, opts)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b.dispEventHandler -> b.provEventHandler

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/buses/natss/bus_test.go Outdated
busDisp, err := NewNatssBusDispatcher(ref, setNewTestBusDispatcher(t, opts))
assert.Nil(t, err)

stopCh := signals.SetupSignalHandler()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we defer closing/sending to this Channel?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/buses/natss/bus_test.go Outdated

// wait for subscriber to respond
select {
case <-done: logger.Infof("Subscriber finished")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the message payload.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Oct 19, 2018
@ghost
Copy link
Copy Markdown
Author

ghost commented Oct 19, 2018

/retest

@ghost
Copy link
Copy Markdown
Author

ghost commented Oct 19, 2018

/test pull-knative-eventing-unit-tests

1 similar comment
@ghost
Copy link
Copy Markdown
Author

ghost commented Oct 19, 2018

/test pull-knative-eventing-unit-tests

Copy link
Copy Markdown
Contributor

@adamharwayne adamharwayne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

)

func TestMain(m *testing.M) {
logger = buses.NewBusLoggerFromConfig(buses.NewLoggingConfig())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anything rely on the logs being written? E.g. something searches the log output to see if 'foobar' was written. Or does it just need a struct that has the right methods?

zap.NewNop() returns a valid logger, but the logs don't get written anywhere.

)

func TestMain(m *testing.M) {
logger = buses.NewBusLoggerFromConfig(buses.NewLoggingConfig())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Do we need the actual logs? Or just a logger (that writes to /dev/null)?

Comment thread pkg/buses/natss/bus.go
}
}

func SetNewBusProvisioner(opts *buses.BusOpts) SetupNatssBus {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for investigating. I think this is fine as-is for this PR.

I think we need to create a fake Reconciler (not in this PR, just in general to make this stuff testable). Then we could set it in the options and not need this workaround.

opts.Reconciler = FakeReconciler(),

As you call bus.Run(), just creating an empty Reconciler{} doesn't work either.

Random musing: Maybe we just need to make Reconciler an interface and swap out Run() to do nothing (as is done in the test file).

Copy link
Copy Markdown
Contributor

@n3wscott n3wscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the churn, we need to refactor this PR to use ClusterChannelProvisioners.

As it is, I don't think we want to commit any new changes to bus impls, we have changed directions a bit on what it means to back a channel.

@@ -0,0 +1,101 @@
apiVersion: v1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should actually be embedded into the controller for the provisioner for the natss channels. And then published into kubernetes when a channel is attempted to be provisioned with the natss cluster channel provisioner

@@ -0,0 +1,9 @@
# NATS Streaming - Knative Bus
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current model does not have busses and sorry to say that we will have to pivot this implementation to conform to the ideas of ClusterChannelProvisioners

Comment thread pkg/buses/natss/bus.go
ReceiveMessageFunc: func(channel buses.ChannelReference, message *buses.Message) error {
bus.logger.Infof("Recieved message from %q channel", channel.String())
if err := stanutil.Publish(natsConn, channel.Name, &message.Payload, bus.logger); err != nil {
bus.logger.Errorf("Error during publish: %+v", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zap wants you to wrap err in zap.Error(err) for pretty print.

Comment thread pkg/buses/natss/bus.go
bus.logger.Errorf("Error during publish: %+v", err)
return err
}
bus.logger.Infof("Published [%s] : '%s'", channel.String(), message)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not log the contents of the message. There is a huge risk to leak PII here.

Comment thread pkg/buses/natss/bus.go
var err error
for i := 0; i < 60; i++ {
if natsConn, err = stanutil.Connect("knative-nats-streaming", clientId, b.natssUrl, b.logger); err != nil {
b.logger.Errorf(" Create new connection failed: %+v", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zap.Error(err) for pretty print.

}

// Publish a message to a subject
func Publish(sc *stan.Conn, subj string, msg *[]byte, logger *zap.SugaredLogger) (err error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general, loggers should not be passed around, only context and then pull the logger from the context. There are examples in the repo to do this with the knative/pkg/logging helpers.

defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("recovered from: %v", r)
logger.Errorf("Publish(): %v", err.Error())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zap.Error(err) for pretty print.

}
err = (*sc).Publish(subj, *msg)
if err != nil {
logger.Errorf("Error during publish: %v\n", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zap.Error(err) for pretty print.

}()

if sc == nil {
err = errors.New("cant'publish on empty stan connection")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: -> "can't publish on empty stan connection"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likely it should be "can not publish on empty stan connection"

@@ -0,0 +1,73 @@
package stanutil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs knative header

@ghost
Copy link
Copy Markdown
Author

ghost commented Oct 29, 2018

Thanks a lot for reviews!
We will change the implementation to be aligned with the new ClusterChannelProvisioners.

@knative-metrics-robot
Copy link
Copy Markdown

The following is the coverage report on pkg/.
Say /test pull-knative-eventing-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/buses/natss/bus.go Do not exist 61.2%
pkg/buses/natss/dispatcher/main.go Do not exist 0.0%
pkg/buses/natss/provisioner/main.go Do not exist 0.0%
pkg/buses/natss/stanutil/stanutil.go Do not exist 57.7%

@knative-prow-robot
Copy link
Copy Markdown
Contributor

@radufa: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-knative-eventing-build-tests 8a77c45 link /test pull-knative-eventing-build-tests

Full PR test history. Your PR dashboard.

Details

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. I understand the commands that are listed here.

@ghost ghost changed the title Add NATS Streaming as a new bus implementation [WIP] Add NATS Streaming as a new bus implementation Nov 16, 2018
@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 16, 2018
@matzew
Copy link
Copy Markdown
Member

matzew commented Nov 19, 2018

@radufa I guess this can be closed - due to #624 ?

@ghost
Copy link
Copy Markdown
Author

ghost commented Nov 19, 2018

Close this PR cause it is replaced by the new one: "Add NATS Streaming provisioner", see: #624

@ghost ghost closed this Nov 19, 2018
pierDipi pushed a commit to pierDipi/eventing that referenced this pull request Jan 17, 2024
…knative#7250) (knative#491)

* Fixed eventtype create-delete loop on built in sources



* Fix unit tests



* Fixed source finalizers



* Fixed tests



---------

Signed-off-by: Calum Murray <cmurray@redhat.com>
Co-authored-by: Calum Murray <cmurray@redhat.com>
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Indicates the PR's author has signed the CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.