Skip to content

Commit

Permalink
fix(detected_fields): fix issues with frontend integration (#12406)
Browse files Browse the repository at this point in the history
This PRs fixes issues we found when integrating with the frontend
* the `/experimental` api made it difficult to interact with using the existing datasource, so move to `v1/detected_fields`
* the config flag was considered cumbersome as the only potential negative impact of the endpoint is when it is used, and nothing is currently using it
* the use of an enum in the protobuf produced unexpected results in the json, so type was converted to string
  • Loading branch information
trevorwhitney authored Mar 29, 2024
1 parent b286075 commit 246623f
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 289 deletions.
53 changes: 0 additions & 53 deletions cmd/loki/loki-local-experimental-config.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions docs/sources/configure/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,6 @@ The `frontend` block configures the Loki query-frontend.
# The TLS configuration.
[tail_tls_config: <tls_config>]
# Whether to enable experimental APIs in the frontend.
# CLI flag: -frontend.experimental-apis-enabled
[experimental_apis_enabled: <boolean> | default = false]
```

### query_range
Expand Down
18 changes: 12 additions & 6 deletions pkg/logproto/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,17 @@ func (m *Shard) SpaceFor(stats *IndexStatsResponse, targetShardBytes uint64) boo
return newDelta <= curDelta
}

type DetectedFieldType string

const (
DetectedFieldString DetectedFieldType = 0
DetectedFieldInt DetectedFieldType = 1
DetectedFieldFloat DetectedFieldType = 2
DetectedFieldBoolean DetectedFieldType = 3
DetectedFieldDuration DetectedFieldType = 4
DetectedFieldBytes DetectedFieldType = 5
DetectedFieldString DetectedFieldType = "string"
DetectedFieldInt DetectedFieldType = "int"
DetectedFieldFloat DetectedFieldType = "float"
DetectedFieldBoolean DetectedFieldType = "boolean"
DetectedFieldDuration DetectedFieldType = "duration"
DetectedFieldBytes DetectedFieldType = "bytes"
)

func (d DetectedFieldType) String() string {
return string(d)
}
383 changes: 177 additions & 206 deletions pkg/logproto/logproto.pb.go

Large diffs are not rendered by default.

11 changes: 1 addition & 10 deletions pkg/logproto/logproto.proto
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,8 @@ message DetectedFieldsResponse {
repeated DetectedField fields = 1;
}

enum DetectedFieldType {
STRING = 0;
INT = 1;
FLOAT = 2;
BOOL = 3;
DURATION = 4;
BYTES = 5;
}

message DetectedField {
string label = 1;
DetectedFieldType type = 2;
string type = 2 [(gogoproto.casttype) = "DetectedFieldType"];
uint64 cardinality = 3;
}
5 changes: 1 addition & 4 deletions pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ func (t *Loki) initQueryFrontend() (_ services.Service, err error) {
t.Server.HTTP.Path("/loki/api/v1/labels").Methods("GET", "POST").Handler(frontendHandler)
t.Server.HTTP.Path("/loki/api/v1/label/{name}/values").Methods("GET", "POST").Handler(frontendHandler)
t.Server.HTTP.Path("/loki/api/v1/series").Methods("GET", "POST").Handler(frontendHandler)
t.Server.HTTP.Path("/loki/api/v1/detected_fields").Methods("GET", "POST").Handler(frontendHandler)
t.Server.HTTP.Path("/loki/api/v1/index/stats").Methods("GET", "POST").Handler(frontendHandler)
t.Server.HTTP.Path("/loki/api/v1/index/shards").Methods("GET", "POST").Handler(frontendHandler)
t.Server.HTTP.Path("/loki/api/v1/index/volume").Methods("GET", "POST").Handler(frontendHandler)
Expand All @@ -1056,10 +1057,6 @@ func (t *Loki) initQueryFrontend() (_ services.Service, err error) {
t.Server.HTTP.Path("/api/prom/tail").Methods("GET", "POST").Handler(defaultHandler)
}

if t.Cfg.Frontend.ExperimentalAPIsEnabled {
t.Server.HTTP.Path("/loki/api/experimental/detected_fields").Methods("GET", "POST").Handler(frontendHandler)
}

if t.frontend == nil {
return services.NewIdleService(nil, func(_ error) error {
if t.stopper != nil {
Expand Down
3 changes: 0 additions & 3 deletions pkg/lokifrontend/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ type Config struct {

TailProxyURL string `yaml:"tail_proxy_url"`
TLS tls.ClientConfig `yaml:"tail_tls_config"`

ExperimentalAPIsEnabled bool `yaml:"experimental_apis_enabled"`
}

// RegisterFlags adds the flags required to config this to the given FlagSet.
Expand All @@ -34,5 +32,4 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.BoolVar(&cfg.CompressResponses, "querier.compress-http-responses", true, "Compress HTTP responses.")
f.StringVar(&cfg.DownstreamURL, "frontend.downstream-url", "", "URL of downstream Loki.")
f.StringVar(&cfg.TailProxyURL, "frontend.tail-proxy-url", "", "URL of querier for tail proxy.")
f.BoolVar(&cfg.ExperimentalAPIsEnabled, "frontend.experimental-apis-enabled", false, "Whether to enable experimental APIs in the frontend.")
}
4 changes: 2 additions & 2 deletions pkg/querier/queryrange/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ func (c Codec) EncodeRequest(ctx context.Context, r queryrangebase.Request) (*ht
}

u := &url.URL{
Path: "/loki/api/experimental/detected_fields",
Path: "/loki/api/v1/detected_fields",
RawQuery: params.Encode(),
}
req := &http.Request{
Expand Down Expand Up @@ -904,7 +904,7 @@ func (c Codec) Path(r queryrangebase.Request) string {
case *logproto.VolumeRequest:
return "/loki/api/v1/index/volume_range"
case *DetectedFieldsRequest:
return "/loki/api/experimental/detected_fields"
return "/loki/api/v1/detected_fields"
}

return "other"
Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/queryrange/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func getOperation(path string) string {
return VolumeRangeOp
case path == "/loki/api/v1/index/shards":
return IndexShardsOp
case path == "/loki/api/experimental/detected_fields":
case path == "/loki/api/v1/detected_fields":
return DetectedFieldsOp
default:
return ""
Expand Down

0 comments on commit 246623f

Please sign in to comment.