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

fix: improve backend testsuite #1120

Merged
merged 24 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7292606
fix: change test command to look for tests in all folders except dash…
Traxmaxx Oct 20, 2023
4c5e9ff
Merge branch 'develop' of github.com:tailwarden/komiser into feature/…
Traxmaxx Oct 20, 2023
7dba083
fix: fix N2 instance types and refactor calculateMachineHourly test
Traxmaxx Oct 20, 2023
76c7a83
fix: improve typecasting and make it dry
Traxmaxx Oct 20, 2023
94dd271
fix: update contribution guidelines with test instructions
Traxmaxx Oct 20, 2023
dcb8c2e
fix: improve contribution guidelines formatting for backend
Traxmaxx Oct 20, 2023
086d68a
fix: improve contribution guidelines formatting for backend
Traxmaxx Oct 20, 2023
e6ce760
fix: remove installation instructions from contributing guidelines
Traxmaxx Oct 20, 2023
d327fef
fix: add tests for all remaining machine instances
Traxmaxx Oct 20, 2023
98af742
fix: fix machine instance types price map for GCP
Traxmaxx Oct 20, 2023
e83dc56
fix: formatting
Traxmaxx Oct 20, 2023
e16da59
fix: fix typeGetterN2D
Traxmaxx Oct 20, 2023
4674aa5
fix: fix typeGetterN1
Traxmaxx Oct 20, 2023
33ad61d
fix: fix typeGetterC2D
Traxmaxx Oct 20, 2023
96cb2f8
Merge branch 'develop' of github.com:tailwarden/komiser into feature/…
Traxmaxx Oct 20, 2023
6a58d67
fix: fix Feedback Toast components import in Feedback Widget
Traxmaxx Oct 20, 2023
90c5d0d
fix: fix Feedback Toast components import in Feedback Widget
Traxmaxx Oct 20, 2023
55eb162
fix: add ts-ignore for story
Traxmaxx Oct 20, 2023
d6848fd
fix: add multiple prop to feedback widget and fix close button
Traxmaxx Oct 20, 2023
5f82c87
fix: adress review comment and remove outcommented logging
Traxmaxx Oct 23, 2023
2d29a04
Merge branch 'develop' of github.com:tailwarden/komiser into feature/…
Traxmaxx Oct 23, 2023
4b9da22
fix: change props and update css
Traxmaxx Oct 24, 2023
db80b10
Merge branch 'develop' of github.com:tailwarden/komiser into feature/…
Traxmaxx Oct 26, 2023
6106333
Merge branch 'develop' into feature/tech-1706
mlabouardy Oct 27, 2023
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
78 changes: 45 additions & 33 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,33 +108,18 @@ The core Komiser Engine is written in Go (Golang) and leverages Go Modules. Here
2. 🔧 **GOPATH**:
- Ensure that the **`GOPATH`** environment variable is configured appropriately.

---

## 🛠️ Komiser Installation

