Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix. change buz logic for getting thanos url #166

Merged
merged 1 commit into from
Oct 23, 2023
Merged
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
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
Loading