-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from logzio/dev
v0.0.1
- Loading branch information
Showing
13 changed files
with
1,549 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Build and deploy ezkonnect server image to dockerhub | ||
on: | ||
release: | ||
types: [published] | ||
jobs: | ||
push_to_registry: | ||
name: Push Docker image to Docker Hub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v2 | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASS }} | ||
- name: Build images release | ||
run: IMAGE_TAG=${{ github.event.release.tag_name }} make docker-build | ||
- name: Push images release | ||
run: IMAGE_TAG=${{ github.event.release.tag_name }} make docker-push | ||
- name: Build images latest | ||
run: IMAGE_TAG=latest make docker-build | ||
- name: Push images latest | ||
run: IMAGE_TAG=latest make docker-push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Start from a Golang base image | ||
FROM golang:1.19-alpine AS build | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Copy API code to container | ||
COPY . . | ||
|
||
# Build the Go binary | ||
RUN go build -o main . | ||
|
||
# Create a new image from scratch | ||
FROM alpine:3.14 | ||
|
||
# Copy the Go binary from the previous stage | ||
COPY --from=build /app/main /app/main | ||
|
||
# Expose port 8080 | ||
EXPOSE 5050 | ||
|
||
# Start the API server | ||
CMD ["/app/main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
IMAGE_NAME := ezkonnect-server | ||
IMAGE_TAG := v1.0.0 | ||
DOCKER_REPO := logzio/$(IMAGE_NAME):$(IMAGE_TAG) | ||
K8S_NAMESPACE := ezkonnect | ||
|
||
.PHONY: docker-build | ||
docker-build: | ||
docker build -t $(DOCKER_REPO) . | ||
|
||
.PHONY: docker-push | ||
docker-push: | ||
docker push $(DOCKER_REPO) | ||
|
||
.PHONY: deploy-kubectl | ||
deploy-kubectl: | ||
kubectl apply -f deploy/k8s-manifest.yaml -n $(K8S_NAMESPACE) | ||
|
||
.PHONY: clean-kubectl | ||
clean-kubectl: | ||
kubectl delete -f deploy/k8s-manifest.yaml -n $(K8S_NAMESPACE) | ||
|
||
.PHONY: local-server | ||
local-server: | ||
go run main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
# ezkonnect-backend | ||
# Ezkonnect-server | ||
Ezkonnect server is a web server written in go that exposes an API for Ezkonnect. It is responsible for managing the state of instrumented applications. | ||
This server is designed to run in a kubernetes environment, However it can run locally as well if a `kubeconfig` file connected to a kubernetes cluster is present on your machine. | ||
### getting started | ||
1. Clone the repo | ||
2. Run `make server-local` to start the server | ||
3. The server will be running on `localhost:5050` | ||
|
||
### API | ||
**Full API docs can be found [Here](./api.md)** | ||
- Get the state Instrumented Applications `[GET] /api/v1/state` | ||
|
||
This endpoint retrieves information about instrumented applications in the form of custom resources of type InstrumentedApplication. | ||
|
||
- Update traces resource annotations `[POST] /api/v1/annotate/traces` | ||
|
||
This endpoint allows you to update annotations for Kubernetes deployments and statefulsets. The annotations can be used to enable or disable telemetry features such as traces auto instrumentation. | ||
|
||
- Update logs resource annotations `[POST] /api/v1/annotate/logs` | ||
|
||
This endpoint allows you to update annotations for Kubernetes deployments and statefulsets. The annotations can be used to set the log type for your applications. | ||
|
||
### development | ||
- run `make server-local` to start the server | ||
- run `make docker-build` to build the docker image | ||
- run `make docker-push` to push the docker image to the registry | ||
- run `deploy-kubectl` to deploy the server to your cluster | ||
- run `clean-kubectl` to delete the server from your cluster | ||
|
||
|
||
## changelog | ||
- v1.0.0 - Initial release | ||
- A web server written in go that exposes an API for Ezkonnect. It is responsible for managing the state of instrumented applications. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,282 @@ | ||
## API Documentation | ||
- ### `[GET] /api/v1/state` Get the state Instrumented Applications | ||
This endpoint retrieves information about instrumented applications in the form of custom resources of type InstrumentedApplication. | ||
|
||
### Request | ||
- Method: `GET` | ||
- Path: `/api/v1/state` | ||
|
||
### Response | ||
### Success | ||
- Status code: `200 OK` | ||
- Content-Type: `application/json` | ||
|
||
The response body will be a JSON array of objects, where each object contains the following fields: | ||
- `name` (string): The name of the custom resource. | ||
- `namespace` (string): The namespace of the custom resource. | ||
- `controller_kind` (string): The kind of the controller (lowercased owner reference kind). | ||
- `container_name` (string, optional): The container name associated with the instrumented application. Will be empty if both language and application fields are empty. | ||
- `traces_instrumented` (bool): Whether the application is instrumented or not. | ||
- `metrics_instrumented` (bool): Whether the application is exporting metrics or not. | ||
- `application` (string, optional): The application name if available in the spec. | ||
- `language` (string, optional): The programming language if available in the spec. | ||
|
||
Each instrumented application can have a `language` and/or an `application` field, or none of them. If neither `language` nor `application` is present, the application cannot be instrumented. If at least one of `language` or `application` fields is non-empty, there will also be a `container_name` field. However, if both language and application fields are empty, the `container_name` will be empty as well. | ||
|
||
|
||
#### Example Success Response | ||
```json | ||
[ | ||
{ | ||
"name": "my-instrumented-app", | ||
"namespace": "default", | ||
"controller_kind": "deployment", | ||
"container_name": "app-container", | ||
"traces_instrumented": true, | ||
"metrics_instrumented": false, | ||
"application": null, | ||
"language": "python" | ||
}, | ||
{ | ||
"name": "uninstrumented-app", | ||
"namespace": "default", | ||
"controller_kind": "deployment", | ||
"container_name": "", | ||
"traces_instrumented": false, | ||
"metrics_instrumented": false | ||
}, | ||
{ | ||
"name": "statefulset-with-app-detection", | ||
"namespace": "default", | ||
"controller_kind": "statefulset", | ||
"container_name": "app-container", | ||
"traces_instrumented": false, | ||
"metrics_instrumented": false, | ||
"application": "my-app", | ||
"language": null | ||
}, | ||
{ | ||
"name": "deployment-with-language-detection", | ||
"namespace": "default", | ||
"controller_kind": "deployment", | ||
"container_name": "app-container", | ||
"traces_instrumented": false, | ||
"metrics_instrumented": false, | ||
"application": null, | ||
"language": "java" | ||
} | ||
] | ||
``` | ||
### Errors | ||
- Status code: `405 Method Not Allowed` | ||
|
||
The request method is not GET. | ||
|
||
Example error response: | ||
|
||
```json | ||
{ | ||
"error": "Invalid request method" | ||
} | ||
``` | ||
- Status code: `500 Internal Server Error` | ||
|
||
There was an error processing the request, such as failing to interact with the Kubernetes cluster. | ||
|
||
Example error response: | ||
|
||
```json | ||
{ | ||
"error": "Error message" | ||
} | ||
``` | ||
|
||
|
||
- ### `[POST] /api/v1/anotate/traces` Update traces Resource Annotations | ||
This endpoint allows you to update annotations for Kubernetes deployments and statefulsets. The annotations can be used to enable or disable telemetry features such as metrics and traces. | ||
|
||
### Request | ||
- Method: `POST` | ||
- Path: `/api/v1/anotate/traces` | ||
|
||
#### Request Body | ||
The request body should be a JSON array of objects, where each object contains the following fields: | ||
- `name` (string): The name of the resource. | ||
- `controller_kind` (string): The kind of the resource, either deployment or statefulset. | ||
- `namespace` (string): The namespace of the resource. | ||
- `action` (string): The action to perform, either add or delete. | ||
|
||
#### Example Request Body | ||
json | ||
```json | ||
[ | ||
{ | ||
"name": "my-deployment", | ||
"controller_kind": "deployment", | ||
"namespace": "default", | ||
"action": "add" | ||
}, | ||
{ | ||
"name": "my-statefulset", | ||
"controller_kind": "statefulset", | ||
"namespace": "default", | ||
"action": "delete" | ||
} | ||
] | ||
``` | ||
|
||
### Response | ||
#### Success | ||
- Status code: `200 OK` | ||
- Content-Type: `application/json` | ||
|
||
The response body will be a JSON array of objects, where each object contains the following fields: | ||
- `name` (string): The name of the updated resource. | ||
- `namespace` (string): The namespace of the updated resource. | ||
- `controller_kind` (string): The kind of the updated resource, either deployment or statefulset. | ||
- `updated_annotations` (object): The updated annotations with their keys and values. | ||
#### Example Success Response | ||
```json | ||
[ | ||
{ | ||
"name": "my-deployment", | ||
"namespace": "default", | ||
"controller_kind": "deployment", | ||
"updated_annotations": { | ||
"logz.io/instrument": "true" | ||
} | ||
}, | ||
{ | ||
"name": "my-statefulset", | ||
"namespace": "default", | ||
"controller_kind": "statefulset", | ||
"updated_annotations": { | ||
"logz.io/instrument": "rollback" | ||
} | ||
} | ||
] | ||
``` | ||
|
||
#### Errors | ||
- Status code: `400 Bad Request` | ||
|
||
The request body is malformed, or one or more of the provided fields have invalid values. | ||
|
||
Example error response: | ||
|
||
```json | ||
{ | ||
"error": "Invalid input" | ||
} | ||
``` | ||
|
||
- Status code: `500 Internal Server Error` | ||
|
||
There was an error processing the request, such as failing to interact with the Kubernetes cluster. | ||
|
||
Example error response: | ||
|
||
```json | ||
{ | ||
"error": "Error message" | ||
} | ||
``` | ||
|
||
|
||
- ### `[POST] /api/v1/annotate/logs` Update Logs Resource Annotations | ||
|
||
|
||
This endpoint allows you to set the log type for Kubernetes deployments and statefulsets. The annotation is used to determine the type of logs that should be collected from the resource. | ||
|
||
### Request | ||
|
||
* Method: `POST` | ||
* Path: `/api/v1/annotate/logs` | ||
|
||
#### Request Body | ||
|
||
The request body should be a JSON array of objects, where each object contains the following fields: | ||
|
||
* `name` (string): The name of the resource. | ||
* `controller_kind` (string): The kind of the resource controller, either "deployment" or "statefulset". | ||
* `namespace` (string): The namespace of the resource. | ||
* `log_type` (string): The type of logs to add. | ||
|
||
#### Example Request Body | ||
|
||
```json | ||
[ | ||
{ | ||
"name": "my-deployment", | ||
"controller_kind": "deployment", | ||
"namespace": "default", | ||
"log_type": "application" | ||
}, | ||
{ | ||
"name": "my-statefulset", | ||
"controller_kind": "statefulset", | ||
"namespace": "default", | ||
"log_type": "system" | ||
} | ||
] | ||
|
||
``` | ||
|
||
### Response | ||
|
||
#### Success | ||
|
||
* Status code: `200 OK` | ||
* Content-Type: `application/json` | ||
|
||
The response body will be a JSON array of objects, where each object contains the following fields: | ||
|
||
* `name` (string): The name of the updated resource. | ||
* `namespace` (string): The namespace of the updated resource. | ||
* `controller_kind` (string): The kind of the updated resource, either "deployment" or "statefulset". | ||
* `updated_annotations` (object): The updated annotations with their keys and values. | ||
|
||
#### Example Success Response | ||
|
||
```json | ||
[ | ||
{ | ||
"name": "my-deployment", | ||
"namespace": "default", | ||
"controller_kind": "deployment", | ||
"updated_annotations": { | ||
"logz.io/application_type": "application" | ||
} | ||
}, | ||
{ | ||
"name": "my-statefulset", | ||
"namespace": "default", | ||
"controller_kind": "statefulset", | ||
"updated_annotations": { | ||
"logz.io/application_type": "system" | ||
} | ||
} | ||
] | ||
|
||
``` | ||
#### Errors | ||
|
||
* Status code: `400 Bad Request` | ||
|
||
The request body is malformed, or one or more of the provided fields have invalid values. | ||
|
||
Example error response: | ||
|
||
jsonCopy code | ||
|
||
`{ "error": "Invalid input" }` | ||
|
||
* Status code: `500 Internal Server Error` | ||
|
||
There was an error processing the request, such as failing to interact with the Kubernetes cluster. | ||
|
||
Example error response: | ||
|
||
jsonCopy code | ||
|
||
`{ "error": "Error message" }` |
Oops, something went wrong.