### **Step 1: Installing Komiser CLI**
Follow the instructions in the [documentation](https://docs.komiser.io/getting-started/installation) to install the **Komiser CLI** for your operating system.

### **Step 2: Connect to a Cloud Account**
To deploy a **self-hosted (local) instance** of Komiser, connect your Komiser CLI to a cloud account of your choice. Refer to the documentation of the [supported cloud providers](https://docs.komiser.io/configuration/cloud-providers/aws).

### **Step 3: Accessing the Komiser UI**
Access the dashboard UI at **`http://localhost:3002`** once the local Komiser instance is running.

![komiser-dashboard](https://hackmd.io/_uploads/Syo0bMtgT.png)

---

## 🌟 Ways to Contribute to Komiser Engine

Komiser is an open-source cloud-agnostic resource manager. It helps you break down cloud resource costs at the resource level. As a cloud-agnostic cloud management tool, we always have more providers and cloud services to add, update, and cost-calculate.

### 1️⃣ Adding a new Cloud Provider

- Step 1: Create **`provider_name.go`** in **`providers/provider_name`** directory.
### ☁️ Adding a new Cloud Provider

- Step 2: Add the following boilerplate:
#### 1️⃣ Create provider.
Create `provider_name.go` in `providers/provider_name` directory.

#### 2️⃣ Add the following boilerplate:
```go
package PROVIDER_NAME

Expand Down Expand Up @@ -164,7 +149,8 @@ func FetchProviderData(ctx context.Context, client ProviderClient, db *bun.DB) {
}
```

- Step 3: Add SDK client details in [**`providers/provider.go`**](https://github.com/tailwarden/komiser/blob/develop/providers/providers.go):
#### 3️⃣ Add SDK client details:
Add your client details to [**`providers/provider.go`**](https://github.com/tailwarden/komiser/blob/develop/providers/providers.go)

```go
type ProviderClient struct {
Expand All @@ -188,7 +174,8 @@ type AzureClient struct {
}
```

- **Step 4:** Add provider configuration in TOML format in **`config.toml`**:
#### 4️⃣ Add provider configuration:
Add provider configuration in TOML format in **`config.toml`**

```toml
[[gcp]]
Expand All @@ -198,27 +185,27 @@ source="ENVIRONMENT_VARIABLES"
profile="production"
```

- **Step 5:** Compile a new Komiser binary:

#### 5️⃣ Compile a new Komiser binary:
```bash
go build
```

- **Step 6:** Start a new Komiser development server:
#### 6️⃣ Start a new Komiser development server:

```bash
./komiser start
```

### 2️⃣ Adding a new Cloud Service/Resource
### 🔋 Adding a new Cloud Service/Resource

Here are the general steps to add a new service/resource for a cloud provider in Komiser:

**Step 1:**
Create a new file **`servicename.go`** under the path **`providers/provider_name/servicename`**
#### 1️⃣ Create Service
Create a new file `servicename.go` under the path `providers/provider_name/servicename`

**Step 2:**
#### 2️⃣ Add boilerplate
Add the following boilerplate code, which defines the structure of any new service/resource to be added for a cloud provider:

```go
package service

Expand All @@ -243,10 +230,10 @@ func MyServiceResources(ctx context.Context, client ProviderClient) ([]Resource,

To understand how to write the required logic, you may refer any [existing examples](https://github.com/tailwarden/komiser/tree/develop/providers/aws) for inspiration!

**Step 3:**
Call the **`MyServiceResources()`** function from the above file, by adding it to **`providers/providername/provider.go`** file's **`listOfSupportedServices()`** function.
#### 3️⃣ Edit Provider
Call the `MyServiceResources()` function from the above file, by adding it to `providers/providername/provider.go` file's `listOfSupportedServices()` function.

```
```go
func listOfSupportedServices() []providers.FetchDataFunction {
return []providers.FetchDataFunction{
ec2.Instances,
Expand All @@ -267,15 +254,40 @@ func listOfSupportedServices() []providers.FetchDataFunction {
.
```

**Step 4:**
Repeat steps **`4,5,6`** accordingly and you'll see a new resource/service added to Komiser, in the dashboard!
#### 4️⃣
Do above mentioned steps [4](#4️⃣-add-provider-configuration), [5](#5️⃣-compile-a-new-komiser-binary) and [6](#6️⃣-start-a-new-komiser-development-server). You'll see a new resource/service added to Komiser, in the dashboard!

Additionally, [here](https://youtu.be/Vn5uc2elcVg?feature=shared) is a video tutorial of the entire process for your reference.

> 💡 Tip: you can also start the server via `go run *.go start --config ./config.toml` if you do want to skip the compile step!

### 3️⃣ Enhance existing Cloud service/resource

**So, you wish to improve the code quality of an existing cloud service/resource?** Feel free to discuss your ideas with us on our [Discord Server](https://discord.tailwarden.com) and [open a new issue](https://github.com/tailwarden/komiser/issues).

## 🧪 Testing Your Changes

We leverage the [testing](https://pkg.go.dev/testing) package for tests. Test names follow the `TestXxx(*testing.T)` format where Xxx does not start with a lowercase letter. The function name serves to identify the test routine.
For creating a new test you create a `[name]_test.go` next to the file you'd like to test and replace `[name]` with your filename of the implementation. Look at any of the `*_test.go` files for an example or read the [official docs](https://pkg.go.dev/testing).
You then can run it with `go test /path/to/your/folder/where/the/test/is`. You can run all of our engine tests with `make tests`. You should see something similar to this:

```logtalk
go test ./... | grep -v /dashboard/
...
ok github.com/tailwarden/komiser/internal (cached) [no tests to run]
? github.com/tailwarden/komiser/providers/aws/ecr [no test files]
? github.com/tailwarden/komiser/providers/aws/ecs [no test files]
? github.com/tailwarden/komiser/providers/aws/efs [no test files]
? github.com/tailwarden/komiser/providers/aws/eks [no test files]
? github.com/tailwarden/komiser/providers/aws/elasticache [no test files]
? github.com/tailwarden/komiser/providers/aws/elb [no test files]
? github.com/tailwarden/komiser/providers/aws/iam [no test files]
ok github.com/tailwarden/komiser/providers/aws/ec2 (cached)
? github.com/tailwarden/komiser/providers/aws/kms [no test files]
? github.com/tailwarden/komiser/providers/aws/lambda [no test file
...
```

# 🚀 Contributing to Komiser Dashboard UI

Komiser Dashboard utilizes a modern tech stack. Here's a brief about it:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ package:

## test: Run tests.
test:
go test -v $(go list ./... | grep -v /dashboard/)
go test ./... | grep -v /dashboard/

## version: Show version.
version:
Expand Down
8 changes: 7 additions & 1 deletion dashboard/components/feedback-widget/FeedbackWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ const useFeedbackWidget = (defaultState: boolean = false) => {
)}
<div className="flex-1 grow">
<Upload
multiple={false}
fileOrFiles={fileAttachement}
handleChange={uploadFile}
onClose={() => setFileAttachement(null)}
Expand Down Expand Up @@ -289,7 +290,12 @@ const useFeedbackWidget = (defaultState: boolean = false) => {
.
</p>
<div className="flex gap-2">
<Button size="xs" disabled={isSendingFeedback} style="ghost">
<Button
size="xs"
disabled={isSendingFeedback}
style="ghost"
onClick={() => closeFeedbackModal()}
>
Cancel
</Button>
<Button type="submit" size="xs" disabled={isSendingFeedback}>
Expand Down
37 changes: 21 additions & 16 deletions dashboard/components/upload/Upload.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,27 @@ function UploadWrapper({
}
};

return multiple ? (
<Upload
multiple={multiple}
fileOrFiles={selectedFiles}
handleChange={uploadFile}
onClose={() => setSelectedFiles(null)}
{...otherProps}
/>
) : (
<Upload
multiple={multiple}
fileOrFiles={selectedFile}
handleChange={uploadFile}
onClose={() => setSelectedFile(null)}
{...otherProps}
/>
return (
// it's impossible to define a true/false type in storybook
// so we ignore the next type error because true|false != boolean for some reason \o/
// @ts-ignore
multiple ? (
<Upload
multiple={multiple}
fileOrFiles={selectedFiles}
handleChange={uploadFile}
onClose={() => setSelectedFiles(null)}
{...otherProps}
/>
) : (
<Upload
multiple={multiple}
fileOrFiles={selectedFile}
handleChange={uploadFile}
onClose={() => setSelectedFile(null)}
{...otherProps}
/>
)
);
}

Expand Down
6 changes: 3 additions & 3 deletions dashboard/components/upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ type BaseUploadProps = {
};

export type SingleUploadProps = BaseUploadProps & {
multiple?: false;
fileOrFiles: File | File[] | null;
multiple: false;
fileOrFiles: File | null;
handleChange: (file: File | null) => void;
};

export type MultipleUploadProps = BaseUploadProps & {
multiple: true;
fileOrFiles: File | File[] | null;
fileOrFiles: File[] | null;
handleChange: (files: File[] | null) => void;
};

Expand Down
10 changes: 8 additions & 2 deletions dashboard/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@
}

.popper-div {
text-shadow: 0 0 5px #f4f9f9, 0 0 5px #f4f9f9, 0 0 5px #f4f9f9,
0 0 5px #f4f9f9, 0 0 5px #f4f9f9, 0 0 5px #f4f9f9, 0 0 5px #f4f9f9,
text-shadow:
0 0 5px #f4f9f9,
0 0 5px #f4f9f9,
0 0 5px #f4f9f9,
0 0 5px #f4f9f9,
0 0 5px #f4f9f9,
0 0 5px #f4f9f9,
0 0 5px #f4f9f9,
0 0 5px #f4f9f9;
position: relative;
color: #000;
Expand Down
Loading