Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
Signed-off-by: jojohappy <sarahdj0917@gmail.com>
  • Loading branch information
jojohappy committed Apr 9, 2019
1 parent ddd928a commit 14a3d33
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions pkg/store/prometheus.go
Expand Up @@ -375,16 +375,18 @@ func (p *PrometheusStore) LabelNames(ctx context.Context, r *storepb.LabelNamesR

if resp.StatusCode == http.StatusNoContent {
return &storepb.LabelNamesResponse{Names: []string{}}, nil
} else if m.Status != "success" {
}

if m.Status != "success" {
if !r.PartialResponseDisabled {
return &storepb.LabelNamesResponse{Names: m.Data}, nil
} else {
code, exists := statusToCode[resp.StatusCode]
if !exists {
code = codes.Internal
}
return nil, status.Error(code, m.Error)
}

code, exists := statusToCode[resp.StatusCode]
if !exists {
code = codes.Internal
}
return nil, status.Error(code, m.Error)
}

return &storepb.LabelNamesResponse{Names: m.Data}, nil
Expand Down Expand Up @@ -426,18 +428,21 @@ func (p *PrometheusStore) LabelValues(ctx context.Context, r *storepb.LabelValue
}

sort.Strings(m.Data)

if resp.StatusCode == http.StatusNoContent {
return &storepb.LabelValuesResponse{Values: []string{}}, nil
} else if m.Status != "success" {
}

if m.Status != "success" {
if !r.PartialResponseDisabled {
return &storepb.LabelValuesResponse{Values: m.Data}, nil
} else {
code, exists := statusToCode[resp.StatusCode]
if !exists {
code = codes.Internal
}
return nil, status.Error(code, m.Error)
}

code, exists := statusToCode[resp.StatusCode]
if !exists {
code = codes.Internal
}
return nil, status.Error(code, m.Error)
}

return &storepb.LabelValuesResponse{Values: m.Data}, nil
Expand Down

0 comments on commit 14a3d33

Please sign in to comment.