Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions cmd/frontend/graphqlbackend/parse_search_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ package graphqlbackend
import (
"context"

"github.com/sourcegraph/log"

"github.com/sourcegraph/sourcegraph/internal/database"
"github.com/sourcegraph/sourcegraph/internal/dotcom"
"github.com/sourcegraph/sourcegraph/internal/featureflag"
"github.com/sourcegraph/sourcegraph/internal/search"
"github.com/sourcegraph/sourcegraph/internal/search/client"
"github.com/sourcegraph/sourcegraph/internal/search/job"
"github.com/sourcegraph/sourcegraph/internal/search/job/jobutil"
"github.com/sourcegraph/sourcegraph/internal/search/job/printer"
Expand Down Expand Up @@ -63,7 +59,7 @@ func (r *schemaResolver) ParseSearchQuery(ctx context.Context, args *args) (stri
case ParseTree:
return outputParseTree(searchType, args)
case JobTree:
return outputJobTree(ctx, searchType, args, r.db, r.logger)
return outputJobTree(ctx, searchType, args, r.db)
}
return "", nil
}
Expand All @@ -89,7 +85,6 @@ func outputJobTree(
searchType query.SearchType,
args *args,
db database.DB,
logger log.Logger,
) (string, error) {
plan, err := query.Pipeline(query.Init(args.Query, searchType))
if err != nil {
Expand All @@ -105,7 +100,7 @@ func outputJobTree(
UserSettings: settings,
PatternType: searchType,
Protocol: search.Streaming,
Features: client.ToFeatures(featureflag.FromContext(ctx), logger),
Features: search.FeaturesFromContext(ctx),
OnSourcegraphDotCom: dotcom.SourcegraphDotComMode(),
}
j, err := jobutil.NewPlanJob(inputs, plan)
Expand Down
3 changes: 0 additions & 3 deletions internal/search/client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ go_library(
"//internal/conf",
"//internal/database",
"//internal/dotcom",
"//internal/featureflag",
"//internal/gitserver",
"//internal/search",
"//internal/search/job",
Expand All @@ -30,8 +29,6 @@ go_library(
"//lib/errors",
"//schema",
"@com_github_grafana_regexp//:regexp",
"@com_github_prometheus_client_golang//prometheus",
"@com_github_prometheus_client_golang//prometheus/promauto",
"@com_github_sourcegraph_log//:log",
"@io_opentelemetry_go_otel//attribute",
],
Expand Down
25 changes: 1 addition & 24 deletions internal/search/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"

"github.com/grafana/regexp"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"go.opentelemetry.io/otel/attribute"

"github.com/sourcegraph/log"
Expand All @@ -15,7 +13,6 @@ import (
"github.com/sourcegraph/sourcegraph/internal/conf"
"github.com/sourcegraph/sourcegraph/internal/database"
"github.com/sourcegraph/sourcegraph/internal/dotcom"
"github.com/sourcegraph/sourcegraph/internal/featureflag"
"github.com/sourcegraph/sourcegraph/internal/gitserver"
"github.com/sourcegraph/sourcegraph/internal/search"
"github.com/sourcegraph/sourcegraph/internal/search/job"
Expand Down Expand Up @@ -146,7 +143,7 @@ func (s *searchClient) Plan(
SearchMode: searchMode,
UserSettings: settings,
OnSourcegraphDotCom: s.sourcegraphDotComMode,
Features: ToFeatures(featureflag.FromContext(ctx), s.runtimeClients.Logger),
Features: search.FeaturesFromContext(ctx),
PatternType: searchType,
Protocol: protocol,
ContextLines: finalContextLines,
Expand Down Expand Up @@ -304,26 +301,6 @@ func overrideSearchType(input string, searchType query.SearchType) query.SearchT
return searchType
}

func ToFeatures(flagSet *featureflag.FlagSet, logger log.Logger) *search.Features {
if flagSet == nil {
flagSet = &featureflag.FlagSet{}
metricFeatureFlagUnavailable.Inc()
logger.Warn("search feature flags are not available")
}

// When adding a new feature flag remember to add it to the list in
// client/web/src/featureFlags/featureFlags.ts to allow overriding.
return &search.Features{
ContentBasedLangFilters: flagSet.GetBoolOr("search-content-based-lang-detection", false),
Debug: flagSet.GetBoolOr("search-debug", false),
}
}

var metricFeatureFlagUnavailable = promauto.NewCounter(prometheus.CounterOpts{
Name: "src_search_featureflag_unavailable",
Help: "temporary counter to check if we have feature flag available in practice.",
})

func getBoolPtr(b *bool, def bool) bool {
if b == nil {
return def
Expand Down
14 changes: 14 additions & 0 deletions internal/search/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,20 @@ type Features struct {
CodyFileMatcher func(repo api.RepoID, path string) bool `json:"-"`
}

func FeaturesFromContext(ctx context.Context) *Features {
flagSet := featureflag.FromContext(ctx)
if flagSet == nil {
flagSet = &featureflag.FlagSet{}
}

// When adding a new feature flag remember to add it to the list in
// client/web/src/featureFlags/featureFlags.ts to allow overriding.
return &Features{
ContentBasedLangFilters: flagSet.GetBoolOr("search-content-based-lang-detection", false),
Debug: flagSet.GetBoolOr("search-debug", false),
}
}

func (f *Features) String() string {
jsonObject, err := json.Marshal(f)
if err != nil {
Expand Down