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

Remove the "layers" object in extra_config opentelemetry #36

Merged
merged 3 commits into from
Oct 30, 2024
Merged

Conversation

dhontecillas
Copy link
Contributor

@dhontecillas dhontecillas commented Oct 10, 2024

This PR adds the ability to override OTEL configuration for:

  • proxy layer for a single endpoint (it does not allows to set backend layers, for this single endpoint.. if you want to override the backend layer, it must be done in each of its childs)
  • backend for a single backend.

The "overrides" do not inherit parent configs, so if for example, you only specify this in a config for a backend:

{
                    "host": [
                        "https://jsonplaceholder.typicode.com"
                    ],
                    "url_pattern": "/posts?userId={id}",
                    "extra_config": {
                        "telemetry/opentelemetry": {
                            "backend": {
                                "metrics": {
                                    "static_attributes": [
                                        {
                                            "key": "my_metric_backend_override_attr",
                                            "value": "my_metric_backend_override_val"
                                        }
                                    ]
                                }
                            }
                        }
                    }
                
}

The backend will not have static attributes for traces, the values for the traces will be the defaults (not the ones specified at the service level, inside layers), for metrics , the roundtrip , read_payload , and detailed_connection will be set to false.

The example provided, even it was actually performing a mix of attributes for the proxy and the backend layers, is not documented in KrakenD Community Edition, and does not match the format of the KrakenD Enterprise Edition.

(Related PR: krakend/krakend-schema#52 )

A part from fixing the example, we want to maintain the ability to add static attributes at the endpoint and backend levels (but the config parsing must change to match the Enterprise edition).

This is intended for a 2.8 release (since the current behaviour is not documented, we can change it as is an "undocumented feature) .

Tested in Krakend CE

With config :

{
  "$schema": "https://www.krakend.io/schema/v3.json",
  "version": 3,
  "name": "KrakenD Community API Gateway",
  "port": 8080,
  "host": ["http://fake_api"],
  "timeout": "3000ms",
  "cache_ttl": "300s",
  "endpoints": [
    {
      "@comment": "Feature: Aggregation + Basic transformation (filtering & mapping) + grouping",
      "endpoint": "/git/{user}",
      "backend": [
        {
          "host": ["https://api.github.com"],
          "url_pattern": "/users/{user}",
          "allow": [
            "avatar_url",
            "name",
            "company",
            "blog",
            "location",
            "mail",
            "hireable",
            "followers",
            "public_repos",
            "public_gists"
          ],
          "mapping": {
            "blog": "website"
          },
          "group": "user",
          "extra_config": {
             "telemetry/opentelemetry": {
                "backend": {
                    "traces": {
                        "static_attributes": [
                            {
                                "key": "a_git_key",
                                "value": "a_git_value"
                            }
                        ]
                    },
                    "metrics": {
                        "static_attributes": [
                            {
                                "key": "a_git_mt",
                                "value": "a_git_val"
                            }
                        ]
                    }
                }
             }
           }
        },
        {
          "host": ["https://api.github.com"],
          "url_pattern": "/users/{user}/repos",
          "mapping": {
            "collection": "repos"
          },
          "is_collection": true
        }
      ],
      "extra_config": {
        "telemetry/opentelemetry": {
            "proxy": {
                "disable_metrics": true,
                "report_headers": true,
                "traces_static_attributes": [
                    {
                        "key": "prx_k",
                        "value": "prx_val"
                    }
                ]
            }
        }
      }
    }
  ],
  "sequential_start": true,
  "extra_config": {
    "telemetry/logging": {
      "level": "DEBUG",
      "prefix": "[KRAKEND]",
      "syslog": false,
      "stdout": true
    },
    "telemetry/gelf": {
      "address": "logstash:12201",
      "enable_tcp": false
    },
    "security/cors": {
      "allow_origins": ["*"],
      "allow_methods": ["POST", "GET"],
      "allow_headers": ["Origin", "Authorization", "Content-Type"],
      "expose_headers": ["Content-Length"],
      "max_age": "12h"
    },
    "auth/revoker": {
      "N": 10000000,
      "P": 0.0000001,
      "hash_name": "optimal",
      "TTL": 1500,
      "port": 1234,
      "token_keys": ["jti"]
    },
    "telemetry/opentelemetry": {
        "service_name": "krakend_frontend_service",
        "metric_reporting_period": 1,
        "trace_sample_rate": 1,
        "exporters": { 
            "prometheus": [
                {
                    "name": "local_prometheus",
                    "port": 9090,
                    "process_metrics": true,
                    "go_metrics": true
                }
            ],
            "otlp": [
                {
                    "name": "local_tempo",
                    "host": "tempo",
                    "port": 4317,
                    "use_http": false,
                    "disable_metrics": true
                },
                {
                    "name": "local_jaeger",
                    "host": "jaeger",
                    "port": 4317,
                    "use_http": false,
                    "disable_metrics": true
                }
            ]
        },
        "layers": {
            "global": {
                "disable_metrics": false,
                "disable_traces": false,
                "disable_propagation": false,
                "report_headers": true
            },
            "proxy": {
                "disable_metrics": false,
                "disable_traces": false,
                "report_headers": true
            }, 
            "backend": {
                "metrics": {
                    "disable_stage": false,
                    "round_trip": true,
                    "read_payload": true,
                    "detailed_connection": true,
                    "static_attributes": [
                        {
                            "key": "my_metric_attr",
                            "value": "my_metric_val"
                        }
                    ]
                },
                "traces": {
                    "disable_stage": false,
                    "round_trip": true,
                    "read_payload": true,
                    "detailed_connection": true,
                    "static_attributes": [
                        {
                            "key": "my_trace_attr",
                            "value": "my_trace_val" 
                        }
                    ],
                    "report_headers": true
                }
            }
        }
    }
  }
}

In the above config we disable the details in tracing for the /user/{user} backend request, so it won't have extra spans, and we add an attribute a_git_key=a_git_value , and we also add at the proxy level prx_k=prx_val , so, it works as expected :

test_krakend_ce_overrides

screenshot_2024_10_24__09_53_50

@dhontecillas dhontecillas marked this pull request as ready for review October 14, 2024 13:45
@kpacha kpacha merged commit fc4107f into main Oct 30, 2024
6 checks passed
@kpacha kpacha deleted the fix_examples branch October 30, 2024 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants