Skip to content

Commit

Permalink
Merge pull request #2 from logzio/dev
Browse files Browse the repository at this point in the history
v1.0.1
  • Loading branch information
yotamloe committed Jun 6, 2023
2 parents c16e3ff + 572ccb2 commit 45fc900
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IMAGE_NAME := ezkonnect-server
IMAGE_TAG := v1.0.0
IMAGE_TAG := v1.0.1
DOCKER_REPO := logzio/$(IMAGE_NAME):$(IMAGE_TAG)
K8S_NAMESPACE := ezkonnect

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ This endpoint allows you to update annotations for Kubernetes deployments and st


## changelog
- v1.0.1
- Add support for adding service name
- 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.
- A web server written in go that exposes an API for Ezkonnect. It is responsible for managing the state of instrumented applications.
19 changes: 10 additions & 9 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Each instrumented application can have a `language` and/or an `application` fiel
"controller_kind": "deployment",
"container_name": "app-container",
"traces_instrumented": true,
"metrics_instrumented": false,
"application": null,
"language": "python"
},
Expand All @@ -42,16 +41,14 @@ Each instrumented application can have a `language` and/or an `application` fiel
"namespace": "default",
"controller_kind": "deployment",
"container_name": "",
"traces_instrumented": false,
"metrics_instrumented": false
"traces_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
},
Expand All @@ -61,7 +58,6 @@ Each instrumented application can have a `language` and/or an `application` fiel
"controller_kind": "deployment",
"container_name": "app-container",
"traces_instrumented": false,
"metrics_instrumented": false,
"application": null,
"language": "java"
}
Expand Down Expand Up @@ -105,6 +101,7 @@ The request body should be a JSON array of objects, where each object contains t
- `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.
- `service_name` (string): The name of the service associated with the resource.

#### Example Request Body
json
Expand All @@ -114,13 +111,15 @@ json
"name": "my-deployment",
"controller_kind": "deployment",
"namespace": "default",
"action": "add"
"action": "add",
"service_name": "my-service"
},
{
"name": "my-statefulset",
"controller_kind": "statefulset",
"namespace": "default",
"action": "delete"
"action": "delete",
"service_name": "my-other-service"
}
]
```
Expand All @@ -143,15 +142,17 @@ The response body will be a JSON array of objects, where each object contains th
"namespace": "default",
"controller_kind": "deployment",
"updated_annotations": {
"logz.io/instrument": "true"
"logz.io/instrument": "true",
"logz.io/service-name": "my-service"
}
},
{
"name": "my-statefulset",
"namespace": "default",
"controller_kind": "statefulset",
"updated_annotations": {
"logz.io/instrument": "rollback"
"logz.io/instrument": "rollback",
"logz.io/service-name": "my-other-service"
}
}
]
Expand Down
3 changes: 2 additions & 1 deletion api/annotate/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"net/http"
"strings"
)

const (
Expand Down Expand Up @@ -143,7 +144,7 @@ func UpdateLogsResourceAnnotations(w http.ResponseWriter, r *http.Request) {

func isValidLogsResourceRequest(req LogsResourceRequest) bool {
for _, validKind := range api.ValidKinds {
if req.Kind == validKind {
if req.Kind == strings.ToLower(validKind) {
return true
}
}
Expand Down
28 changes: 17 additions & 11 deletions api/annotate/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"net/http"
"strings"
)

const (
InstrumentationAnnotation = "logz.io/traces_instrument"
ServiceNameAnnotation = "logz.io/service-name"
)

// TracesResourceRequest ResourceRequest is the JSON body of the POST request
Expand All @@ -18,11 +20,13 @@ const (
// kind: kind of the resource (deployment or statefulset) consts defined at `common.go` (api.KindDeployment, api.KindStatefulSet)
// namespace: namespace of the resource
// action: action to perform (add or delete) consts defined at `common.go` (api.ActionAdd, api.ActionDelete)
// service_name: name of the service
type TracesResourceRequest struct {
Name string `json:"name"`
Kind string `json:"controller_kind"`
Namespace string `json:"namespace"`
Action string `json:"action"`
Name string `json:"name"`
Kind string `json:"controller_kind"`
Namespace string `json:"namespace"`
Action string `json:"action"`
ServiceName string `json:"service_name"`
}

// TracesResourceResponse is the JSON response of the POST request
Expand Down Expand Up @@ -73,13 +77,15 @@ func UpdateTracesResourceAnnotations(w http.ResponseWriter, r *http.Request) {
var responses []TracesResourceResponse
for _, resource := range resources {
// choose the annotation key and value according to the telemetry type and action
value := "true"
actionValue := "true"
if resource.Action == api.ActionDelete {
value = "rollback"
actionValue = "rollback"
}

annotations := map[string]string{
InstrumentationAnnotation: value,
annotations := map[string]string{}
annotations[InstrumentationAnnotation] = actionValue
// add service name annotation if exists
if resource.ServiceName != "" {
annotations[ServiceNameAnnotation] = resource.ServiceName
}

// Create the response
Expand Down Expand Up @@ -159,12 +165,12 @@ func isValidTracesResourceRequest(req TracesResourceRequest) bool {
isValidAction := false
isValidKind := false
for _, validAction := range api.ValidActions {
if req.Action == validAction {
if req.Action == strings.ToLower(validAction) {
isValidAction = true
}
}
for _, validKind := range api.ValidKinds {
if req.Kind == validKind {
if req.Kind == strings.ToLower(validKind) {
isValidKind = true
}
}
Expand Down
4 changes: 2 additions & 2 deletions api/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

const (
KindDeployment = "Deployment"
KindStatefulSet = "StatefulSet"
KindDeployment = "deployment"
KindStatefulSet = "statefulSet"
ActionAdd = "add"
ActionDelete = "delete"
ErrorDecodeJSON = "Error decoding JSON body "
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

// main starts the server. Endpoints:
// 1. /api/v1/state - returns a list of all custom resources of type InstrumentedApplication
// 2. /api/v1/annotate - handles the POST request for annotating a deployment or a statefulset
// 3. /api/v1/annotate/logs - handles the POST request for annotating a deployment or a statefulset with log annotations
// 2. /api/v1/annotate/traces - handles the POST request for annotating a supported resource kind
// 3. /api/v1/annotate/logs - handles the POST request for annotating a supported resource kind with log annotations
func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/api/v1/state", stateapi.GetCustomResourcesHandler).Methods(http.MethodGet)
Expand Down

0 comments on commit 45fc900

Please sign in to comment.