Skip to content

Commit

Permalink
bugfix. change buz logic for getting thanos url
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkfree committed Oct 23, 2023
1 parent 1580951 commit 88bbdce
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
7 changes: 5 additions & 2 deletions internal/helper/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ func IsDurationExpired(targetTime time.Time, duration time.Duration) bool {
}

func SplitAddress(url string) (address string, port int) {
url = strings.TrimSuffix(url, "\n")
arr := strings.Split(url, ":")
address = arr[0] + ":" + arr[1]
port, _ = strconv.Atoi(arr[2])

port, err := strconv.Atoi(arr[2])
if err != nil {
log.Error(err)
}
return
}

Expand Down
44 changes: 31 additions & 13 deletions internal/usecase/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,28 +418,46 @@ func (u *DashboardUsecase) getThanosUrl(organizationId string) (out string, err
return out, fmt.Errorf("Invalid primary clusterId")
}

clientset_user, err := kubernetes.GetClientFromClusterId(organization.PrimaryClusterId)
clientset_admin, err := kubernetes.GetClientAdminCluster()
if err != nil {
return out, errors.Wrap(err, "Failed to get client set for user cluster")
}
service, err := clientset_user.CoreV1().Services("lma").Get(context.TODO(), "thanos-query-frontend", metav1.GetOptions{})

// tks-endpoint-secret 이 있다면 그 secret 내의 endpoint 를 사용한다.
secrets, err := clientset_admin.CoreV1().Secrets(organization.PrimaryClusterId).Get(context.TODO(), "tks-endpoint-secret", metav1.GetOptions{})
if err != nil {
service, err = clientset_user.CoreV1().Services("lma").Get(context.TODO(), "thanos-query", metav1.GetOptions{})
log.Info("cannot found tks-endpoint-secret. so use LoadBalancer...")

clientset_user, err := kubernetes.GetClientFromClusterId(organization.PrimaryClusterId)
if err != nil {
return out, errors.Wrap(err, "Failed to get services.")
return out, errors.Wrap(err, "Failed to get client set for user cluster")
}
}

// LoadBalaner 일경우, aws address 형태의 경우만 가정한다.
if service.Spec.Type != "LoadBalancer" {
return out, fmt.Errorf("Service type is not LoadBalancer. [%s] ", service.Spec.Type)
}
service, err := clientset_user.CoreV1().Services("lma").Get(context.TODO(), "thanos-query-frontend", metav1.GetOptions{})
if err != nil {
service, err = clientset_user.CoreV1().Services("lma").Get(context.TODO(), "thanos-query", metav1.GetOptions{})
if err != nil {
return out, errors.Wrap(err, "Failed to get services.")
}
}

// LoadBalaner 일경우, aws address 형태의 경우만 가정한다.
if service.Spec.Type != "LoadBalancer" {
return out, fmt.Errorf("Service type is not LoadBalancer. [%s] ", service.Spec.Type)
}

lbs := service.Status.LoadBalancer.Ingress
ports := service.Spec.Ports
if len(lbs) > 0 && len(ports) > 0 {
out = ports[0].TargetPort.StrVal + "://" + lbs[0].Hostname + ":" + strconv.Itoa(int(ports[0].Port))
lbs := service.Status.LoadBalancer.Ingress
ports := service.Spec.Ports
if len(lbs) > 0 && len(ports) > 0 {
out = ports[0].TargetPort.StrVal + "://" + lbs[0].Hostname + ":" + strconv.Itoa(int(ports[0].Port))
u.cache.Set(prefix+organizationId, out, gcache.DefaultExpiration)
return out, nil
}
} else {
out = "http://" + string(secrets.Data["thanos"])
log.Info("thanosUrl : ", out)
u.cache.Set(prefix+organizationId, out, gcache.DefaultExpiration)
return out, nil
}

return
Expand Down

0 comments on commit 88bbdce

Please sign in to comment.