Skip to content

Commit

Permalink
pull events only when subscribed (#74)
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Ding <jackding@gmail.com>
  • Loading branch information
jzding authored Jul 30, 2024
1 parent e6c7d98 commit e7a8771
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.0
github.com/prometheus/client_golang v1.14.0
github.com/redhat-cne/sdk-go v1.0.1-0.20240716153735-19a18fd38ee6
github.com/redhat-cne/sdk-go v1.0.1-0.20240730145324-f9bea0ca99c7
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.8.0
golang.org/x/net v0.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI
github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc=
github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo=
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
github.com/redhat-cne/sdk-go v1.0.1-0.20240716153735-19a18fd38ee6 h1:TYW1M1qUC51tN5nIy3cRwNFDn/M7E81jbtIthzyTwQ8=
github.com/redhat-cne/sdk-go v1.0.1-0.20240716153735-19a18fd38ee6/go.mod h1:q9LxxPbK1tGpDbQm/KIPujqdP0bK1hhuHrIXV3vuUrM=
github.com/redhat-cne/sdk-go v1.0.1-0.20240730145324-f9bea0ca99c7 h1:Ef4rxp3TCCFcCmkmPKFhFMartnms9OnNrPF0a/DbbFo=
github.com/redhat-cne/sdk-go v1.0.1-0.20240730145324-f9bea0ca99c7/go.mod h1:q9LxxPbK1tGpDbQm/KIPujqdP0bK1hhuHrIXV3vuUrM=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
Expand Down
8 changes: 8 additions & 0 deletions v2/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ func (s *Server) getCurrentState(w http.ResponseWriter, r *http.Request) {
respondWithError(w, "resourceAddress can not be empty")
return
}

//identify publisher or subscriber is asking for status
var sub *pubsub.PubSub
if len(s.pubSubAPI.GetSubscriptions()) > 0 {
Expand All @@ -449,13 +450,20 @@ func (s *Server) getCurrentState(w http.ResponseWriter, r *http.Request) {
}

if sub == nil {
respondWithStatusCode(w, http.StatusNotFound, fmt.Sprintf("subscriptions not found for %s", resourceAddress))
return
}

eventSubscribers := s.subscriberAPI.GetClientIDAddressByResource(resourceAddress)
if len(eventSubscribers) == 0 {
respondWithStatusCode(w, http.StatusNotFound, fmt.Sprintf("subscription not found for %s", resourceAddress))
return
}

if !strings.HasPrefix(resourceAddress, "/") {
resourceAddress = fmt.Sprintf("/%s", resourceAddress)
}

// this is placeholder not sending back to report
out := channel.DataChan{
Address: resourceAddress,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ github.com/prometheus/common/model
github.com/prometheus/procfs
github.com/prometheus/procfs/internal/fs
github.com/prometheus/procfs/internal/util
# github.com/redhat-cne/sdk-go v1.0.1-0.20240716153735-19a18fd38ee6
# github.com/redhat-cne/sdk-go v1.0.1-0.20240730145324-f9bea0ca99c7
## explicit; go 1.22
github.com/redhat-cne/sdk-go/pkg/channel
github.com/redhat-cne/sdk-go/pkg/common
Expand Down

0 comments on commit e7a8771

Please sign in to comment.