-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat(Scaler): Adds CouchDB Scaler #3804
Conversation
2bcc5f0
to
fe6862e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the slow response... Thanks a lot for the new scaler, I have left some comments inline.
In general, don't use fmt.Print
functions because there are loggers for doing it, following the log policy applied by end-users.
There are also error in static checks and also unit test are failing
CHANGELOG.md
Outdated
@@ -42,6 +42,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio | |||
- **General:** Introduce new Loki Scaler ([#3699](https://github.com/kedacore/keda/issues/3699)) | |||
- **General**: Add ratelimitting parameters to keda manager to allow override of client defaults ([#3730](https://github.com/kedacore/keda/issues/2920)) | |||
- **General**: Provide Prometheus metric with indication of total number of triggers per trigger type in `ScaledJob`/`ScaledObject`. ([#3663](https://github.com/kedacore/keda/issues/3663)) | |||
- **General:** Introduce new CouchDB Scaler ([#3746](https://github.com/kedacore/keda/issues/3746)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a style guide for the changelog, all entries should be alphabetically sorted, with the General section in the top (bit also sorted)
config/manager/kustomization.yaml
Outdated
@@ -5,5 +5,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 | |||
kind: Kustomization | |||
images: | |||
- name: ghcr.io/kedacore/keda | |||
newName: ghcr.io/kedacore/keda | |||
newName: docker.io/tanishabanik/keda |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undo this change please
@@ -10,5 +10,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 | |||
kind: Kustomization | |||
images: | |||
- name: ghcr.io/kedacore/keda-metrics-apiserver | |||
newName: ghcr.io/kedacore/keda-metrics-apiserver | |||
newName: docker.io/tanishabanik/keda-metrics-apiserver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undo this change please
pkg/scalers/couchdb_scaler.go
Outdated
"context" | ||
"encoding/json" | ||
"fmt" | ||
couchdb "github.com/go-kivik/couchdb/v3" | ||
"github.com/go-kivik/kivik/v3" | ||
"github.com/go-logr/logr" | ||
kedautil "github.com/kedacore/keda/v2/pkg/util" | ||
v2 "k8s.io/api/autoscaling/v2" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/metrics/pkg/apis/external_metrics" | ||
"strconv" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We split the import section in 3 blocks:
- golang
- deps
- keda
The static analyzer checks this indeed, that's one of the failures in static checks
pkg/scalers/couchdb_scaler.go
Outdated
var request couchDBQueryRequest | ||
err := json.Unmarshal([]byte(s.metadata.query), &request) | ||
if err != nil { | ||
fmt.Println("Couldn't unmarshal query string: ", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, don't print messages, we use loggers for that
dsn := fmt.Sprintf("http://admin:%s@test-release-svc-couchdb.%s.svc.cluster.local:5984/animals", password, testNamespace) | ||
cmd := "-vX PUT " + dsn | ||
fmt.Println("Splitted command: ", strings.Split(cmd, " ")) | ||
deployPod(kc, "activation", cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use templates for the sake of consistency
func deployPodDelete(kc *kubernetes.Clientset, podName, args string) { | ||
podSpec := &corev1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-pod-couchdb-" + podName, | ||
Namespace: testNamespace, | ||
}, | ||
Spec: corev1.PodSpec{ | ||
RestartPolicy: "OnFailure", | ||
Containers: []corev1.Container{ | ||
{ | ||
Name: "test-couchdb-container", | ||
Image: "nginx:alpine", | ||
Command: []string{"curl"}, | ||
Args: strings.Split(args, " "), | ||
}, | ||
}, | ||
}, | ||
} | ||
_, err := kc.CoreV1().Pods(testNamespace).Create(context.Background(), podSpec, metav1.CreateOptions{}) | ||
if err != nil { | ||
fmt.Println("Failed to create test pod: ", err) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, use templates for this
fmt.Printf("Rev id: %s-test", rev) | ||
fmt.Println() | ||
dsn := fmt.Sprintf("http://admin:%s@test-release-svc-couchdb.%s.svc.cluster.local:5984/animals/%s?rev=%s", password, testNamespace, uuid, rev) | ||
cmd := " -X DELETE " + dsn | ||
fmt.Println("curl" + cmd) | ||
fmt.Println("curl" + cmd) | ||
deployPodDelete(kc, name, cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as other lines
type PodLog struct { | ||
OK bool `json:"ok"` | ||
ID string `json:"id"` | ||
Rev string `json:"rev"` | ||
} | ||
|
||
func getPodLogs(kc *kubernetes.Clientset, podName string) (string, error) { | ||
podLogOpts := corev1.PodLogOptions{} | ||
req := kc.CoreV1().Pods(testNamespace).GetLogs(podName, &podLogOpts) | ||
podLogs, err := req.Stream(context.Background()) | ||
if err != nil { | ||
fmt.Println("error in opening stream: ", err) | ||
return "", err | ||
} | ||
defer podLogs.Close() | ||
|
||
buf := new(bytes.Buffer) | ||
_, err = io.Copy(buf, podLogs) | ||
if err != nil { | ||
fmt.Println("error in copy information from podLogs to buf: ", err) | ||
return "", err | ||
} | ||
str := buf.String() | ||
fmt.Println("Index: ", strings.Index(str, `"rev":`)) | ||
chars := str[strings.Index(str, `"rev":`)+7 : strings.Index(str, `}`)-1] | ||
fmt.Println(chars) | ||
fmt.Println("Type of chars: ", reflect.TypeOf(chars)) | ||
return chars, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a helper for this https://github.com/kedacore/keda/blob/main/tests/helper/helper.go#L507
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a customised pod log function, I am trying to get specific lines with some string ops
/run-e2e couch* |
func installCouchDB(t *testing.T) { | ||
_, err := ExecuteCommand(fmt.Sprintf("helm repo add couchdb %s", couchdbHelmRepo)) | ||
assert.NoErrorf(t, err, "cannot execute command - %s", err) | ||
_, err = ExecuteCommand("sudo helm repo update") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need sudo here? e2e test fails because sudo isn't installed in the agents
_, err = ExecuteCommand("sudo helm repo update") | ||
assert.NoErrorf(t, err, "cannot execute command - %s", err) | ||
uuid := generateUUID() | ||
_, err = ExecuteCommand(fmt.Sprintf("sudo helm install test-release --set couchdbConfig.couchdb.uuid=%s --namespace %s couchdb/couchdb", uuid, testNamespace)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need sudo here? e2e test fails because sudo isn't installed in the agents
@26tanishabanik any update on this please? we plan to do a release in ~2 weeks. |
Yes, @zroubalik , I will complete it by this weekend, have been busy with work |
cool, and no worries, if you are not able to make it, we will ship this in the next release. |
We are going to release KEDA v2.9 on Thursday. Do you think you can complete the open work by Wednesday @26tanishabanik? |
Yes @tomkerkhove , I can complete it by weekend itself |
Great, thank you! |
@26tanishabanik could you please fix the problems in Static Checks? and also the unit test failed:
|
/run-e2e couch* |
The problems in static checks were related to keda version unit test and duplicate lines of code |
What should I do about the duplicate lines of code? |
/run-e2e couch* |
@26tanishabanik there is still error in unit tests:
|
@26tanishabanik also, could you please fix the PR to contain only your commits? |
How can I do that @zroubalik |
@26tanishabanik to fix the Static Check, please add similar rule for this scaler: https://github.com/kedacore/keda/blob/cbdb405dc3f9936d100f39ee0a1c6c1f98c1c2dd/.golangci.yml |
Like this: Lines 87 to 89 in cbdb405
|
@26tanishabanik this could be tricky, sometimes might be better to use this approach:
|
also, |
Let me try that @zroubalik , thank you for the suggestion |
|
it depends how you have named your git remotes, see that in: |
@26tanishabanik feel free to ping me on slack about this |
Signed-off-by: 26tanishabanik <[email protected]>
4bbcc98
to
43a831d
Compare
Signed-off-by: 26tanishabanik <[email protected]>
Signed-off-by: 26tanishabanik <[email protected]>
Signed-off-by: 26tanishabanik <[email protected]>
Signed-off-by: Zbynek Roubalik <[email protected]>
Signed-off-by: Zbynek Roubalik <[email protected]>
/run-e2e couch* |
Provide a description of what has been changed
Checklist
Relates to #3746
Relates to kedacore/keda-docs#967