Esempio n. 1
0
    def test_default_match(self):
        self._write_file_with_separator_conversion(""" {
            api_key: "hi there",
            k8s_logs: [
              {
                attributes: {
                  "foo": "bar",
                  "baz": "boo",
                },
                testTest: "test",

              }
            ]
          }
        """)
        config = self._create_test_configuration_instance()
        config.parse()

        builder = K8sConfigBuilder(config.k8s_log_configs,
                                   self.logger,
                                   rename_no_original=True)

        config = builder.get_log_config(
            self.info,
            self.k8s_info,
            self.parser,
        )

        self.assertEqual(self.parser, config["parser"])
        self.assertEqual(self.info["log_path"], config["path"])
        self.assertEqual("json", config["parse_format"])
        expected = JsonObject({"baz": "boo", "foo": "bar"})
        self.assertEqual(expected, config["attributes"])
        self.assertEqual("test", config["testTest"])
Esempio n. 2
0
    def test_no_glob_match(self):
        self._write_file_with_separator_conversion(""" {
            api_key: "hi there",
            k8s_logs: [
              {
                "k8s_pod_glob": "no_match",
                "test": "no_match",
              },
            ]
          }
        """)
        config = self._create_test_configuration_instance()
        config.parse()

        builder = K8sConfigBuilder(config.k8s_log_configs,
                                   self.logger,
                                   rename_no_original=True)

        config = builder.get_log_config(
            self.info,
            self.k8s_info,
            self.parser,
        )

        self.assertFalse("test" in config)
Esempio n. 3
0
    def test_multi_match(self):
        self._write_file_with_separator_conversion(""" {
            api_key: "hi there",
            k8s_logs: [
              {
                "k8s_pod_glob": "no_match",
                "k8s_namespace_glob": "no_match",
                "k8s_container_glob": "no_match",
                "test": "no_match",
              },
              {
                "k8s_pod_glob": "*pod*",
                "k8s_namespace_glob": "*namespace*",
                "k8s_container_glob": "*container*",
                "test": "multi match",
              }
            ]
          }
        """)
        config = self._create_test_configuration_instance()
        config.parse()

        builder = K8sConfigBuilder(config.k8s_log_configs,
                                   self.logger,
                                   rename_no_original=True)

        config = builder.get_log_config(
            self.info,
            self.k8s_info,
            self.parser,
        )

        self.assertEqual("multi match", config["test"])
Esempio n. 4
0
    def test_default_rename_logfile(self):
        self._write_file_with_separator_conversion(""" {
            api_key: "hi there",
            k8s_logs: [
              {
                "test": "test"
              },
            ]
          }
        """)
        config = self._create_test_configuration_instance()
        config.parse()

        builder = K8sConfigBuilder(config.k8s_log_configs,
                                   self.logger,
                                   rename_no_original=True)

        config = builder.get_log_config(
            self.info,
            self.k8s_info,
            self.parser,
        )

        self.assertEqual("/${container_runtime}/${container_name}.log",
                         config["rename_logfile"])
Esempio n. 5
0
    def test_no_k8s_info(self):
        self._write_file_with_separator_conversion(""" {
            api_key: "hi there",
          }
        """)
        config = self._create_test_configuration_instance()
        config.parse()

        builder = K8sConfigBuilder(config.k8s_log_configs,
                                   self.logger,
                                   rename_no_original=True)

        info = {}
        config = builder.get_log_config(info, None, self.parser)

        self.assertTrue(config is None)
Esempio n. 6
0
    def test_cant_change_path(self):
        self._write_file_with_separator_conversion(""" {
            api_key: "hi there",
            k8s_logs: [
              {
                "path": "/no/change/allowed.log",
                "test": "testy"
              }
            ]
          }
        """)
        config = self._create_test_configuration_instance()
        config.parse()

        builder = K8sConfigBuilder(config.k8s_log_configs,
                                   self.logger,
                                   rename_no_original=True)

        config = builder.get_log_config(self.info, self.k8s_info, self.parser)

        self.assertEqual("testy", config["test"])
        self.assertEqual("/var/log/test.log", config["path"])