Skip to content

Commit

Permalink
[Web UI] Filter entities by given subscription (#1656)
Browse files Browse the repository at this point in the history
Signed-off-by: James Phillips <[email protected]>
  • Loading branch information
jamesdphillips authored Jun 18, 2018
1 parent f059bcd commit 4556e4e
Show file tree
Hide file tree
Showing 15 changed files with 1,150 additions and 98 deletions.
48 changes: 48 additions & 0 deletions backend/apid/graphql/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package graphql
import (
"errors"
"sort"
"strings"

"github.com/sensu/sensu-go/backend/apid/actions"
"github.com/sensu/sensu-go/backend/apid/graphql/globalid"
Expand All @@ -11,6 +12,7 @@ import (
"github.com/sensu/sensu-go/graphql"
"github.com/sensu/sensu-go/types"
"github.com/sensu/sensu-go/util/eval"
string_utils "github.com/sensu/sensu-go/util/strings"
)

var _ schema.EnvironmentFieldResolvers = (*envImpl)(nil)
Expand Down Expand Up @@ -283,3 +285,49 @@ func (r *envImpl) CheckHistory(p schema.EnvironmentCheckHistoryFieldResolverPara
limit := clampInt(p.Args.Limit, 0, len(history))
return history[0:limit], nil
}

// Subscriptions implements response to request for 'subscriptions' field.
func (r *envImpl) Subscriptions(p schema.EnvironmentSubscriptionsFieldResolverParams) (interface{}, error) {
set := string_utils.OccurrenceSet{}
env := p.Source.(*types.Environment)
ctx := types.SetContextFromResource(p.Context, env)

entities, err := r.entityCtrl.Query(ctx)
if err != nil {
return set, err
}
for _, entity := range entities {
newSet := occurrencesOfSubscriptions(entity)
set.Merge(newSet)
}

checks, err := r.checksCtrl.Query(ctx)
if err != nil {
return set, err
}
for _, check := range checks {
newSet := occurrencesOfSubscriptions(check)
set.Merge(newSet)
}

// If specified omit subscriptions prefix'd with 'entity:'
if p.Args.OmitEntity {
for _, subscription := range set.Values() {
if strings.HasPrefix(subscription, "entity:") {
set.Remove(subscription)
}
}
}

// Sort entries
subscriptionSet := newSubscriptionSet(set)
if p.Args.OrderBy == schema.SubscriptionSetOrders.ALPHA_DESC {
subscriptionSet.sortByAlpha(false)
} else if p.Args.OrderBy == schema.SubscriptionSetOrders.ALPHA_ASC {
subscriptionSet.sortByAlpha(true)
} else if p.Args.OrderBy == schema.SubscriptionSetOrders.OCCURRENCES {
subscriptionSet.sortByOccurrence()
}

return subscriptionSet, nil
}
158 changes: 134 additions & 24 deletions backend/apid/graphql/schema/environment.gql.go

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

Loading

0 comments on commit 4556e4e

Please sign in to comment.